def get_normal_board_placement(self): """ Method to set the pieces properly on the chessboard for the 'normal' start position. This is the only method that is actually called by the program itself. All the other 'get_*_board_placement' methods are used solely in testing. """ rank = 1 self.__board[rank][1].piece = Rook(is_white=True) self.__board[rank][2].piece = Knight(is_white=True) self.__board[rank][3].piece = Bishop(is_white=True) self.__board[rank][4].piece = Queen(is_white=True) self.__board[rank][5].piece = King(is_white=True) self.__board[rank][6].piece = Bishop(is_white=True) self.__board[rank][7].piece = Knight(is_white=True) self.__board[rank][8].piece = Rook(is_white=True) rank = 8 self.__board[rank][1].piece = Rook(is_white=False) self.__board[rank][2].piece = Knight(is_white=False) self.__board[rank][3].piece = Bishop(is_white=False) self.__board[rank][4].piece = Queen(is_white=False) self.__board[rank][5].piece = King(is_white=False) self.__board[rank][6].piece = Bishop(is_white=False) self.__board[rank][7].piece = Knight(is_white=False) self.__board[rank][8].piece = Rook(is_white=False) for file in range(1, 9): self.__board[2][file].piece = Pawn(is_white=True) self.__board[7][file].piece = Pawn(is_white=False)
def get_stalemate_board_placement(self): """ Method to set the pieces properly on the chessboard, for testing purposes. The next move for black is a position in which the computer can stalemate the opponent. (The computer will avoid stalemating) """ self.__board[6][8].piece = King(is_white=False) self.__board[3][2].piece = Queen(is_white=False) self.__board[2][3].piece = Queen(is_white=False) self.__board[1][1].piece = King(is_white=True)
def get_special_moves_applied(self, move, piece): """ Method to apply the special cases of the pawn two step move, the pawn promotion, the rook initial move, the king initial move. If the moved piece is a pawn, its initial square gets changed so it can no longer take two steps and if it reached the promotion zone, the piece becomes a queen. If the move is the two step move, the pawn moves two steps forward. If the moved piece is a rook, it can no longer partake in castling. If the moved piece is a king, it can no longer partake in castling. :param move: Move, object recording details about the move to be performed. :param piece: Piece, object recording details about the piece that is being moved. """ piece_is_pawn = isinstance(piece, Pawn) piece_is_rook = isinstance(piece, Rook) piece_is_king = isinstance(piece, King) if piece_is_pawn: pawn_is_on_initial_square = piece.initial_square pawn_reached_promotion = (move.move_to.rank == 8 and piece.is_white ) or (move.move_to.rank == 1 and not piece.is_white) if pawn_is_on_initial_square: self.get_pawn_two_step_move_applied(move, piece) elif pawn_reached_promotion: move.move_to.piece = Queen(piece.is_white) elif piece_is_rook: if piece.can_castle: piece.can_castle = False move.changed_initial_position = True elif piece_is_king: piece.can_castle = False
def get_check_board_placement(self): """ Method to set the pieces properly on the chessboard, for testing purposes. The next move is a position in which the computer can check the opponent. """ self.__board[6][8].piece = King(is_white=False) self.__board[2][8].piece = Queen(is_white=False) self.__board[1][1].piece = King(is_white=True)
def get_failing_castling_board_placement(self): """ Method to set the pieces properly on the chessboard, for testing purposes. The next move for white is a position in which the computer cannot castle. """ self.__board[8][1].piece = Queen(is_white=False) self.__board[7][7].piece = Pawn(is_white=True) self.__board[6][7].piece = Pawn(is_white=True) self.__board[6][8].piece = King(is_white=False) self.__board[1][1].piece = Rook(is_white=True) self.__board[1][5].piece = King(is_white=True)