def run(log_dir, episodes, rounds):
    model_path = log_dir + '/rl1_model.h5'
    rl_player = RLPlayer(name='RL1', model_path=model_path, rounds=rounds)
    players = [
        rl_player,
        ChallengePlayer(name='Tick'),
        ChallengePlayer(name='Trick'),
        ChallengePlayer(name='Track')
    ]
    players = [
        rl_player,
        GreedyPlayer(name='Tick'),
        GreedyPlayer(name='Trick'),
        GreedyPlayer(name='Track')
    ]
    sum_won = 0
    for e in range(episodes):
        tournament = Tournament()
        [tournament.register_player(player) for player in players]
        tournament.play(rounds=rounds, use_counting_factor=False)
        rl_player.replay()
        sum_won += rl_player.won[0]
        print_stats_winning(rl_player.won_stich, rl_player.won, e, sum_won)
        rl_player.reset_stats()
    rl_player.model.save(model_path)
Exemple #2
0
def run_game(players, point_limit=1000, number_of_tournaments=1000):
    tournament = Tournament(point_limit=point_limit)
    [tournament.register_player(player=player) for player in players]

    team_1_won = 0
    team_2_won = 0

    start = timer()

    for _ in range(number_of_tournaments):
        tournament.play()
        if tournament.teams[0].won(point_limit=point_limit):
            team_1_won += 1
        else:
            team_2_won += 1

    end = timer()
    print("\nTo run {0} tournaments it took {1:.2f} seconds.".format(
        number_of_tournaments, end - start))

    difference = abs(team_1_won - team_2_won)
    print("Difference: ", difference)
    print("Team 1 ({0}, {1}): {2}".format(players[0].name, players[2].name,
                                          team_1_won))
    print("Team 2 ({0}, {1}): {2}".format(players[1].name, players[3].name,
                                          team_2_won))
    assert True
Exemple #3
0
def test_is_random():
    point_limit = 1000
    number_of_tournaments = 1000
    mean = number_of_tournaments * 0.5  # assume that a RandomPlayer has a 50% chance to win
    variance = mean * (1 - 0.5)
    standard_deviation = int(floor(sqrt(variance)))

    random_players = [RandomPlayer(name=i) for i in range(4)]
    tournament = Tournament(point_limit=point_limit)
    [tournament.register_player(player=player) for player in random_players]

    team_1_won = 0
    team_2_won = 0

    start = timer()

    for _ in range(number_of_tournaments):
        tournament.play()
        if tournament.teams[0].won(point_limit=point_limit):
            team_1_won += 1
        else:
            team_2_won += 1

    end = timer()
    print("\nTo run {0} tournaments it took {1:.2f} seconds.".format(
        number_of_tournaments, end - start))

    difference = abs(team_1_won - team_2_won)
    print("Difference: ", difference)
    print("Team 1: ", team_1_won)
    print("Team 2: ", team_2_won)
    assert difference in range(0, 2 * standard_deviation)
def run_statistics(players):
    point_limit = 1000
    number_of_tournaments = 1000

    tournament = Tournament(point_limit=point_limit)
    [tournament.register_player(player=player) for player in players]

    team_1_won = 0
    team_2_won = 0

    start = timer()

    for _ in range(number_of_tournaments):
        tournament.play()
        if tournament.teams[0].won(point_limit=point_limit):
            team_1_won += 1
        else:
            team_2_won += 1

    end = timer()
    print("\nTo run {0} tournaments it took {1:.2f} seconds.".format(
        number_of_tournaments, end - start))

    difference = abs(team_1_won - team_2_won)
    print("Difference: ", difference)
    print("Team 1: ", team_1_won)
    print("Team 2: ", team_2_won)
    assert team_1_won > team_2_won
