forked from rubenrtorrado/GVGAI_GYM
-
Notifications
You must be signed in to change notification settings - Fork 0
/
testAgent.py
27 lines (25 loc) · 1.06 KB
/
testAgent.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
#!/usr/bin/env python
import gym
import gym_gvgai
import Agent as Agent
# Predefined names referring to framework
games = ['gvgai-testgame1', 'gvgai-testgame2', 'gvgai-testgame3']
trainingLevels = ['lvl0-v0', 'lvl1-v0']
testLevels = ['lvl2-v0', 'lvl3-v0', 'lvl4-v0']
for game in games:
for level in trainingLevels: #testLevels:
env = gym_gvgai.make(game + '-' + level)
agent = Agent.Agent()
print('Starting ' + env.env.game + " with Level " + str(env.env.lvl))
# reset environment
stateObs = env.reset()
actions = env.unwrapped.get_action_meanings()
for t in range(2000):
# choose action based on trained policy
action_id = agent.act(stateObs, actions)
# do action and get new state and its reward
stateObs, diffScore, done, debug = env.step(action_id)
print("Action " + str(action_id) + " tick " + str(t+1) + " reward " + str(diffScore) + " win " + debug["winner"])
# break loop when terminal state is reached
if done:
break