diff --git a/gymnasium/envs/box2d/car_racing.py b/gymnasium/envs/box2d/car_racing.py index 64eec81bc..d89022755 100644 --- a/gymnasium/envs/box2d/car_racing.py +++ b/gymnasium/envs/box2d/car_racing.py @@ -556,6 +556,7 @@ def step(self, action: Union[np.ndarray, int]): step_reward = 0 terminated = False truncated = 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. @@ -566,14 +567,16 @@ def step(self, action: Union[np.ndarray, int]): if self.tile_visited_count == len(self.track) or self.new_lap: # Termination due to finishing lap terminated = True + info["finished"] = True x, y = self.car.hull.position if abs(x) > PLAYFIELD or abs(y) > PLAYFIELD: terminated = True + info["finished"] = False step_reward = -100 if self.render_mode == "human": self.render() - return self.state, step_reward, terminated, truncated, {} + return self.state, step_reward, terminated, truncated, info def render(self): if self.render_mode is None: