Giter Site home page Giter Site logo

Comments (5)

pseudo-rnd-thoughts avatar pseudo-rnd-thoughts commented on July 22, 2024 7

With v0.26 you can use this code

from nes_py.wrappers import JoypadSpace
import gym_super_mario_bros
from gym_super_mario_bros.actions import SIMPLE_MOVEMENT
import gym

env = gym.make('SuperMarioBros-v0', apply_api_compatibility=True, render_mode="human")
env = JoypadSpace(env, SIMPLE_MOVEMENT)

done = True
env.reset()
for step in range(5000):
    action = env.action_space.sample()
    obs, reward, terminated, truncated, info = env.step(action)
    done = terminated or truncated

    if done:
       state = env.reset()

env.close()

You can read about the migration guide for the new API https://gymnasium.farama.org/content/migration-guide/

from gym-super-mario-bros.

JRod-Seed avatar JRod-Seed commented on July 22, 2024

It would appear that the issue stems from a mismatch in the expected return from env.step. gym/wrappers/time_limit.py returns 5 parameters (observation, reward, terminated, truncated, info) but the invocation is only expecting 4 (observation, reward, terminated, info)

Likely related to: Kautenja/nes-py#85

from gym-super-mario-bros.

Robwc000 avatar Robwc000 commented on July 22, 2024

I'm having the same issue what is the fix?

from gym-super-mario-bros.

zxdclyz avatar zxdclyz commented on July 22, 2024

Try to use gym==0.25.1, it works for me

from gym-super-mario-bros.

PowderFan87 avatar PowderFan87 commented on July 22, 2024

I've debugged the step functions and it seems that nes-py returns 4 or 5 length tuple.
They have a code snippet that checks for if(Len(result)==4) and for 5.
That seems to be the "way to go" it just is not implemented in the gym/wrappers/time_limit.py

I adapted the snipped and set truncated to False as a default:

def step(self, action):
    """Steps through the environment and if the number of steps elapsed exceeds ``max_episode_steps`` then truncate.

    Args:
        action: The environment step action

    Returns:
        The environment step ``(observation, reward, terminated, truncated, info)`` with `truncated=True`
        if the number of steps elapsed >= max episode steps

    """

    truncated = False
    result = self.env.step(action)

    if (len(result) == 4):
        observation, reward, terminated, info = self.env.step(action)
    elif (len(result) == 5):
        observation, reward, terminated, truncated, info = self.env.step(action)
    else:
        raise Exception('Tupel length of step return was neither 4 nore 5. Stop run.')

    self._elapsed_steps += 1

    if self._elapsed_steps >= self._max_episode_steps:
        truncated = True

    return observation, reward, terminated, truncated, info

so instead of just reading 5 every time I do the same check and this works fine.
But I realise changing the lib is bad mojo so maybe this could be a fix ;) with a proper Exception added...

from gym-super-mario-bros.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.