-
Notifications
You must be signed in to change notification settings - Fork 0
/
gym-play.py
68 lines (53 loc) · 1.86 KB
/
gym-play.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
import argparse
import random
import numpy as np
#import pdb
import gym
from gym import logger
import sys
from reflex_agent.reflex_agent import ReflexAgent
from neat_agent.neat_agent import NEATAgent
from random_agent.random_agent import RandomAgent
class Agent(object):
"""The world's simplest agent!"""
def __init__(self, action_space):
self.action_space = action_space
# You should modify this function
def act(self, observation, reward, done):
return self.action_space.sample()
## YOU MAY NOT MODIFY ANYTHING BELOW THIS LINE OR USE
## ANOTHER MAIN PROGRAM
if __name__ == '__main__':
parser = argparse.ArgumentParser(description=None)
parser.add_argument('--env_id', nargs='?', default='Berzerk-v0', help='Select the environment to run')
args = parser.parse_args()
# You can set the level to logger.DEBUG or logger.WARN if you
# want to change the amount of output.
logger.set_level(logger.INFO)
env = gym.make(args.env_id)
# You provide the directory to write to (can be an existing
# directory, including one with existing data -- all monitor files
# will be namespaced). You can also dump to a tempdir if you'd
# like: tempfile.mkdtemp().
outdir = 'random-agent-results'
env.seed(0)
agent = NEATAgent(env.action_space)
episode_count = 100
reward = 0
done = False
score = 0
special_data = {}
special_data['ale.lives'] = 3
ob = env.reset()
while not done:
action = agent.act(ob, reward, done)
ob, reward, done, x = env.step(action)
score += reward
env.render()
agent.act(ob, reward, done)
agent_num_levels = agent.num_levels
agent_total_steps = agent.total_steps
agent_elapsed_time = agent.elapsed_time
# Close the env and write monitor result info to disk
print ("Your score: %d" % score)
env.close()