Exemple #1
0
def test_board_move():
    board = Chessboard(chess.STARTING_FEN)

    moves = (
        chess.Move(
            initial_square=96,
            target_square=64,
            moving_piece="P",
            attacked_piece=".",
            capture=False,
            score=None,
        ),
        chess.Move(
            initial_square=16,
            target_square=48,
            moving_piece="p",
            attacked_piece=".",
            capture=False,
            score=None,
        ),
        chess.Move(
            initial_square=112,
            target_square=48,
            moving_piece="R",
            attacked_piece="p",
            capture=True,
            score=None,
        ),
    )

    for move in moves:
        board.move(move)

        assert move.attacked_piece != board.board[move.target_square]
        assert move.moving_piece == board.board[move.target_square]
        assert board.board[move.initial_square] == "."
Exemple #2
0
def test_board_undo_move():
    board = Chessboard(chess.STARTING_FEN)
    og_board = board.board

    moves = (
        chess.Move(
            initial_square=96,
            target_square=64,
            moving_piece="P",
            attacked_piece=".",
            capture=False,
            score=None,
        ),
        chess.Move(
            initial_square=16,
            target_square=48,
            moving_piece="p",
            attacked_piece=".",
            capture=False,
            score=None,
        ),
        chess.Move(
            initial_square=113,
            target_square=80,
            moving_piece="N",
            attacked_piece=".",
            capture=False,
            score=None,
        ),
    )

    for move in moves:
        board.move(move)
        assert board.board != og_board
        board.undo_move()
        assert board.board == og_board