Set the discs on the board as per the move made on the given cell
(self, row: int, col: int, PLAYER: int)
| 108 | return legal_moves |
| 109 | |
| 110 | def set_discs(self, row: int, col: int, PLAYER: int) -> None: |
| 111 | '''Set the discs on the board as per the move made on the given cell''' |
| 112 | self.board[row, col] = PLAYER |
| 113 | OPPONENT = Board.WHITE if PLAYER == Board.BLACK else Board.BLACK |
| 114 | |
| 115 | # outflanking pieces on the right |
| 116 | c = col + 1 |
| 117 | while c < 8 and self.board[row, c] == OPPONENT: |
| 118 | c += 1 |
| 119 | if (c != col + 1 and c < 8) and self.board[row, c] == PLAYER: # outflanking is legal |
| 120 | self.board[row, col:c] = PLAYER |
| 121 | |
| 122 | # outflanking pieces on the left |
| 123 | c = col - 1 |
| 124 | while c >= 0 and self.board[row, c] == OPPONENT: |
| 125 | c -= 1 |
| 126 | if (c != col - 1 and c >= 0) and self.board[row, c] == PLAYER: # outflanking is ilegal |
| 127 | self.board[row, c:col] = PLAYER |
| 128 | |
| 129 | # outflanking pieces below |
| 130 | r = row + 1 |
| 131 | while r < 8 and self.board[r, col] == OPPONENT: |
| 132 | r += 1 |
| 133 | if (r != row + 1 and r < 8) and self.board[r, col] == PLAYER: # outflanking is legal |
| 134 | self.board[row:r , col] = PLAYER |
| 135 | |
| 136 | # outflanking pieces above |
| 137 | r = row - 1 |
| 138 | while r >= 0 and self.board[r, col] == OPPONENT: |
| 139 | r -= 1 |
| 140 | if (r != row - 1 and r >= 0) and self.board[r, col] == PLAYER: # outflanking is legal |
| 141 | self.board[r:row, col] = PLAYER |
| 142 | |
| 143 | # outflanking pieces in the diagonal from the cell towards top left |
| 144 | r = row - 1 |
| 145 | c = col - 1 |
| 146 | while (r >= 0 and c >= 0) and self.board[r, c] == OPPONENT: |
| 147 | r -= 1 |
| 148 | c -= 1 |
| 149 | if (r != row - 1 and c != col - 1) and (r >= 0 and c >= 0) and self.board[r, c] == PLAYER: # outflanking is legal |
| 150 | r = row - 1 |
| 151 | c = col - 1 |
| 152 | while self.board[r, c] == OPPONENT: |
| 153 | self.board[r, c] = PLAYER |
| 154 | r -= 1 |
| 155 | c -= 1 |
| 156 | |
| 157 | # outflanking pieces in the diagonal from the cell towards top right |
| 158 | r = row - 1 |
| 159 | c = col + 1 |
| 160 | while (r >= 0 and c < 8) and self.board[r, c] == OPPONENT: |
| 161 | r -= 1 |
| 162 | c += 1 |
| 163 | if (r != row - 1 and c != col + 1) and (r >= 0 and c < 8) and self.board[r, c] == PLAYER: # outflanking is legal |
| 164 | r = row - 1 |
| 165 | c = col + 1 |
| 166 | while self.board[r, c] == OPPONENT: |
| 167 | self.board[r, c] = PLAYER |