forked from justinmeister/Mario-Level-1
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrandom_agent.py
48 lines (39 loc) · 1.01 KB
/
random_agent.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
import subprocess
import os
from os import path
import copy
import ast
import pickle
def killFCEUX():
subprocess.call(["killall", "-9", "fceux"])
import gym
class RandomAgent(object):
def __init__(self, action_space):
self.action_space = action_space
def act(self, observation, reward, done):
#return [0,0,0,1,0,0] # always right
#return [0,0,0,0,0,0] # dont move
return [self.action_space.sample()]
def main():
env = gym.make('SuperMarioBros-1-1-v0')
agent = RandomAgent(env.action_space)
for i in range(2):
env.lock.acquire()
observation = env.reset()
env.lock.release()
for t in range(1000):
env.render()
print(observation)
action = agent.act(observation, None, None)
observation, reward, done, info = env.step(action)
print(info)
if done:
print("Episode finished after {} timesteps".format(t+1))
break
env.lock.acquire()
env.close()
env.lock.release()
killFCEUX()
os._exit(0)
if __name__ == '__main__':
main()