From 71f11a06429c9f5e3eff4f0a28e491024e48147c Mon Sep 17 00:00:00 2001 From: Antonin RAFFIN Date: Wed, 15 Jun 2022 15:34:42 +0200 Subject: [PATCH] Fix CarRacing termination (#2890) --- gym/envs/box2d/car_racing.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/gym/envs/box2d/car_racing.py b/gym/envs/box2d/car_racing.py index 9e1a38510..1537c5a36 100644 --- a/gym/envs/box2d/car_racing.py +++ b/gym/envs/box2d/car_racing.py @@ -88,7 +88,7 @@ def _contact(self, contact, begin): and self.env.tile_visited_count / len(self.env.track) > self.lap_complete_percent ): - self.env_new_lap = True + self.env.new_lap = True else: obj.tiles.remove(tile) @@ -484,6 +484,7 @@ def step(self, action: Union[np.ndarray, int]): step_reward = 0 done = False + info = {} if action is not None: # First step without action, called from reset() self.reward -= 0.1 # We actually don't want to count fuel spent, we want car to be faster. @@ -493,13 +494,17 @@ def step(self, action: Union[np.ndarray, int]): self.prev_reward = self.reward if self.tile_visited_count == len(self.track) or self.new_lap: done = True + # Termination due to finishing lap + # This should not be treated as a failure + # but like a timeout + info["TimeLimit.truncated"] = True x, y = self.car.hull.position if abs(x) > PLAYFIELD or abs(y) > PLAYFIELD: done = True step_reward = -100 self.renderer.render_step() - return self.state, step_reward, done, {} + return self.state, step_reward, done, info def render(self, mode: str = "human"): if self.render_mode is not None: