Training runs a standard on policy PPO loop, but the wrapper environment does most of the interesting work. Every step inside the agent's rollout, Pitwall:
- Receives a continuous action
(steer, throttle, brake)from the policy. - Steps the underlying CarRacing physics. Box2D integrates the dynamics at 50 Hz.
- Reads the resulting car state: speed from
car.hull.linearVelocity, lateral acceleration from|ω| · v(normalised into the [0, 10] cornering range the tire model was trained on). - Queries
predict_wear_rate(speed, cornering_load, lap, current_wear, compound)and scales the output into a per env step wear delta. - Updates internal state: tire wear, lap counter (via CarRacing's
tile_visited_count), stagnation counter, pit zone proximity. - Computes the shaped reward (see below) and returns the new observation, reward, and termination signals to PPO.
Eight env workers run in parallel via SubprocVecEnv. PPO collects 512 steps
per worker per rollout (4096 total samples), then runs 10 epochs of mini batch
gradient updates with the standard clipped surrogate objective. A separate
EvalCallback runs deterministic policy rollouts every 10 000 total steps
on a held out single env to track unbiased progress, and saves the best
best_model.zip whenever a new high water mark is hit.