Exemplo n.º 1
0
def test_get_next_state_valid_move():
    """Check that the board state is updated if a legal move is performed.
    """
    game = BloomsGame(size=4)
    board = game.getInitBoard()

    # Attempt a legal move
    player = -1
    move = ((6, 2, 2), ())
    move_idx = board.move_map_player_0[move]
    next_board, next_player = game.getNextState(board, player, action=move_idx)

    next_board.board_2d
    for r in range(next_board.board_2d.shape[0]):
        for q in range(next_board.board_2d.shape[1]):
            if (q == 6) and (r == 2):
                assert next_board.board_2d[r, q] == 2
            else:
                assert next_board.board_2d[r, q] == 0

    assert next_player == -player
Exemplo n.º 2
0
def test_get_next_state_invalid_move():
    """Check that the original (i.e. unchanged) board state is returned if an
    invalid move is performed.
    """
    game = BloomsGame(size=4)
    board = game.getInitBoard()

    # Initialise the board with a stone
    board.place_stone((6, 2), colour=1)

    initial_board_array = board.get_board_3d()

    # Attempt an illegal move
    player = -1
    move = ((6, 2, 2), ())
    move_idx = board.move_map_player_0[move]
    next_board, next_player = game.getNextState(board, player, action=move_idx)

    post_move_board_array = next_board.get_board_3d()

    assert next_player == -player
    assert np.all(initial_board_array == post_move_board_array)