Esempio n. 1
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. 2
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. 3
0
def test_play():
    if skip_slow:
        py.test.skip("too slow")

    from ggplib.player.gamemaster import GameMaster

    game_info = lookup.by_name("draughts_killer_10x10")
    gm = GameMaster(game_info, verbose=False)

    # add two python players
    gm.add_player(create_player(), "white")
    gm.add_player(create_player(), "black")

    gm.start(meta_time=2, move_time=2)
    gm.play_to_end()

    # check scores/depth make some sense
    print gm.scores
Esempio n. 4
0
def test_speed():
    gm = GameMaster(get_gdl_for_game("reversi"))

    # add two python players
    a = get.get_player("simplemcts")
    a.skip_single_moves = True
    a.max_tree_playout_iterations = 200

    b = get.get_player("simplemcts")
    b.skip_single_moves = True
    b.max_tree_playout_iterations = 200

    gm.add_player(a, "red")
    gm.add_player(b, "black")

    import time
    gm.start(meta_time=10, move_time=5)
    s = time.time()
    gm.play_to_end()
    print "DONE", time.time() - s
def test_breakthrough():
    gm = GameMaster(get_gdl_for_game("breakthrough"))

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

    gurgeh = GurgehPlayer("Gurgeh")
    gurgeh.max_tree_search_time = 1
    gurgeh.max_tree_search_time = 1
    gurgeh.thread_workers = 2

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

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

    print "white_score", pymcs.name, gm.get_score("white")
    print "black_score", gurgeh.name, gm.get_score("black")
Esempio n. 6
0
def play_game(generation_name, num_previous_states):
    game = "breakthrough"

    # ensure we have a network
    man = get_manager()
    generation_descr = templates.default_generation_desc(game,
                                                         multiple_policy_heads=True,
                                                         num_previous_states=num_previous_states)

    nn = man.create_new_network(game, "tiny", generation_descr)
    man.save_network(nn, generation_name)
    nn.summary()

    conf = templates.puct_config_template(generation_name, "compete")

    gm = GameMaster(get_gdl_for_game(game))

    gm.add_player(CppPUCTPlayer(conf=conf), "white")
    gm.add_player(get.get_player("random"), "black")

    gm.start(meta_time=30, move_time=15)
    gm.play_to_end()
Esempio n. 7
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. 8
0
def test_puct_tournament():
    gm = GameMaster(get_gdl_for_game("breakthrough"))

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

    black = PUCTPlayer(conf=default_puct_config)

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

    acc_black_score = 0
    acc_red_score = 0
    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 "white_score", gm.players_map["white"].name, acc_red_score
    print "black_score", gm.players_map["black"].name, acc_black_score
Esempio n. 9
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