Esempio n. 1
0
    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
Esempio n. 2
0
    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
Esempio n. 3
0
 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
Esempio n. 4
0
 def test_remove_piece_empty_cell(self):
     board = Board()
     board.remove_piece(Position(3, 4))
     assert board.get_piece(Position(3, 4)) is None
Esempio n. 5
0
 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
Esempio n. 6
0
    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