-
Notifications
You must be signed in to change notification settings - Fork 1
/
run_log.py
111 lines (100 loc) · 2.37 KB
/
run_log.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
107
108
109
110
111
from game.game import Game
from evo.evo import EvoAlg
from agents.rulebased import RuleBasedAgent0, RuleBasedAgent1, RuleBasedAgent2, RuleBasedAgent3, RandomAgent
import random
import time
import sys
gen_param_specs = {
'initial_rock_density' : {
'dtype' : float,
'min' : 0.1,
'max' : 0.4
},
'initial_tree_density' : {
'dtype' : float,
'min' : 0.1,
'max' : 0.4
},
'rock_refinement_runs' : {
'dtype' : int,
'min' : 1,
'max' : 3
},
'tree_refinement_runs' : {
'dtype' : int,
'min' : 1,
'max' : 3
},
'rock_neighbour_depth' : {
'dtype' : int,
'min' : 1,
'max' : 2
},
'tree_neighbour_depth' : {
'dtype' : int,
'min' : 1,
'max' : 2
},
'rock_neighbour_number' : {
'dtype' : int,
'min' : 4,
'max' : 8
},
'tree_neighbour_number' : {
'dtype' : int,
'min' : 4,
'max' : 8
},
'base_clear_depth' : {
'dtype' : int,
'min' : 1,
'max' : 1
},
'enemies_crush_trees' : {
'dtype' : bool
},
'random_seed' : {
'dtype' : int,
'min' : 1,
'max' : 9999
},
'flee_distance' : {
'dtype' : int,
'min' : 0,
'max' : 10
}
}
ea = EvoAlg(gen_param_specs)
env = Game(evo_system=ea)
state = env.reset()
agent_classes = {
'R01' : RuleBasedAgent0,
'R02' : RuleBasedAgent1,
'R03' : RuleBasedAgent2,
'R04' : RuleBasedAgent3,
'RR' : RandomAgent
}
generations = 30
run_limit = generations * ea.population_size
if len(sys.argv) == 4 and sys.argv[1] == '--run':
agent_class = agent_classes[sys.argv[2]]
agent = agent_class(env)
i = 0
reward_count = 0
reward_history = []
while True:
state, reward, done, _ = env.step(agent.act(state))
reward_count += reward
if done:
reward_history.append(reward_count)
reward_count = 0
env.reset()
i += 1
agent = agent_class(env)
if i > run_limit:
f = open('{}_reward.txt'.format(sys.argv[3]), 'a')
for value in reward_history:
f.write('{}\n'.format(value))
f.close()
env.worldgen.save_log(sys.argv[3])
quit()