forked from rubenrtorrado/GVGAI_GYM
-
Notifications
You must be signed in to change notification settings - Fork 7
/
validate_script.py
38 lines (33 loc) · 1.27 KB
/
validate_script.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
#!/usr/bin/env python
import gym
import gym_gvgai
import Agent as Agent
games = ['gvgai-testgame1', 'gvgai-testgame2', 'gvgai-testgame3']
validateLevels = ['lvl1-v0', 'lvl2-v0', 'lvl3-v0']
totalTimes = 20
# variables for recording the results
results = {}
for game in games:
levelRecord = {}
for level in validateLevels:
timeRecord = {}
for t in range(totalTimes):
env = gym_gvgai.make(game + '-' + level)
agent = Agent.Agent()
print('Starting ' + env.env.game + " with Level " + str(env.env.lvl))
stateObs = env.reset()
actions = env.unwrapped.get_action_meanings()
totalScore = 0
for tick in range(2000):
action_id = agent.act(stateObs, actions)
stateObs, diffScore, done, debug = env.step(action_id)
totalScore += diffScore
print("Action " + str(action_id) + " tick " + str(tick+1) + " reward " + str(diffScore) + " win " + debug["winner"])
if done:
break
timeRecord[t] = [tick, totalScore, debug["winner"]]
levelRecord[level] = timeRecord
results[game] = levelRecord
filename = agent.name + "_result.txt"
with open(filename,'w') as f:
f.write(str(results))