Skip to content

Commit

Permalink
Works with basic test script
Browse files Browse the repository at this point in the history
  • Loading branch information
simondlevy committed May 12, 2020
1 parent c19acae commit 05cf915
Show file tree
Hide file tree
Showing 7 changed files with 50 additions and 5 deletions.
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
*.swp
*~
*.egg-info
__pycache__/
build/
dist/
2 changes: 1 addition & 1 deletion gym_mygame/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@

register(
id='MyGame-v0',
entry_point='gym_game.envs:MyGame',
entry_point='gym_mygame.envs:MyGame',
max_episode_steps=10000
)
2 changes: 1 addition & 1 deletion gym_mygame/envs/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
from mygame import MyGame
from gym_mygame.envs.mygame import MyGame
Binary file modified gym_mygame/envs/__pycache__/mygame.cpython-36.pyc
Binary file not shown.
17 changes: 14 additions & 3 deletions gym_mygame/envs/mygame.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,28 @@ def __init__(self):

gym.Env.__init__(self)

# Use [-1,+1] for observation space an action space
self.observation_space = gym.spaces.Box(-1, +1, shape=(1,), dtype=np.float32)
self.action_space = gym.spaces.Box(-1, +1, (1,), dtype=np.float32)

self.reset()

def step(self, action):

return
state = [0]
reward = 0
done = False
info = {}

def render(self):
return state, reward, done, info

def render(self, mode='human'):

return

def reset(self):

return
return [0]

def close(self):

Expand Down
1 change: 1 addition & 0 deletions setup.py
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#!/usr/bin/env python3
'''
Python distutils setup file for gym-mygame module.
Expand Down
27 changes: 27 additions & 0 deletions test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#!/usr/bin/env python3
'''
Python distutils setup file for gym-mygame module.
Adapted from http://gym.openai.com/docs/
Copyright (C) 2020 Simon D. Levy
MIT License
'''

import gym

env = gym.make('gym_mygame:MyGame-v0')

for i_episode in range(20):
observation = env.reset()
for t in range(100):
env.render()
print(observation)
action = env.action_space.sample()
observation, reward, done, info = env.step(action)
if done:
print("Episode finished after {} timesteps".format(t+1))
break

env.close()

0 comments on commit 05cf915

Please sign in to comment.