Actions and input files

An input is an Action: a race tick, a kind and a value. The keyword arguments of Gym.step() cover a plain control loop; explicit actions are for inputs at chosen ticks inside a step’s window, and they are what a recorded race is made of.

from tickgym import Action, InputText

# Two inputs at chosen ticks inside a 10-tick step.
t = gym.step(10, [Action.steer(gym.next_tick, -40), Action.brake(gym.next_tick + 5)])

# The whole race so far, saved as TICK input text.
InputText.write("records/best.txt", gym.export().actions)
class Action(tick: int, kind: InputActionKind, value: int = 0)

One input event at a race tick. A value holds until the next event of the same kind, as in the game. Build them with the factories below.

tick: int

The race tick the input takes effect at.

kind: InputActionKind

What the input is.

value: int

The input’s value. A steer runs from -127 to 127, a pressed control is 1 or 0, a seed or flags word is as is.

static steer(tick: int, steer: int) → Action

Steering at tick: -127 (full left) to 127 (full right).

static accelerate(tick: int, on: bool = True) → Action

The accelerator pressed (or released) at tick.

static brake(tick: int, on: bool = True) → Action

The brake pressed (or released) at tick.

static respawn(tick: int) → Action

A respawn at the last checkpoint at tick.

static standing_respawn(tick: int) → Action

A standing respawn at tick: the car is put back at the last checkpoint without speed.

static flags(tick: int, flags: int) → Action

TICK’s input flags word at tick; rarely needed.

static seed(tick: int, seed: int) → Action

The race seed record, as the first record of an exported race carries it.

class InputActionKind(value)
ACCELERATE = 1
BRAKE = 2
STEER = 3
SEED = 4
RESPAWN = 5
FLAGS = 6
STANDING_RESPAWN = 7
GAME_SPEED = 8

Input text

class InputText

TICK’s input text, the format its editor loads and saves, to and from Action values.

One input per line, <time> <action> [<value>]; blank lines and # comments are skipped. A time is milliseconds (1500), a clock (1:02.50) or seconds (1.5), and aligns to 10 ms ticks. The actions are accel, brake, steer, respawn, srespawn, seed, flags and speed:

0 seed 1
0 accel 1
1500 steer -40
2:10.50 brake 1
static parse(text: str) → tuple[Action, ...]

The actions in a text, in line order.

Raises:

InputTextError – A line is not input text.

static format(items: Sequence[Action]) → str

The text of these actions: one line each, milliseconds first.

static read(path: Path | str) → tuple[Action, ...]

The actions in an input text file.

Raises:

InputTextError – A line is not input text.

static write(
path: Path | str,
items: Sequence[Action],
) → None

Writes these actions as an input text file, creating the folders on the way.

exception InputTextError(line_number: int, code: str, message: str)

A line that is not TICK input text.

line_number: int

The line, counted from 1.

code: str

TICK’s error code for the problem.

message: str

What is wrong with the line.