def test2(): players = tourney_sim.get_players(20) t = tourney.MatchingPairedTournament(players, weight_function5) rounds = 4 * (len(players) - 1) tourney_sim.test_harness(t, rounds, True, True)
def test5(): players = tourney_sim.get_players(8) """card_system = (frozenset([(0, 4), (1, 5), (2, 6), (3, 7)]), frozenset([(0, 2), (1, 3), (4, 6), (5, 7)]), frozenset([(0, 1), (2, 3), (4, 5), (6, 7)])) final_card_rankings = {x : 8 - x for x in range(8)} """ card_system = (frozenset([(0, 7), (1, 6), (2, 5), (3, 4)]), frozenset([(0, 3), (1, 2)]), frozenset([(0, 1)])) final_card_rankings = {0: 3, 1: 2, 2: 1, 3: 1, 4: 0, 5: 0, 6: 0, 7: 0} t = tourney.PowerMatchedTournament(players, card_system=card_system, final_card_rankings=final_card_rankings) rounds = 3 tourney_sim.test_harness(t, rounds)
def evaluation_function(x): card_system = [] for r in x: r_without_byes = r[:r.index(NUM_PLAYERS)] if len(r_without_byes) % 2 == 1: del r_without_byes[-1] card_system.append( tuple(zip(r_without_byes[::2], r_without_byes[1::2]))) card_system = tuple(card_system) final_card_rankings = {n: NUM_PLAYERS - n for n in range(NUM_PLAYERS)} total_rank_coefficient = 0.0 for trial in range(FITNESS_SAMPLE_SIZE): players = tourney_sim.get_players(NUM_PLAYERS) if SEEDED: players = [ y[0] for y in sorted([(p, p.ability + random.gauss(0, NOISE_FACTOR)) for p in players], key=lambda x: -x[1]) ] t = tourney.PowerMatchedTournament( players, card_system=card_system, final_card_rankings=final_card_rankings) total_rank_coefficient += tourney_sim.test_harness( t, NUM_ROUNDS, False)[TEST_STATISTIC] for x, y in itertools.combinations(players, 2): total_rank_coefficient -= repeat_penalty( t.win_matrix_entry(x, y) + t.win_matrix_entry(y, x)) return total_rank_coefficient
def test1(): players = tourney_sim.get_players() t = tourney.RoundRobinPairedTournament(players) rounds = (len(players) - 1) tourney_sim.test_harness(t, rounds)
def test3(): NUM_TRIALS = 500 PLAYERS = 20 ROUNDS = 19 ranks = {x: [] for x in ('round_robin', 'matching1', 'matching2')} print("Round robin data") print("----------------") for trial in range(NUM_TRIALS): players = tourney_sim.get_players(PLAYERS) t = tourney.RoundRobinPairedTournament(players) rc = tourney_sim.test_harness(t, ROUNDS, verbose=False)['rank_coefficient'] print("{0:8.6f}".format(rc)) ranks['round_robin'].append(rc) print("") print("Matching 1 data ") print("----------------") for trial in range(NUM_TRIALS): players = tourney_sim.get_players(PLAYERS) t = tourney.MatchingPairedTournament(players, weight_function4) rc = tourney_sim.test_harness(t, ROUNDS, verbose=False)['rank_coefficient'] print("{0:8.6f}".format(rc)) ranks['matching1'].append(rc) print("") print("Matching 2 data ") print("----------------") for trial in range(NUM_TRIALS): players = tourney_sim.get_players(PLAYERS) t = tourney.MatchingPairedTournament(players, weight_function5) rc = tourney_sim.test_harness(t, ROUNDS, verbose=False)['rank_coefficient'] print("{0:8.6f}".format(rc)) ranks['matching2'].append(rc) print("") print("Summary stats ") print("----------------") #print(ranks['round_robin']) #print(ranks['random_swiss']) #print(ranks['matching']) means = { x: sum(ranks[x]) / len(ranks[x]) for x in ('round_robin', 'matching1', 'matching2') } sample_stds = { x: (sum([(y - means[x])**2 for y in ranks[x]]) / (len(ranks[x]) - 1))**0.5 for x in ('round_robin', 'matching1', 'matching2') } print(' Method Mean Std.Dev.') print('------------ -------- --------') print('Round robin {0:0.6f} {1:0.6f}'.format(means['round_robin'], sample_stds['round_robin'])) print('Matching 1 {0:0.6f} {1:0.6f}'.format(means['matching1'], sample_stds['matching1'])) print('Matching 2 {0:0.6f} {1:0.6f}'.format(means['matching2'], sample_stds['matching2']))
def run_test(tup): #tup[0] is a tournament, tup[1] is the number of rounds return tourney_sim.test_harness(tup[0], tup[1], verbose=False)[tup[2]]
def run_tournament(self): players = tourney_sim.get_players(self.num_players) t = tourney.MatchingPairedTournament(players, weight_function2) print("Starting a tournament with {0} players and {1} rounds".format( self.num_players, self.num_rounds)) tourney_sim.test_harness(t, self.num_rounds, verbose=True)