Ejemplo n.º 1
0
def test_arabian_mate():
    """"""
    game = Game([
        [Empty() for _ in range(7)] + [King('black')],
        [Empty() for _ in range(7)] + [Tower('white')],
        [Empty() for _ in range(5)] +
        [Horse('white'), Empty(), Empty()],
        [Empty() for _ in range(8)],
        [Empty() for _ in range(8)],
        [Empty() for _ in range(8)],
        [Empty() for _ in range(8)],
        [Empty() for _ in range(8)],
    ])
    assert game.is_check('black'), print(game)
    assert game.is_checkmate('black'), print(game)
Ejemplo n.º 2
0
def test_damiano_mate():
    """"""
    game = Game([
        [Empty() for _ in range(5)] +
        [Tower('black'), King('black'), Empty()],
        [Empty()
         for _ in range(6)] + [Pawn('black'), Queen('white')],
        [Empty() for _ in range(6)] + [Pawn('white'), Empty()],
        [Empty() for _ in range(8)],
        [Empty() for _ in range(8)],
        [Empty() for _ in range(8)],
        [Empty() for _ in range(8)],
        [Empty() for _ in range(7)] + [King('white')],
    ])
    assert game.is_check('black'), print(game)
    assert game.is_checkmate('black'), print(game)
Ejemplo n.º 3
0
def test_anastasia_s_mate():
    """"""
    game = Game([
        [Empty() for _ in range(8)],
        [Empty() for _ in range(4)] +
        [Horse('white'), Empty(),
         Pawn('black'), King('black')],
        [Empty() for _ in range(8)],
        [Empty() for _ in range(7)] + [Tower('white')],
        [Empty() for _ in range(8)],
        [Empty() for _ in range(8)],
        [Empty() for _ in range(8)],
        [King('white')] + [Empty() for _ in range(7)],
    ])
    assert game.is_check('black'), print(game)
    assert game.is_checkmate('black'), print(game)
Ejemplo n.º 4
0
def test_black_swine_mate():
    """"""
    game = Game([
        [Empty() for _ in range(5)] +
        [Tower('black'), King('black'), Empty()],
        [Empty()
         for _ in range(6)] + [Tower('white'), Tower('white')],
        [Empty() for _ in range(8)],
        [Empty() for _ in range(8)],
        [Empty() for _ in range(8)],
        [Empty() for _ in range(8)],
        [Empty() for _ in range(8)],
        [Empty() for _ in range(8)],
    ])
    assert game.is_check('black'), print(game)
    assert game.is_checkmate('black'), print(game)
Ejemplo n.º 5
0
def test_no_move_to_current_position(piece):
    """Test that a piece cannot move to its current position."""
    for i in range(8):
        for j in range(8):
            new_board = Board([[Empty() for i in range(8)] for j in range(8)])
            new_board[i, j] = piece

            for move in piece.moves():
                assert move != (i, j), (f"Move {move} for piece {type(piece)} "
                                        "is current position.\n\n"
                                        f"{new_board}")
Ejemplo n.º 6
0
    def move(self, from_, to):
        piece = self.board[from_]

        # If a Pawn reaches eigth rank then replace by a queen.
        if isinstance(piece, Pawn) and to[0] in [0, 7]:
            piece = Queen(self.current_color)

        self.board[to] = piece
        self.board[from_] = Empty(None, self)
        self.current_color = self.opponent_color()
        return self
Ejemplo n.º 7
0
def test_no_moves_outside_board(piece):
    """Test that a piece cannot move outside the board."""
    for i in range(8):
        for j in range(8):
            new_board = Board([[Empty() for i in range(8)] for j in range(8)])
            new_board[i, j] = piece
            for move in piece.moves():
                assert move in product(
                    range(8),
                    range(8)), (f"Move {move} for piece {type(piece)} "
                                "is outside of the board.\n\n"
                                f"{new_board}")
Ejemplo n.º 8
0
def test_bishop_and_knight_mate():
    """"""
    game = Game([
        [Empty() for _ in range(7)] + [King('black')],
        [Empty() for _ in range(8)],
        [Empty() for _ in range(5)] +
        [Bishop('white'), King('white'),
         Horse('white')],
        [Empty() for _ in range(8)],
        [Empty() for _ in range(8)],
        [Empty() for _ in range(8)],
        [Empty() for _ in range(8)],
        [Empty() for _ in range(8)],
    ])
    assert game.is_check('black'), print(game)
    assert game.is_checkmate('black'), print(game)
