Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 12 additions & 9 deletions gymnasium/envs/box2d/car_racing.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,20 +87,21 @@ def _contact(self, contact, begin):
tile.color[:] = self.env.road_color
if not obj or "tiles" not in obj.__dict__:
return

# Lap is considered completed if enough % of the track was covered
if (
tile.idx == 0
and self.env.tile_visited_count / len(self.env.track)
> self.lap_complete_percent
):
self.env.new_lap = True

if begin:
obj.tiles.add(tile)
if not tile.road_visited:
tile.road_visited = True
self.env.reward += 1000.0 / len(self.env.track)
self.env.tile_visited_count += 1

# Lap is considered completed if enough % of the track was covered
if (
tile.idx == 0
and self.env.tile_visited_count / len(self.env.track)
> self.lap_complete_percent
):
self.env.new_lap = True
else:
obj.tiles.remove(tile)

Expand Down Expand Up @@ -146,7 +147,7 @@ class CarRacing(gym.Env, EzPickle):
The car starts at rest in the center of the road.

## Episode Termination
The episode finishes when all the tiles are visited. The car can also go outside the playfield -
The episode finishes when the car reaches the end of the circuit or the time limit is reached. The car can also go outside the playfield -
that is, far off the track, in which case it will receive -100 reward and die.

## Arguments
Expand Down Expand Up @@ -190,6 +191,8 @@ class CarRacing(gym.Env, EzPickle):
```

## Version History
- v4: The episode will now terminate upon completing the lap, regardless of the number of tiles visited
- v3: Improved RNG handling with seed=-1; fixed bugs in environment checking and Box shape inference; minor fixes, including typos and dependency management.
- v2: Change truncation to termination when finishing the lap (1.0.0)
- v1: Change track completion logic and add domain randomization (0.24.0)
- v0: Original version
Expand Down
Loading