Skip to content

Commit

Permalink
Works with gymnasium
Browse files Browse the repository at this point in the history
  • Loading branch information
simondlevy committed Sep 10, 2023
1 parent e044954 commit 4a08d19
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 9 deletions.
2 changes: 1 addition & 1 deletion gym_mygame/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from gym.envs.registration import register
from gymnasium.envs.registration import register

register(
id='MyGame-v0',
Expand Down
9 changes: 5 additions & 4 deletions gym_mygame/envs/mygame.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
MIT License
'''

import gym
import gymnasium as gym

import numpy as np

Expand All @@ -26,14 +26,15 @@ def step(self, action):

state = [0]
reward = 0
done = False
terminated = False
truncated = False
info = {}

return state, reward, done, info
return state, reward, terminated, truncated, info

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

return
pass

def reset(self):

Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

setup (name = 'gym_mygame',
version = '0.1',
install_requires = ['gym', 'numpy'],
install_requires = ['gymnasium', 'numpy'],
description = 'Gym environment for my CSCI 316 game',
packages = ['gym_mygame', 'gym_mygame.envs'],
author='Simon D. Levy',
Expand Down
13 changes: 10 additions & 3 deletions test.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,25 @@
MIT License
'''

import gym
import gymnasium as 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:

observation, reward, terminated, truncated, info = env.step(action)

if terminated or truncated:
print("Episode finished after {} timesteps".format(t+1))
break

Expand Down

0 comments on commit 4a08d19

Please sign in to comment.