Gym¶
One car on a session’s map, driven over its own connection. Session.connect() is the usual way to get one.
Ticks¶
The race advances in ticks of 10 ms. Gym.reset() plays the countdown and answers at race tick -1, the state
before the first race tick. A step of n ticks simulates the window from Gym.next_tick to
next_tick + n - 1 and answers the state at its end. Inputs given by keyword are written at the window’s first tick
and hold until changed, as in the game; explicit Action records go at ticks of your choosing inside the window.
- class Gym(
- host: str,
- port: int,
- session_id: int,
- telemetry: TelemetryGroup,
- lidar: Lidar | None = None,
- *,
- timeout: float | None = 60.0,
A world on a session’s map, driven over its own connection.
Session.connectis the usual way to get one. Every request is one round trip. A request that fails on the connection, or whose answer the client cannot read, closes the gym and raisesTransportErrororProtocolError, because whether it ran is then unknown: open a new gym, reset, and step the exported record if the race is to go on.- Parameters:
host – The address of the session’s gym socket.
port – Its port.
session_id – The session to open the gym on.
telemetry – The groups every sample carries, combined with
|.lidar – The rays to cast on every sample.
TelemetryGroup.LIDARis its scan, and is in the telemetry exactly when a lidar is given.timeout – Seconds to wait on the server before giving up, for connecting and for every read and write;
Nonewaits forever.
- id: int¶
The gym’s id on the server, as
Session.gymslists it.
- property telemetry: TelemetryGroup¶
The groups every sample carries, combined with
|.
- property race_tick: int¶
The tick of the last computed state, which is -1 before the first reset and right after one.
- property next_tick: int¶
The first tick the next step simulates, where its explicit actions may start.
- property finished: bool¶
Whether the race is finished. A finished gym answers its final state and ignores actions until a reset or a restore.
- reset(seed: int = 0) Telemetry¶
Starts a new race and discards the gym’s snapshots.
The countdown is played, so the answer is at race tick
-1, the state before the first race tick, and the next step’s window starts at tick0.- Parameters:
seed – The race’s random seed; the same seed and inputs give the same race.
- Returns:
The state at race tick
-1.
- step(
- ticks: int,
- actions: Sequence[Action] = (),
- *,
- steer: int | None = None,
- accelerate: bool | None = None,
- brake: bool | None = None,
- respawn: bool = False,
- standing_respawn: bool = False,
- restore: Snapshot | int | None = None,
Advances the race by
ticksticks and answers the state at the end.The window simulated is
next_tickthroughnext_tick + ticks - 1(after the restore, if one is named). Inputs given by keyword are written at the window’s first tick and hold afterwards, as in the game; an input not given keeps its value. Explicitactionscarry their own ticks, which must lie inside the window.A recorded race plays as it is: in the first step after a
reset(), the record’s seed record starts the race over with that seed, and its inputs follow at their ticks. The same record gives the same race on any gym of the map.- Parameters:
ticks – How many ticks to simulate, 1 to 60000. A tick is 10 ms.
actions – Inputs at chosen ticks inside the window, or a whole record.
steer – Steering from -127 (full left) to 127 (full right).
accelerate – Whether the accelerator is held.
brake – Whether the brake is held.
respawn – Respawn at the last checkpoint at the window’s first tick.
standing_respawn – Respawn standing still at the window’s first tick.
restore – A snapshot to put the gym back at before the window, in the same round trip.
- Returns:
The state at the window’s end. A race that finishes inside the window stops there.
- Raises:
ValueError –
ticksorsteeris out of range.BadActionError – An explicit action is outside the window, or a seed record comes once the race has started.
SnapshotUnknownError –
restorenames a snapshot this gym does not hold.
- snapshot() Snapshot¶
Saves the gym’s state on the server.
- Returns:
- Raises:
SnapshotLimitError – The gym already holds
GymInfo.max_snapshots_per_gymsnapshots.
- restore(snapshot: Snapshot | int) Telemetry¶
Puts the gym back at a snapshot.
- Parameters:
snapshot – The snapshot, or its id.
- Returns:
The state at the snapshot’s tick.
- Raises:
SnapshotUnknownError – The snapshot is not one this gym holds.
- discard(*snapshots: Snapshot | int) None¶
Frees snapshots on the server.
- Parameters:
*snapshots – The snapshots, or their ids. All or none are freed.
- Raises:
SnapshotUnknownError – One of them is not a snapshot this gym holds.
- raycast(rays: Sequence[Ray]) LidarScan¶
Casts rays at the car’s current pose, each from its origin along its direction up to its range, in its frame.
- Parameters:
rays – The rays to cast.
- Returns:
One entry per ray, in the order given, like a sampled lidar scan.
- checkpoints() tuple[Checkpoint, ...]¶
Where the race stands against the map’s waypoints: one entry per
MapInfo.waypoints, in that order.A waypoint is taken once the car has passed it in the current lap, with the race time of that passage. On a lap race the entries clear as a lap ends, as the game’s own checkpoint state does.
- Returns:
The checkpoints, finish included.
- export() ExportedRace¶
The race so far: the finish time and every input since the reset, the seed first.
- Returns:
What TICK replays;
InputText.writesaves the actions as input text.
Values¶
- class GymInfo¶
The server as it introduced itself when the gym opened.
- class MapInfo¶
The session’s map as the server knows it.
- vehicle: VehicleType¶
The car the race starts in.
- waypoints: tuple[Waypoint, ...]¶
The checkpoints and the finish, each with the trigger the race tests the car against. The start has no trigger:
start_positionandstart_rotationstand for it.
- class Waypoint¶
A waypoint of the map, with its trigger as a triangle mesh in world space: the car passes the waypoint when its collision shape meets one of the triangles.
- id: int¶
The id
Gym.checkpoints()names it by.
- kind: WaypointKind¶
What passing it counts as.
- vertices: FloatArray¶
The mesh’s vertices, in metres. Shape
(N, 3).
- class Checkpoint¶
One waypoint of the map in
Gym.checkpoints(): whether the race has passed it in the current lap, and when.- waypoint_id: int¶
The
Waypoint.id.
- class Snapshot¶
A server-held snapshot of the gym, as
Gym.snapshotreturns it.
- class ExportedRace¶
A gym’s record since its reset, as
Gym.exportreturns it.