diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..76b29b6 --- /dev/null +++ b/.gitignore @@ -0,0 +1,6 @@ +*.swp +*~ +*.egg-info +__pycache__/ +build/ +dist/ diff --git a/gym_mygame/__init__.py b/gym_mygame/__init__.py index 5a89d7c..49ec76b 100644 --- a/gym_mygame/__init__.py +++ b/gym_mygame/__init__.py @@ -2,6 +2,6 @@ register( id='MyGame-v0', - entry_point='gym_game.envs:MyGame', + entry_point='gym_mygame.envs:MyGame', max_episode_steps=10000 ) diff --git a/gym_mygame/envs/__init__.py b/gym_mygame/envs/__init__.py index 4347e28..869f00d 100644 --- a/gym_mygame/envs/__init__.py +++ b/gym_mygame/envs/__init__.py @@ -1 +1 @@ -from mygame import MyGame +from gym_mygame.envs.mygame import MyGame diff --git a/gym_mygame/envs/__pycache__/mygame.cpython-36.pyc b/gym_mygame/envs/__pycache__/mygame.cpython-36.pyc index 5dc3fa5..37e9a33 100644 Binary files a/gym_mygame/envs/__pycache__/mygame.cpython-36.pyc and b/gym_mygame/envs/__pycache__/mygame.cpython-36.pyc differ diff --git a/gym_mygame/envs/mygame.py b/gym_mygame/envs/mygame.py index 667ba0f..1172054 100644 --- a/gym_mygame/envs/mygame.py +++ b/gym_mygame/envs/mygame.py @@ -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): diff --git a/setup.py b/setup.py old mode 100644 new mode 100755 index 1326985..27845d5 --- a/setup.py +++ b/setup.py @@ -1,3 +1,4 @@ +#!/usr/bin/env python3 ''' Python distutils setup file for gym-mygame module. diff --git a/test.py b/test.py new file mode 100755 index 0000000..d8de3fc --- /dev/null +++ b/test.py @@ -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()