Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug Report] Box2d car racing environment fails to take integer action #1233

Open
1 task done
sizzflair97 opened this issue Oct 25, 2024 · 1 comment
Open
1 task done
Labels
bug Something isn't working

Comments

@sizzflair97
Copy link

sizzflair97 commented Oct 25, 2024

Describe the bug

8161d7d#diff-b2657ab36b5d46d0f112f0c7d20e3026e4d50c8a0e260e5669002d229e5f027cR544

the newly added line 543 of box2d/car_racing.py always fails to run non-continuous action.

Code example

Replacing the type casting may be helpful:

#line 540
def step(self, action: Union[np.ndarray, int]):
    assert self.car is not None
        if action is not None:
            if self.continuous:
                action = action.astype(np.float64)
                self.car.steer(-action[0])
                self.car.gas(action[1])
                self.car.brake(action[2])
            else:
                if not self.action_space.contains(action):
                    raise InvalidAction(
                        f"you passed the invalid action `{action}`. "
                        f"The supported action_space is `{self.action_space}`"
                    )
                self.car.steer(-0.6 * (action == 1) + 0.6 * (action == 2))
                self.car.gas(0.2 * (action == 3))
                self.car.brake(0.8 * (action == 4))

System info

No response

Additional context

No response

Checklist

  • I have checked that there is no similar issue in the repo
@sizzflair97 sizzflair97 added the bug Something isn't working label Oct 25, 2024
@pseudo-rnd-thoughts
Copy link
Member

Could you make a PR fixing this along with a test about it?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants