示例#1
0
def test_get_symmetries():
    """Check that the function correctly creates six new reflected boards and
    policy vectors, one for each axis of symmetry.
    """
    game = BloomsGame(size=4, score_target=15)
    board = game.getInitBoard()

    # Place stones
    board.place_stone(position=(3, 1), colour=1)
    board.place_stone(position=(5, 1), colour=2)
    board.place_stone(position=(3, 5), colour=3)
    board.place_stone(position=(1, 5), colour=4)

    # board.visualise(show_coords=True, title="Original")

    # Create a dummy policy vector
    pi = np.random.random_sample(game.getActionSize())

    profiler = Profiler()
    profiler.start()

    symmetrical_states = game.getSymmetries(board, pi)

    profiler.stop()
    print(profiler.output_text(unicode=True, color=True))

    assert len(symmetrical_states) == 24
    assert symmetrical_states[1][1][37] == pi[52]
    assert symmetrical_states[1][1][614] == pi[1277]

    assert all(
        [sum(x[1]) == pytest.approx(sum(pi)) for x in symmetrical_states])
示例#2
0
def test_get_action_size_base3():
    """Check that the correct action space size is returned for a base 3 board.
    """
    game = BloomsGame(size=3)
    n_spaces = 19

    assert game.getActionSize() == 2 * n_spaces + perm(n_spaces, 2)
示例#3
0
def test_get_valid_moves():
    """Test that the valid moves vector is correctly built.
    """
    game = BloomsGame(size=4)
    board = game.getInitBoard()

    valid_moves = game.getValidMoves(board, player=-1)
    assert len(valid_moves) == game.getActionSize()
    assert np.all((valid_moves == 0) | (valid_moves == 1))