Ejemplo n.º 9
0
 def empty_row(self):
     return [Empty(None, self) for j in range(len(self))]
Ejemplo n.º 10
0
def test_back_rank_mate():
    """"""
    game = Game([
        [Empty() for _ in range(3)] +
        [Tower('white'),
         Empty(), Empty(),
         King('black'),
         Empty()],
        [Empty() for _ in range(5)] +
        [Pawn('black'), Pawn('black'),
         Pawn('black')],
        [Empty() for _ in range(8)],
        [Empty() for _ in range(8)],
        [Empty() for _ in range(8)],
        [Empty() for _ in range(8)],
        [Empty() for _ in range(8)],
        [Empty() for _ in range(8)],
    ])
    assert game.is_check('black'), print(game)
    assert game.is_checkmate('black'), print(game)
Ejemplo n.º 11
0
def test_anderssen_s_mate():
    """"""
    game = Game([
        [Empty()
         for _ in range(6)] + [King('black'), Tower('white')],
        [Empty() for _ in range(6)] + [Pawn('white'), Empty()],
        [Empty() for _ in range(5)] +
        [King('white'), Empty(), Empty()],
        [Empty() for _ in range(8)],
        [Empty() for _ in range(8)],
        [Empty() for _ in range(8)],
        [Empty() for _ in range(8)],
        [Empty() for _ in range(8)],
    ])
    assert game.is_check('black'), print(game)
    assert game.is_checkmate('black'), print(game)
Ejemplo n.º 12
0
def test_damiano_s_bishop_mate():
    """"""
    game = Game([
        [Empty() for _ in range(5)] +
        [King('black'), Empty(), Empty()],
        [Empty() for _ in range(5)] +
        [Queen('white'), Empty(), Empty()],
        [Empty()
         for _ in range(6)] + [Bishop('white'), Empty()],
        [Empty() for _ in range(8)],
        [Empty() for _ in range(8)],
        [Empty() for _ in range(8)],
        [Empty() for _ in range(8)],
        [Empty() for _ in range(7)] + [King('white')],
    ])
    assert game.is_check('black'), print(game)
    assert game.is_checkmate('black'), print(game)
Ejemplo n.º 13
0
def test_box_mate():
    """"""
    game = Game([
        [Tower('white'), Empty(), Empty()] + [King('black')] +
        [Empty() for _ in range(4)],
        [Empty() for _ in range(8)],
        [Empty()
         for _ in range(3)] + [King('white')] + [Empty() for _ in range(4)],
        [Empty() for _ in range(8)],
        [Empty() for _ in range(8)],
        [Empty() for _ in range(8)],
        [Empty() for _ in range(8)],
        [Empty() for _ in range(8)],
    ])
    assert game.is_check('black'), print(game)
    assert game.is_checkmate('black'), print(game)
Ejemplo n.º 14
0
def test_bodens_mate():
    """"""
    game = Game([
        [Empty(), Empty()] + [King('black'), Tower('black')] +
        [Empty() for _ in range(4)],
        [Empty()
         for _ in range(3)] + [Pawn('black')] + [Empty() for _ in range(4)],
        [Bishop('white')] + [Empty() for _ in range(7)],
        [Empty() for _ in range(8)],
        [Empty() for _ in range(5)] +
        [Bishop('white'), Empty(), Empty()],
        [Empty() for _ in range(8)],
        [Empty() for _ in range(8)],
        [Empty() for _ in range(8)],
    ])
    assert game.is_check('black'), print(game)
    assert game.is_checkmate('black'), print(game)
Ejemplo n.º 15
0
def test_blackburne_s_mate():
    """"""
    game = Game([
        [Empty() for _ in range(5)] +
        [Tower('black'), King('black'), Empty()],
        [Empty() for _ in range(7)] + [Bishop('white')],
        [Empty() for _ in range(8)],
        [Empty() for _ in range(6)] + [Horse('white'), Empty()],
        [Empty() for _ in range(8)],
        [Empty() for _ in range(8)],
        [Empty(), Bishop('white')] + [Empty() for _ in range(6)],
        [Empty() for _ in range(8)],
    ])
    assert game.is_check('black'), print(game)
    assert game.is_checkmate('black'), print(game)