Esempio n. 1
0
def test_tictactoe_take_win():
    gm = GameMaster(get_gdl_for_game("ticTacToe"))

    # add two c++ players
    gm.add_player(get.get_player("ggtest1"), "xplayer")
    gm.add_player(get.get_player("ggtest1"), "oplayer")

    str_state = '''
    (true (control xplayer))
    (true (cell 2 2 x))
    (true (cell 3 2 o))
    (true (cell 3 3 x))
    (true (cell 2 3 o))
    (true (cell 3 1 b))
    (true (cell 2 1 b))
    (true (cell 1 3 b))
    (true (cell 1 2 b))
    (true (cell 1 1 b)) '''

    gm.start(meta_time=30, move_time=2,
             initial_basestate=gm.convert_to_base_state(str_state))

    # play a single move - should take win
    move = gm.play_single_move()
    assert str(move[0]) == "(mark 1 1)"
    assert str(move[1]) == "noop"

    gm.play_to_end(last_move=move)

    # check scores/depth make some sense
    assert gm.scores['xplayer'] == 100
    assert gm.scores['oplayer'] == 0
    assert gm.get_game_depth() == 1
Esempio n. 2
0
def test_tictactoe_cpp_play():
    gm = GameMaster(get_gdl_for_game("ticTacToe"))

    # add two c++ players
    gm.add_player(get.get_player("random"), "xplayer")
    gm.add_player(get.get_player("legal"), "oplayer")

    gm.start(meta_time=10, move_time=5)
    gm.play_to_end()

    # check scores/depth make some sense
    assert sum(gm.scores.values()) == 100
    assert 5 <= gm.get_game_depth() <= 9
Esempio n. 3
0
def test_tictactoe_play_verbose():
    gm = GameMaster(lookup.by_name("ticTacToe"), verbose=True)

    # add two python players
    gm.add_player(get.get_player("pyrandom"), "xplayer")
    gm.add_player(get.get_player("pylegal"), "oplayer")

    gm.start(meta_time=10, move_time=5)
    gm.play_to_end()

    # check scores/depth make some sense
    assert sum(gm.scores.values()) == 100
    assert 5 <= gm.get_game_depth() <= 9
Esempio n. 4
0
def test_fast_plays():
    ''' very fast rollouts, basically this config of puct player is a policy player '''
    gm = GameMaster(get_gdl_for_game("breakthrough"))

    import attr
    conf = confs.PUCTPlayerConfig(**attr.asdict(default_puct_config))
    conf.verbose = False

    # just checking that we haven't modified default
    assert not conf.verbose and default_puct_config.verbose

    conf.playouts_per_iteration = 1
    conf.playouts_per_iteration_noop = 0
    conf.dirichlet_noise_alpha = -1
    print conf

    # add two players
    white = PUCTPlayer(conf=conf)
    black = PUCTPlayer(conf=conf)

    gm.add_player(white, "white")
    gm.add_player(black, "black")

    acc_black_score = 0
    acc_red_score = 0
    s = time.time()
    for _ in range(ITERATIONS):
        gm.start(meta_time=30, move_time=15)
        gm.play_to_end()

        acc_black_score += gm.scores["black"]
        acc_red_score += gm.scores["white"]

        print gm.get_game_depth()

    print "time taken", time.time() - s
    print "white_score", gm.players_map["white"].name, acc_red_score
    print "black_score", gm.players_map["black"].name, acc_black_score
Esempio n. 5
0
def test_tictactoe_play_test_db_lookup():
    game_gdl_str = get_gdl_for_game("ticTacToe", dict(mark="kram",
                                                      noop="notamove",
                                                      cell="bell",
                                                      oplayer="doobie"))

    gm = GameMaster(game_gdl_str)

    # add two python players
    gm.add_player(get.get_player("pyrandom"), "xplayer")
    gm.add_player(get.get_player("pylegal"), "oplayer")

    gm.start(meta_time=10, move_time=5)
    gm.play_to_end()

    # check scores/depth make some sense
    assert sum(gm.scores.values()) == 100
    assert 5 <= gm.get_game_depth() <= 9
Esempio n. 6
0
def test_breakthrough():
    ' mcs player vs ggtest1 '
    gm = GameMaster(get_gdl_for_game("breakthrough"))

    # add two players
    white = get.get_player("pymcs")
    white.max_run_time = 0.25

    black = get.get_player("simplemcts")
    black.skip_single_moves = True

    gm.add_player(white, "white")
    gm.add_player(black, "black")

    gm.start(meta_time=30, move_time=2.0)
    gm.play_to_end()

    # hopefully simplemcts wins!  Not a great test.
    assert gm.scores["white"] == 0
    assert gm.scores["black"] == 100

    # check scores/depth make some sense
    assert sum(gm.scores.values()) == 100
    assert gm.get_game_depth() >= 10