Exemple #5
0
def test_greedy():
    point_limit = 1000
    number_of_tournaments = 1000
    players = [
        GreedyPlayer(name='Greedy1'),
        RandomPlayer(name='Track'),
        GreedyPlayer(name='Greedy2'),
        RandomPlayer(name='Track')
    ]
    tournament = Tournament(point_limit=point_limit)
    [tournament.register_player(player=player) for player in players]

    team_1_won = 0
    team_2_won = 0

    start = timer()

    for _ in range(number_of_tournaments):
        tournament.play()
        if tournament.teams[0].won(point_limit=point_limit):
            team_1_won += 1
        else:
            team_2_won += 1

    end = timer()
    print("\nTo run {0} tournaments it took {1:.2f} seconds.".format(
        number_of_tournaments, end - start))

    difference = abs(team_1_won - team_2_won)
    print("Difference: ", difference)
    print("Team 1: ", team_1_won)
    print("Team 2: ", team_2_won)
    assert team_1_won > team_2_won
Exemple #6
0
def test_tournament_player_id(random_players):
    tournament = Tournament()
    [tournament.register_player(player=player) for player in random_players]
    assert tournament.players[0].name == 'Tick'
    assert tournament.players[1].name == 'Trick'
    assert tournament.players[2].name == 'Track'
    assert tournament.players[3].name == 'Dagobert'
Exemple #7
0
def test_tournament(random_players):
    point_limit = 1000
    tournament = Tournament(point_limit=point_limit)
    [tournament.register_player(player=player) for player in random_players]
    tournament.play()
    points = [tournament.teams[0].points, tournament.teams[1].points]
    assert point_limit <= max(points) and point_limit > min(points)
Exemple #8
0
def test_tournament_rounds(random_players):
    point_limit = 100
    tournament = Tournament(point_limit=point_limit)
    [tournament.register_player(player=player) for player in random_players]
    tournament.play(rounds=20)
    points = [tournament.teams[0].points, tournament.teams[1].points]
    assert 3 * point_limit < max(points)
Exemple #9
0
def start_tournament(points):
    tournament = Tournament(point_limit=points)

    players = [RandomPlayer(name='Tick'), RandomPlayer(name='Trick'), RandomPlayer(name='Track'),
               GreedyPlayer(name='Dagobert')]
    players = [RandomPlayer(name='Tick'), RandomPlayer(name='Trick'), ChallengePlayer(name='Track'),
               GreedyPlayer(name='Dagobert')]

    [tournament.register_player(player) for player in players]

    tournament.play()
Exemple #10
0
def test_tournament_register(random_players):
    for _ in range(3):
        tournament = Tournament()
        [
            tournament.register_player(player=player)
            for player in random_players
        ]
        tournament.play(rounds=1)
        assert tournament.teams[0].players[0].name == 'Tick'
        assert tournament.teams[0].players[1].name == 'Track'
        assert tournament.teams[1].players[0].name == 'Trick'
        assert tournament.teams[1].players[1].name == 'Dagobert'
Exemple #11
0
def run(log_dir, episodes, rounds):
    save_model_path = log_dir + '/sl1_model.h5'
    trumpf_model_path = log_dir + '/trumpf_network_model_final__2018-06-18_112248.h5'
    game_model_path = log_dir + '/Supervised_Gamenetwork__network_model_282__2018-09-02_122529.h5'
    sl_player = SLPlayer3LP222(name='SL1', game_model_path=game_model_path, trumpf_model_path=trumpf_model_path, rounds=rounds)
    # players = [sl_player, ChallengePlayer(name='Tick'), ChallengePlayer(name='Trick'), ChallengePlayer(name='Track')]
    players = [sl_player, GreedyPlayer(name='Tick'), GreedyPlayer(name='Trick'), GreedyPlayer(name='Track')]
    sum_won = 0
    for e in range(episodes):
        tournament = Tournament()
        [tournament.register_player(player) for player in players]
        tournament.play(rounds=rounds, use_counting_factor=False)
        sum_won += sl_player.won[0]
        print_stats_winning(sl_player.won_stich, sl_player.won, e, sum_won)
        sl_player.reset_stats()