Skip to content

Commit

Permalink
Add an info entry
Browse files Browse the repository at this point in the history
  • Loading branch information
RedTachyon committed Dec 5, 2023
1 parent 60bebb0 commit ad3b1a3
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion gymnasium/envs/box2d/car_racing.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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:
Expand Down

0 comments on commit ad3b1a3

Please sign in to comment.