Esempio n. 1
0
def uct_playerlist():
    return [
        UCTPlayer(ucb_const=100, num_samples=10, name="A"),
        UCTPlayer(ucb_const=100, num_samples=10, name="A"),
        UCTPlayer(ucb_const=100, num_samples=10, name="A"),
        UCTPlayer(ucb_const=100, num_samples=10, name="A")
    ]
Esempio n. 2
0
def main():
    game_state = sample_game_states[18]

    num_simulations = 100
    ucb_constant = 0.1

    player = UCTPlayer(ucb_const=ucb_constant, num_samples=1, num_simulations=num_simulations)

    root_node = MCNode(game_state=game_state)
    mc_tree = MCTree(root_node=root_node)

    for sim_num in range(1, player.num_simulations + 1):
        selected_node = player.selection(mc_tree)
        rewards = player.simulation(selected_node)
        mc_tree.backup_rewards(leaf_node=selected_node, rewards=rewards)

        mc_tree.visualize_tree(ucb=player.ucb_const,
                               filename="img_{}".format(sim_num))

    filenames = ["img_{}.png".format(i) for i in range(player.num_simulations, 0, -1)]
    gif_name = "Gif_test.gif"
    duration = 0.2
    make_gif(filenames=filenames, outputname=gif_name, duration=duration)

    im = Image.open(gif_name)
    frames = [frame.copy() for frame in ImageSequence.Iterator(im)]
    frames.reverse()
    frames[0].save('reversed.gif', save_all=True, append_images=frames[1:])
Esempio n. 3
0
def main():
    sim_player_list = [
        NNPlayer(
            game_mode_nn='../players/models/bigger_classifier200.hdf5',
            partner_nn='../players/models/partner_model_wider_data_2.hdf5',
            solo_nn='../players/models/solo_model_wider_data_10.hdf5',
            wenz_nn='../players/models/wenz_model_wider_data_10.hdf5'),
        NNPlayer(
            game_mode_nn='../players/models/bigger_classifier200.hdf5',
            partner_nn='../players/models/partner_model_wider_data_2.hdf5',
            solo_nn='../players/models/solo_model_wider_data_10.hdf5',
            wenz_nn='../players/models/wenz_model_wider_data_10.hdf5'),
        NNPlayer(
            game_mode_nn='../players/models/bigger_classifier200.hdf5',
            partner_nn='../players/models/partner_model_wider_data_2.hdf5',
            solo_nn='../players/models/solo_model_wider_data_10.hdf5',
            wenz_nn='../players/models/wenz_model_wider_data_10.hdf5'),
        NNPlayer(
            game_mode_nn='../players/models/bigger_classifier200.hdf5',
            partner_nn='../players/models/partner_model_wider_data_2.hdf5',
            solo_nn='../players/models/solo_model_wider_data_10.hdf5',
            wenz_nn='../players/models/wenz_model_wider_data_10.hdf5')
    ]

    game_state = sample_game_states[15]

    num_simulations = 100
    ucb_constant = 0.1

    player = UCTPlayer(ucb_const=ucb_constant,
                       num_samples=1,
                       num_simulations=num_simulations,
                       simulation_player_list=None)

    root_node = MCNode(game_state=game_state)
    mc_tree = MCTree(root_node=root_node)

    for sim_num in range(1, player.num_simulations + 1):
        selected_node = player.selection(mc_tree)
        rewards = player.simulation(selected_node)
        mc_tree.backup_rewards(leaf_node=selected_node, rewards=rewards)

    mc_tree.visualize_tree(
        ucb=player.ucb_const,
        filename="Tree_{}nodes{}ucb_const{}game_mode".format(
            num_simulations, ucb_constant, game_state["game_mode"]))
