def test_remove_piece(self): board = Board() board.set_piece(Position(1, 2), Pieces.BLACK_BISHOP) assert board.get_piece(Position(1, 2)) == Pieces.BLACK_BISHOP board.remove_piece(Position(1, 2)) assert board.get_piece(Position(1, 2)) is None
def test_set_piece(self): board = Board() board.set_piece(Position(4, 4), Pieces.WHITE_ROOK) # TODO(amirov-m): What is the right order for actual and expected? assert board.get_piece(Position(4, 4)) == Pieces.WHITE_ROOK board.set_piece(Position(7, 7), Pieces.BLACK_PAWN) assert board.get_piece(Position(7, 7)) == Pieces.BLACK_PAWN
def all_positions_under_threat_for_side(colour: Colour, board: Board) -> List[Position]: positions_under_threat = [] for pos in board.get_positions_for_side(Colour.change_colour(colour)): positions_under_threat.extend( PositionsUnderThreat.positions_under_threat( pos, board.get_piece(pos), board)) return positions_under_threat
def test_remove_piece_empty_cell(self): board = Board() board.remove_piece(Position(3, 4)) assert board.get_piece(Position(3, 4)) is None
def test_set_piece_rewrite_piece(self): board = Board() board.set_piece(Position(1, 3), Pieces.WHITE_QUEEN) board.set_piece(Position(1, 3), Pieces.BLACK_KING) assert board.get_piece(Position(1, 3)) == Pieces.BLACK_KING
def is_position_enemy(pos: Position, colour: Colour, board: Board) -> bool: """Check if position occupied with enemy piece.""" # Retrieve piece. piece = board.get_piece(pos) return piece is not None and piece.colour != colour