def test_white_rook(test_board): assert test_board test_white_rook = Rook(PieceColor.WHITE) starting_space = test_board.get_space("a", 1) test_white_rook.place(starting_space) return test_white_rook
def init_board(self): new_b = [] for i in range(64): # white if i == 0 or i == 7: new_b.append(Tile(Rook('W'))) elif i == 1 or i == 6: new_b.append(Tile(Knight('W'))) elif i == 2 or i == 5: new_b.append(Tile(Bishop('W'))) elif i == 3: new_b.append(Tile(Queen('W'))) elif i == 4: new_b.append(Tile(King('W'))) elif i >= 8 and i <= 15: new_b.append(Tile(Pawn('W'))) # black elif i == 56 or i == 63: new_b.append(Tile(Rook('B'))) elif i == 57 or i == 62: new_b.append(Tile(Knight('B'))) elif i == 58 or i == 61: new_b.append(Tile(Bishop('B'))) elif i == 59: new_b.append(Tile(Queen('B'))) elif i == 60: new_b.append(Tile(King('B'))) elif i >= 48 and i <= 55: new_b.append(Tile(Pawn('B'))) # empty else: new_b.append(Tile()) return new_b
def fill_board(self): for key in self.__letter_mapping: self[key + '7'] = Pawn(BLACK, self) self[key + '2'] = Pawn(WHITE, self) self['A1'] = Rook(WHITE, self) self['H1'] = Rook(WHITE, self) self['A8'] = Rook(BLACK, self) self['H8'] = Rook(BLACK, self) self['B1'] = Knight(WHITE, self) self['G1'] = Knight(WHITE, self) self['B8'] = Knight(BLACK, self) self['G8'] = Knight(BLACK, self) self['C1'] = Bishop(WHITE, self) self['F1'] = Bishop(WHITE, self) self['C8'] = Bishop(BLACK, self) self['F8'] = Bishop(BLACK, self) self['D1'] = Queen(WHITE, self) self['D8'] = Queen(BLACK, self) self['E1'] = King(WHITE, self) self['E8'] = King(BLACK, self)
def add_pieces(self): """ Appends the proper pieces and locations to each team list. Team lists are used to get the possible moves and easily check the capture status of a piece. """ self.wp.append(King(4, 7, True)) self.wp.append(Queen(3, 7, True)) self.wp.append(Rook(0, 7, True)) self.wp.append(Rook(7, 7, True)) self.wp.append(Knight(1, 7, True)) self.wp.append(Knight(6, 7, True)) self.wp.append(Bishop(2, 7, True)) self.wp.append(Bishop(5, 7, True)) for i in range(8): self.wp.append(Pawn(i, 6, True)) self.bp.append(King(4, 0, False)) self.bp.append(Queen(3, 0, False)) self.bp.append(Rook(0, 0, False)) self.bp.append(Rook(7, 0, False)) self.bp.append(Knight(1, 0, False)) self.bp.append(Knight(6, 0, False)) self.bp.append(Bishop(2, 0, False)) self.bp.append(Bishop(5, 0, False)) for i in range(8): self.bp.append(Pawn(i, 1, False))
def test_black_rook(test_board): starting_file = "a" starting_rank = 8 starting_space = test_board.get_space(starting_file, starting_rank) test_rook = Rook(PieceColor.BLACK) test_rook.place(starting_space) return test_rook
def __init__(self): self.board = [[None for j in range(8)] for i in range(8)] self.pieces = [] # set white board pieces = [] for i in range(8): pieces.append(Pawn(i, 1, COLOR.WHITE)) pieces.append(Rook(0, 0, COLOR.WHITE)) pieces.append(Rook(7 ,0, COLOR.WHITE)) pieces.append(Knight(1, 0, COLOR.WHITE)) pieces.append(Knight(6, 0, COLOR.WHITE)) pieces.append(Bishop(2, 0, COLOR.WHITE)) pieces.append(Bishop(5, 0, COLOR.WHITE)) pieces.append(King(3, 0, COLOR.WHITE)) pieces.append(Queen(4, 0, COLOR.WHITE)) #set black peices for i in range(8): pieces.append(Pawn(i, 6, COLOR.BLACK)) pieces.append(Rook(0, 7, COLOR.BLACK)) pieces.append(Rook(7 ,7, COLOR.BLACK)) pieces.append(Knight(1, 7, COLOR.BLACK)) pieces.append(Knight(6, 7, COLOR.BLACK)) pieces.append(Bishop(2, 7, COLOR.BLACK)) pieces.append(Bishop(5, 7, COLOR.BLACK)) pieces.append(King(3, 7, COLOR.BLACK)) pieces.append(Queen(4, 7, COLOR.BLACK)) for _piece in pieces: self.pieces.append(_piece) self.board[_piece._x][_piece._y] = _piece
def _init_pieces(self): if not self._positions: king = King(color=self._color) self._positions.update({str(king.position): king}) queen = Queen(color=self._color) self._positions.update({str(queen.position): queen}) for i in range(1, 9): pawn = Pawn(self._color, col=i) self._positions.update({str(pawn.position): pawn}) knight = Knight(self._color, col=2) self._positions.update({str(knight.position): knight}) knight = Knight(self._color, col=7) self._positions.update({str(knight.position): knight}) rook = Rook(self._color, col=1) self._positions.update({str(rook.position): rook}) rook = Rook(self._color, col=8) self._positions.update({str(rook.position): rook}) bishop = Bishop(self._color, col=3) self._positions.update({str(bishop.position): bishop}) bishop = Bishop(self._color, col=6) self._positions.update({str(bishop.position): bishop})
def parse(fin): white_pieces = [] black_pieces = [] with open(fin, "r") as file_in: lines = file_in.read().splitlines() for line in lines: if int(line[-1:]) > 0: for idx in range(0, int(line[-1:])): if (line[-7:-2] == 'WHITE'): temp = line[:-8] if (temp == 'BISHOP'): white_pieces.append(Bishop(Position(), True)) elif (temp == 'KNIGHT'): white_pieces.append(Knight(Position(), True)) elif (temp == 'QUEEN'): white_pieces.append(Queen(Position(), True)) elif (temp == 'ROOK'): white_pieces.append(Rook(Position(), True)) elif (line[-7:-2] == 'BLACK'): temp = line[:-8] if (temp == 'BISHOP'): black_pieces.append(Bishop(Position(), False)) elif (temp == 'KNIGHT'): black_pieces.append(Knight(Position(), False)) elif (temp == 'QUEEN'): black_pieces.append(Queen(Position(), False)) elif (temp == 'ROOK'): black_pieces.append(Rook(Position(), False)) file_in.close() return white_pieces, black_pieces
def test_white_rook(test_board): starting_file = "a" starting_rank = 1 starting_space = test_board.get_space(starting_file, starting_rank) test_rook = Rook(PieceColor.WHITE) test_rook.place(starting_space) return test_rook
def test_create_white_rook(self, test_board): test_rook = Rook(PieceColor.WHITE) starting_file = "a" starting_rank = 1 starting_space = test_board.get_space(starting_file, starting_rank) test_rook.place(starting_space) assert test_rook.current_space is starting_space
def test_attacking_moves(self): b = Board() b.clean() b.matrix[4][7] = "p" b.matrix[1][2] = "P" b.matrix[4][1] = "p" rook = Rook(b, Square(4, 2), BLACK) expected = [Square(4, 1), Square(4, 7)] result = rook.attacking_moves() self.assertEqual(expected, result)
def test_valid_moves_clean_board(self): b = Board() b.clean() rook = Rook(b, Square(4, 2), WHITE) expected = [Square(3, 2), Square(2, 2), Square(1, 2), Square(0, 2), Square(5, 2), Square(6, 2), Square(7, 2), Square(4, 1), Square(4, 0), Square(4, 3), Square(4, 4), Square(4, 5), Square(4, 6), Square(4, 7)] result = rook.valid_moves() self.assertEqual(expected, result)
def test_attacking_being_added_to_valid_moves(self): b = Board() b.clean() b.matrix[3][4] = "P" rook = Rook(b, Square(3, 3), WHITE) expected = [Square(2, 3), Square(1, 3), Square(0, 3), Square(4, 3), Square(5, 3), Square(6, 3), Square(7, 3), Square(3, 2), Square(3, 1), Square(3, 0), Square(3, 4)] result = rook.valid_moves() self.assertEqual(expected, result)
def bad_rook_move_vertical(self, test_board, test_black_rook): assert test_board assert test_black_rook assert test_black_rook.current_space assert test_black_rook.current_space.rank - 1 > MIN_RANK target_space = test_board.get_space(test_black_rook.current_space.file, MIN_RANK) obstacle_space = test_board.get_space( test_black_rook.current_space.file, MIN_RANK + 1) obstacle_piece = Rook(PieceColor.WHITE) obstacle_piece.place(obstacle_space) test_black_rook.move(test_board, target_space)
def bad_rook_move_horizontal(self, test_board, test_white_rook): assert test_board assert test_white_rook assert test_white_rook.current_space assert ord(test_white_rook.current_space.file) + 1 < ord(MAX_FILE) target_space = test_board.get_space(MAX_FILE, test_white_rook.current_space.rank) obstacle_space = test_board.get_space( chr(ord(MAX_FILE) - 1), test_white_rook.current_space.rank) obstacle_piece = Rook(PieceColor.BLACK) obstacle_piece.place(obstacle_space) test_white_rook.move(test_board, target_space)
def setBoard(self, fen): row, column = 0, 0 for character in fen: if character == 'R': self.addPiece(Rook(column, row, 'w', self.board.board)) column += 1 elif character == 'r': self.addPiece(Rook(column, row, 'b', self.board.board)) column += 1 elif character == 'N': self.addPiece(Knight(column, row, 'w', self.board.board)) column += 1 elif character == 'n': self.addPiece(Knight(column, row, 'b', self.board.board)) column += 1 elif character == 'B': self.addPiece(Bishop(column, row, 'w', self.board.board)) column += 1 elif character == 'b': self.addPiece(Bishop(column, row, 'b', self.board.board)) column += 1 elif character == 'P': self.addPiece(Pawn(column, row, 'w', self.board.board)) column += 1 elif character == 'p': self.addPiece(Pawn(column, row, 'b', self.board.board)) column += 1 elif character == 'K': self.addPiece(King(column, row, 'w', self.board.board)) column += 1 elif character == 'k': self.addPiece(King(column, row, 'b', self.board.board)) column += 1 elif character == 'Q': self.addPiece(Queen(column, row, 'w', self.board.board)) column += 1 elif character == 'q': self.addPiece(Queen(column, row, 'b', self.board.board)) column += 1 elif character == '/': column = 0 row += 1 else: if character >= '1' and character <= '9': column += int(character) elif character == ' ': i = fen.index(character) + 1 self.whitesTurn = True if fen[i] == 'w' else False return
def test_possible_poss(self): xs = [chr(ord('a') + i) for i in range(0, 8)] ys = [i for i in range(1, 9)] for x, y in product(xs, ys): r = Rook(x, y) verifica= [] for element_x in xs: if r.pos_in_x != element_x: verifica.append((element_x, r.pos_in_y)) elif r.pos_in_x == element_x: for element_y in ys: if element_y != r.pos_in_y: verifica.append((r.pos_in_x, element_y)) try: self.assertTrue(sorted(verifica) == sorted(r.possible_poss())) except: print('Something is wrong') break
def create_standard_game(self): from bishop import Bishop from king import King from knight import Knight from pawn import Pawn from queen import Queen from rook import Rook self.set_piece(Rook(0, Alliance.WHITE)) self.set_piece(Knight(1, Alliance.WHITE)) self.set_piece(Bishop(2, Alliance.WHITE)) self.set_piece(Queen(3, Alliance.WHITE)) self.set_piece(King(4, Alliance.WHITE)) self.set_piece(Bishop(5, Alliance.WHITE)) self.set_piece(Knight(6, Alliance.WHITE)) self.set_piece(Rook(7, Alliance.WHITE)) self.set_piece(Pawn(8, Alliance.WHITE)) self.set_piece(Pawn(9, Alliance.WHITE)) self.set_piece(Pawn(10, Alliance.WHITE)) self.set_piece(Pawn(11, Alliance.WHITE)) self.set_piece(Pawn(12, Alliance.WHITE)) self.set_piece(Pawn(13, Alliance.WHITE)) self.set_piece(Pawn(14, Alliance.WHITE)) self.set_piece(Pawn(15, Alliance.WHITE)) self.set_piece(Pawn(48, Alliance.BLACK)) self.set_piece(Pawn(49, Alliance.BLACK)) self.set_piece(Pawn(50, Alliance.BLACK)) self.set_piece(Pawn(51, Alliance.BLACK)) self.set_piece(Pawn(52, Alliance.BLACK)) self.set_piece(Pawn(53, Alliance.BLACK)) self.set_piece(Pawn(54, Alliance.BLACK)) self.set_piece(Pawn(55, Alliance.BLACK)) self.set_piece(Rook(56, Alliance.BLACK)) self.set_piece(Knight(57, Alliance.BLACK)) self.set_piece(Bishop(58, Alliance.BLACK)) self.set_piece(Queen(59, Alliance.BLACK)) self.set_piece(King(60, Alliance.BLACK)) self.set_piece(Bishop(61, Alliance.BLACK)) self.set_piece(Knight(62, Alliance.BLACK)) self.set_piece(Rook(63, Alliance.BLACK)) self.set_move_alliance(Alliance.WHITE)
def test_attacking_being_added_to_valid_moves(self): b = Board() b.clean() b.matrix[3][4] = "P" rook = Rook(b, Square(3, 3), WHITE) expected = [ Square(2, 3), Square(1, 3), Square(0, 3), Square(4, 3), Square(5, 3), Square(6, 3), Square(7, 3), Square(3, 2), Square(3, 1), Square(3, 0), Square(3, 4) ] result = rook.valid_moves() self.assertEqual(expected, result)
def __init__(self) -> None: """Setup the board with all the pieces on the starting positions.""" self._squares: Dict[str, Square] = { coord: Square(coord) for coord in map("".join, itertools.product(self._FILES, self._RANKS)) } self["a8"].piece = Rook(Color.BLACK) self["b8"].piece = Knight(Color.BLACK) self["c8"].piece = Bishop(Color.BLACK) self["d8"].piece = Queen(Color.BLACK) self["e8"].piece = King(Color.BLACK) self["f8"].piece = Bishop(Color.BLACK) self["g8"].piece = Knight(Color.BLACK) self["h8"].piece = Rook(Color.BLACK) self["a1"].piece = Rook(Color.WHITE) self["b1"].piece = Knight(Color.WHITE) self["c1"].piece = Bishop(Color.WHITE) self["d1"].piece = Queen(Color.WHITE) self["e1"].piece = King(Color.WHITE) self["f1"].piece = Bishop(Color.WHITE) self["g1"].piece = Knight(Color.WHITE) self["h1"].piece = Rook(Color.WHITE) for file in self._FILES: self[f"{file}7"].piece = Pawn(Color.BLACK) self[f"{file}2"].piece = Pawn(Color.WHITE) # Set the adjacent Square nodes for each Square. for i in range(8): for j in range(8): sq = self._get(i, j) sq["n"] = self._get(i, j + 1) sq["e"] = self._get(i + 1, j) sq["s"] = self._get(i, j - 1) sq["w"] = self._get(i - 1, j) sq["ne"] = self._get(i + 1, j + 1) sq["se"] = self._get(i + 1, j - 1) sq["sw"] = self._get(i - 1, j - 1) sq["nw"] = self._get(i - 1, j + 1)
def test_player_taken_pieces(): game = Game() player = game.current_player game._board["a7"].piece = None game._board["b7"].piece = None game._board["c7"].piece = None game._board["a8"].piece = None game._board["b8"].piece = None game._board["h8"].piece = None game._board["c8"].piece = None assert player.taken_pieces == [ Rook(Color.BLACK), Rook(Color.BLACK), Bishop(Color.BLACK), Knight(Color.BLACK), Pawn(Color.BLACK), Pawn(Color.BLACK), Pawn(Color.BLACK) ]
def initializePieces(self): self.board[4][0] = King(self.window, False, 4, 0, self.pieces_image[0]) self.black_king = self.board[4][0] self.board[3][0] = Queen(self.window, False, 3, 0, self.pieces_image[1]) self.board[0][0] = Rook(self.window, False, 0, 0, self.pieces_image[4]) self.board[7][0] = Rook(self.window, False, 7, 0, self.pieces_image[4]) self.board[6][0] = Knight(self.window, False, 6, 0, self.pieces_image[3]) self.board[1][0] = Knight(self.window, False, 1, 0, self.pieces_image[3]) self.board[2][0] = Bishop(self.window, False, 2, 0, self.pieces_image[2]) self.board[5][0] = Bishop(self.window, False, 5, 0, self.pieces_image[2]) self.board[4][7] = King(self.window, True, 4, 7, self.pieces_image[0 + 6]) self.white_king = self.board[4][7] self.board[3][7] = Queen(self.window, True, 3, 7, self.pieces_image[1 + 6]) self.board[0][7] = Rook(self.window, True, 0, 7, self.pieces_image[4 + 6]) self.board[7][7] = Rook(self.window, True, 7, 7, self.pieces_image[4 + 6]) self.board[6][7] = Knight(self.window, True, 6, 7, self.pieces_image[3 + 6]) self.board[1][7] = Knight(self.window, True, 1, 7, self.pieces_image[3 + 6]) self.board[2][7] = Bishop(self.window, True, 2, 7, self.pieces_image[2 + 6]) self.board[5][7] = Bishop(self.window, True, 5, 7, self.pieces_image[2 + 6]) white = False for y in [1, 6]: for x in range(8): if y == 6: white = True if white: image = self.pieces_image[5 + 6] else: image = self.pieces_image[5] self.board[x][y] = Pawn(self.window, white, x, y, image) if white: self.white_pawns.append(self.board[x][y]) else: self.black_pawns.append(self.board[x][y])
def __init__(self): self.board = [[Empty(x='',y='',sl='.',team='')]*9 for _ in range(9)] self.board[0][0] = Rook(x=0,y=0,sl='r',team='black') self.board[0][1] = Knight(x=0,y=1,sl='n',team='black') self.board[0][2] = Bishop(x=0,y=2,sl='b',team='black') self.board[0][3] = Queen(x=0,y=3,sl='q',team='black') self.board[0][4] = King(x=0,y=4,sl='k',team='black') self.board[0][5] = Bishop(x=0,y=5,sl='b',team='black') self.board[0][6] = Knight(x=0,y=6,sl='n',team='black') self.board[0][7] = Rook(x=0,y=7,sl='r',team='black') self.board[1][0] = Pawn(x=1,y=0,sl='p',team='black') self.board[1][1] = Pawn(x=1,y=1,sl='p',team='black') self.board[1][2] = Pawn(x=1,y=2,sl='p',team='black') self.board[1][3] = Pawn(x=1,y=3,sl='p',team='black') self.board[1][4] = Pawn(x=1,y=4,sl='p',team='black') self.board[1][5] = Pawn(x=1,y=5,sl='p',team='black') self.board[1][6] = Pawn(x=1,y=6,sl='p',team='black') self.board[1][7] = Pawn(x=1,y=7,sl='p',team='black') self.board[7][0] = Rook(x=7,y=0,sl='R',team='white') self.board[7][1] = Knight(x=7,y=1,sl='N',team='white') self.board[7][2] = Bishop(x=7,y=2,sl='B',team='white') self.board[7][3] = Queen(x=7,y=3,sl='Q',team='white') self.board[7][4] = King(x=7,y=4,sl='K',team='white') self.board[7][5] = Bishop(x=7,y=5,sl='B',team='white') self.board[7][6] = Knight(x=7,y=6,sl='N',team='white') self.board[7][7] = Rook(x=7,y=7,sl='R',team='white') self.board[6][0] = Pawn(x=3,y=0,sl='P',team='white') self.board[6][1] = Pawn(x=6,y=1,sl='P',team='white') self.board[6][2] = Pawn(x=6,y=2,sl='P',team='white') self.board[6][3] = Pawn(x=6,y=3,sl='P',team='white') self.board[6][4] = Pawn(x=6,y=4,sl='P',team='white') self.board[6][5] = Pawn(x=6,y=5,sl='P',team='white') self.board[6][6] = Pawn(x=6,y=6,sl='P',team='white') self.board[6][7] = Pawn(x=6,y=7,sl='P',team='white') for i in range(9): self.board[i][8 ]= Number(sl=i) for j in range(9): self.board[8][j] = Number(sl=j)
def pawn_promotion(self, pawn, end): options = ("q", "r", "b", "k") new_piece = "None" while new_piece.lower()[0] not in options: new_piece = input("What piece would you like to promote your pawn to? Your options are:\n[Q]ueen\n[R]ook\n[B]ishop\n[K]night ") if new_piece.lower()[0] == "q": self.board[end[0]][end[1]].piece = Queen(color=pawn.color) if new_piece.lower()[0] == "r": self.board[end[0]][end[1]].piece = Rook(color=pawn.color) if new_piece.lower()[0] == "b": self.board[end[0]][end[1]].piece = Bishop(color=pawn.color) if new_piece.lower()[0] == "k": self.board[end[0]][end[1]].piece = Knight(color=pawn.color)
def test_valid_moves_clean_board(self): b = Board() b.clean() rook = Rook(b, Square(4, 2), WHITE) expected = [ Square(3, 2), Square(2, 2), Square(1, 2), Square(0, 2), Square(5, 2), Square(6, 2), Square(7, 2), Square(4, 1), Square(4, 0), Square(4, 3), Square(4, 4), Square(4, 5), Square(4, 6), Square(4, 7) ] result = rook.valid_moves() self.assertEqual(expected, result)
def set_promoted_piece(self, piece_type, piece_position, piece_alliance): if piece_type == Type.QUEEN: from queen import Queen self.promoted_piece = Queen(piece_position, piece_alliance) elif piece_type == Type.BISHOP: from bishop import Bishop self.promoted_piece = Bishop(piece_position, piece_alliance) elif piece_type == Type.KNIGHT: from knight import Knight self.promoted_piece = Knight(piece_position, piece_alliance) elif piece_type == Type.ROOK: from rook import Rook self.promoted_piece = Rook(piece_position, piece_alliance)
def board_setup(self): w = "White" b = "Black" for space in self.board[1]: self.board[space.position[0]][space.position[1]].piece = Pawn(color=b) for space in self.board[6]: self.board[space.position[0]][space.position[1]].piece = Pawn(color=w) self.board[0][0].piece = Rook(color=b) self.board[0][1].piece = Knight(color=b) self.board[0][2].piece = Bishop(color=b) self.board[0][3].piece = Queen(color=b) self.board[0][4].piece = King(color=b) self.board[0][5].piece = Bishop(color=b) self.board[0][6].piece = Knight(color=b) self.board[0][7].piece = Rook(color=b) self.board[7][0].piece = Rook(color=w) self.board[7][1].piece = Knight(color=w) self.board[7][2].piece = Bishop(color=w) self.board[7][3].piece = Queen(color=w) self.board[7][4].piece = King(color=w) self.board[7][5].piece = Bishop(color=w) self.board[7][6].piece = Knight(color=w) self.board[7][7].piece = Rook(color=w)
class TestRook(unittest.TestCase): def setUp(self): self._rook = Rook() def test_next_valid_positions(self): expected_positions = [[('a%s' % z) for z in range(2, 9)], [('%s1' % i) for i in 'bcdefgh']] actual_positions = [str(p) for p in self._rook.next_valid_positions()] for ap in actual_positions: self.assertTrue(ap in expected_positions[0] or ap in expected_positions[1]) self.assertEqual( len(actual_positions), len(expected_positions[0]) + len(expected_positions[1]))
def create_new_piece(piece, position): if piece.get_piece_type() == Type.PAWN: from pawn import Pawn return Pawn(position, piece.get_piece_alliance()) elif piece.get_piece_type() == Type.QUEEN: from queen import Queen return Queen(position, piece.get_piece_alliance()) elif piece.get_piece_type() == Type.BISHOP: from bishop import Bishop return Bishop(position, piece.get_piece_alliance()) elif piece.get_piece_type() == Type.KNIGHT: from knight import Knight return Knight(position, piece.get_piece_alliance()) elif piece.get_piece_type() == Type.ROOK: from rook import Rook return Rook(position, piece.get_piece_alliance()) elif piece.get_piece_type() == Type.KING: from king import King return King(position, piece.get_piece_alliance())
def new_piece(self, char="", pos=(0, 0), side=""): # Returns a new instance of a pieces class based on the string given to this method if char.lower() == 'b': return Bishop(char=char, pos=pos, side=side) if char.lower() == 'k': return King(char=char, pos=pos, side=side) if char.lower() == 'n': return Knight(char=char, pos=pos, side=side) if char.lower() == 'p': return Pawn(char=char, pos=pos, side=side) if char.lower() == 'q': return Queen(char=char, pos=pos, side=side) if char.lower() == 'r': return Rook(char=char, pos=pos, side=side) return Piece(char=char, pos=pos, side=side)
def _all_moves(self) -> Iterator[Move]: yield from Bishop._all_moves(self) yield from Rook._all_moves(self)
from pawn import Pawn from board import Board from rook import Rook board = Board() piao = Pawn(0, (5, 4)) piao.code = 4 piao2 = Pawn(0, (2, 4)) piao2.code = 4 piao3 = Pawn(0, (4, 2)) piao3.code = 4 piao4 = Pawn(0, (4, 6)) piao4.code = 4 torre = Rook(0, (4, 4)) board.createBoard() board.addPieceToBoard(piao) board.addPieceToBoard(piao2) board.addPieceToBoard(piao3) board.addPieceToBoard(piao4) board.addPieceToBoard(torre) for chessFile in board.board: print(chessFile) for pieceOnBoard in board.piecesOnBoard: print(pieceOnBoard) torre.calculateValidMoves(board) print(torre.validMoves) for validRookMove in torre.validMoves: