progress.module
README.md
progress
Laps, ordered checkpoints and race positions as pure functions over plain tables (no engine calls, unit tested). Racer runs every kart's lap logic through it, RaceDirector ranks and publishes standings with it, and RaceHud formats times and places with it.
Rules: only the next gate in order counts, and only when crossed forwards inside its width. A skipped gate means every later gate and the finish line are ignored until the skipped one is driven through, so cutting the infield never counts. The first crossing of the start/finish line (gate 1) starts lap 1; each later crossing after every other gate completes a lap, and completing the last lap finishes.
Functions
new(): a fresh state{ lap, nextGate, passed, finished, missed, wrongWay }.step(state, gates, laps, a, b, margin?): advances the state by a move fromatob; returns"start","checkpoint","lap","finish"or nil.crosses(gate, a, b, margin?): whether the segment crosses the gate forwards inside its width, and whether it crossed backwards.score(state, gates, length, sAlong): comparable progress: gates passed plus the fraction of the way to the next gate.rank(rows): race order, best first (finishers by finish time, then by score, then grid slot); addsplaceto each row.encodeStandings(rows)/decodeStandings(s): standings to and from the compact string RaceDirector syncs in one field.ordinal(n): "1st", "2nd", "3rd", "11th", "21st" and so on.clock(t): "m:ss.mmm" for a time in seconds.