Beispiel #1
0
    def is_check(board: Board, colour: Colour) -> bool:
        """Check if <colour> side got check.
        check = at least one opponent piece aims at own king
        """

        # Retrieve king position
        king_pos = board.get_positions_for_piece(Piece(PieceType.KING,
                                                       colour))[0]
        return king_pos in PositionsUnderThreat.all_positions_under_threat_for_side(
            colour, board)
Beispiel #2
0
 def test_get_positions_for_piece(self):
     board = Board()
     board.set_piece(Position(1, 0), Pieces.WHITE_KNIGHT)
     board.set_piece(Position(4, 0), Pieces.WHITE_KNIGHT)
     board.set_piece(Position(0, 7), Pieces.WHITE_KNIGHT)
     board.set_piece(Position(7, 7), Pieces.WHITE_KNIGHT)
     piece_positions = board.get_positions_for_piece(Pieces.WHITE_KNIGHT)
     assert set(piece_positions) == {
         Position(1, 0),
         Position(4, 0),
         Position(0, 7),
         Position(7, 7),
     }