-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathassess.py
106 lines (92 loc) · 3.26 KB
/
assess.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
import sys
import time
import numpy
from environment_registry import get_env_module
from evaluation import Bot, Tournament
from species import get_species
from paths import build_tournament_results_path
import settings
def run_generation_ladder(
environment_name,
species_list, # [(species, low_gen, high_gen), ...]
num_workers=1,
entrants_per_species=7,
):
bots = []
for species, lowest_generation, highest_generation in species_list:
num_entrants = entrants_per_species
generations = [int(round(x)) for x in numpy.linspace(lowest_generation, highest_generation, num_entrants)]
generations = list(set(generations))
for i in generations:
sp = get_species(species)
Agent = sp.AgentClass
agent_settings = sp.agent_settings(environment_name, i, play_setting="evaluation")
print(f"Adding bot {species}-{i} to tourney")
bots.append(
Bot(
f"{species}-{i}",
Agent,
agent_settings,
)
)
species_str = []
for species, lg, hg in species_list:
species_str.append(f"{species}-{lg}-{hg}")
species_str.sort()
species_str = "__".join(species_str)
tournament_key = f"{round(time.time())}-{species_str}"
results_path = build_tournament_results_path(tournament_key)
env_class = get_env_module(environment_name)
tournament = Tournament.setup(
environment=env_class.Environment,
bots=bots,
)
for i in range(300):
tournament.ladder(num_rounds=1, num_workers=num_workers)
tournament.display_results()
print(f"\nTournament id: {tournament_key}")
tournament.save_results(results_path)
def run_faceoff(
environment_name,
species,
generation,
num_rounds,
num_workers=1,
):
env_class = get_env_module(environment_name)
# The bot your testing and the current best bot
bots = []
for i in range(generation - 1, generation + 1):
sp = get_species(species)
Agent = sp.AgentClass
agent_settings = sp.agent_settings(environment_name, i, play_setting="evaluation")
bots.append(
Bot(
f"{species}-{i}",
Agent,
agent_settings,
)
)
# Run the faceoff
tournament = Tournament.setup(
environment=env_class.Environment,
bots=bots,
)
for i in range(num_rounds):
tournament.ladder(num_rounds=1, num_workers=num_workers) # 2 x 3 games each round
tournament.display_results()
# Return contender matchup
contender_entrant = tournament.entrants[bots[-1].name]
contender_matchup_info = contender_entrant.matchup_histories[bots[0].name]
return contender_matchup_info
if __name__ == "__main__":
# run_faceoff(ENVIRONMENT, BOT_SPECIES, BOT_GENERATION)
species_list_str = sys.argv[2]
species_list = species_list_str.split(",")
species_list = [x.split("-") for x in species_list]
species_list = [(x[0], int(x[1].split("/")[0]), int(x[1].split("/")[1])) for x in species_list]
run_generation_ladder(
environment_name=sys.argv[1],
species_list=species_list,
num_workers=settings.ASSESSMENT_THREADS,
)