Esempio n. 4
0
def main():
    sim_player_list = [NNPlayer(game_mode_nn='../players/models/bigger_classifier200.hdf5',
                                partner_nn='../players/models/partner_model_wider_data_2.hdf5',
                                solo_nn='../players/models/solo_model_wider_data_10.hdf5',
                                wenz_nn='../players/models/wenz_model_wider_data_10.hdf5'),
                       NNPlayer(game_mode_nn='../players/models/bigger_classifier200.hdf5',
                                partner_nn='../players/models/partner_model_wider_data_2.hdf5',
                                solo_nn='../players/models/solo_model_wider_data_10.hdf5',
                                wenz_nn='../players/models/wenz_model_wider_data_10.hdf5'),
                       NNPlayer(game_mode_nn='../players/models/bigger_classifier200.hdf5',
                                partner_nn='../players/models/partner_model_wider_data_2.hdf5',
                                solo_nn='../players/models/solo_model_wider_data_10.hdf5',
                                wenz_nn='../players/models/wenz_model_wider_data_10.hdf5'),
                       NNPlayer(game_mode_nn='../players/models/bigger_classifier200.hdf5',
                                partner_nn='../players/models/partner_model_wider_data_2.hdf5',
                                solo_nn='../players/models/solo_model_wider_data_10.hdf5',
                                wenz_nn='../players/models/wenz_model_wider_data_10.hdf5')]

    cum_depth = 0
    for game_state in sample_game_states:

        num_simulations = 100
        ucb_constant = 0.1

        player = UCTPlayer(ucb_const=ucb_constant,
                           num_samples=1,
                           num_simulations=num_simulations,
                           simulation_player_list=None)

        root_node = MCNode(game_state=game_state)
        mc_tree = MCTree(root_node=root_node)

        for sim_num in range(1, player.num_simulations + 1):
            selected_node = player.selection(mc_tree)
            rewards = player.simulation(selected_node)
            mc_tree.backup_rewards(leaf_node=selected_node, rewards=rewards)

        depth = mc_tree.max_depth()
        cum_depth += depth

    print('Average tree depth without NN:', cum_depth / len(sample_game_states))

    cum_depth_with_nn = 0
    for game_state in sample_game_states:

        num_simulations = 100
        ucb_constant = 0.1

        player = UCTPlayer(ucb_const=ucb_constant,
                           num_samples=1,
                           num_simulations=num_simulations,
                           simulation_player_list=sim_player_list)

        root_node = MCNode(game_state=game_state)
        mc_tree = MCTree(root_node=root_node)

        for sim_num in range(1, player.num_simulations + 1):
            selected_node = player.selection(mc_tree)
            rewards = player.simulation(selected_node)
            mc_tree.backup_rewards(leaf_node=selected_node, rewards=rewards)

        depth = mc_tree.max_depth()
        cum_depth_with_nn += depth

    print('Average tree depth with NN:', cum_depth_with_nn / len(sample_game_states))
Esempio n. 5
0
             partner_nn='../players/models/partner_model_bigger_1.hdf5',
             solo_nn='../players/models/solo_model_bigger_1.hdf5',
             wenz_nn='../players/models/wenz_model_bigger_1.hdf5'),
    NNPlayer(game_mode_nn='../players/models/bigger_classifier200.hdf5',
             partner_nn='../players/models/partner_model_bigger_1.hdf5',
             solo_nn='../players/models/solo_model_bigger_1.hdf5',
             wenz_nn='../players/models/wenz_model_bigger_1.hdf5'),
    NNPlayer(game_mode_nn='../players/models/bigger_classifier200.hdf5',
             partner_nn='../players/models/partner_model_bigger_1.hdf5',
             solo_nn='../players/models/solo_model_bigger_1.hdf5',
             wenz_nn='../players/models/wenz_model_bigger_1.hdf5')
]

playerlist = [
    UCTPlayer(name="A",
              num_samples=10,
              num_simulations=1000,
              simulation_player_list=None),
    RandomPlayer(name="B"),
    RandomPlayer(name="C"),
    RandomPlayer(name="D")
]

player_hands_partner = [[(OBER, ACORNS), (OBER, BELLS), (UNTER, BELLS),
                         (ACE, BELLS), (KING, LEAVES), (TEN, ACORNS),
                         (SEVEN, ACORNS), (NINE, ACORNS)],
                        [(OBER, LEAVES), (OBER, HEARTS), (UNTER, ACORNS),
                         (ACE, HEARTS), (SEVEN, HEARTS), (ACE, ACORNS),
                         (KING, BELLS), (SEVEN, BELLS)],
                        [(UNTER, LEAVES), (TEN, LEAVES), (KING, HEARTS),
                         (KING, ACORNS), (TEN, HEARTS), (SEVEN, LEAVES),
                         (EIGHT, ACORNS), (NINE, BELLS)],
Esempio n. 6
0
        wenz_nn='../players/models/trickplay_model_wenz_extended.hdf5'),
    NNPlayer(
        game_mode_nn='../players/models/bigger_classifier200.hdf5',
        partner_nn='../players/models/trickplay_model_partner_extended.hdf5',
        solo_nn='../players/models/trickplay_model_solo_extended.hdf5',
        wenz_nn='../players/models/trickplay_model_wenz_extended.hdf5'),
    NNPlayer(
        game_mode_nn='../players/models/bigger_classifier200.hdf5',
        partner_nn='../players/models/trickplay_model_partner_extended.hdf5',
        solo_nn='../players/models/trickplay_model_solo_extended.hdf5',
        wenz_nn='../players/models/trickplay_model_wenz_extended.hdf5')
]

playerlist = [
    UCTPlayer(num_samples=10,
              num_simulations=20,
              ucb_const=1,
              simulation_player_list=sim_player_list),
    # UCTPlayer(name="A", num_samples=10, num_simulations=100, ucb_const=1),
    # NNPlayer(game_mode_nn='../players/models/bigger_classifier200.hdf5',
    #          partner_nn='../players/models/trickplay_model_partner_extended.hdf5',
    #          solo_nn='../players/models/trickplay_model_solo_extended.hdf5',
    #          wenz_nn='../players/models/trickplay_model_wenz_extended.hdf5',
    #          use_extended_models=True),
    # HeuristicsPlayer(),
    # RandomPlayer(),
    # ISUCTPlayer(num_simulations=1000, ucb_const=2, simulation_player_list=None),
    HeuristicsPlayer(name="B"),
    HeuristicsPlayer(name="C"),
    HeuristicsPlayer(name="D")
]