Games & simulation
2D autonomous car simulation in the browser, driven by TypeSafe's Jev decision model
import { TypeSafeClient, APIError } from "@typesafe-ai/sdk";The link points at the commit we read, so the line number still holds.
These question sets are lifted from this project's source exactly as written.
from public/js/brain.js:5
lane_actionchoiceYou are the driving policy of `ego`, a car on a one-way road with 3 lanes (see `road`).
keep_lane — Stay in the current lane; it is clear enough, or no adjacent lane is safer.change_left — Move one lane to the left: the left lane exists, is clear ahead and no car is closing from behind, and the current lane is blocked or slower.change_right — Move one lane to the right: the right lane exists, is clear ahead and no car is closing from behind, and the current lane is blocked or slower.speed_actionchoiceDecide how `ego` should adjust its speed in the next second. Only `lanes.current` matters for speed; objects in
stop — Brake to a full stop: a pedestrian is in or entering the path, or a stopped obstacle/vehicle is within `ego.stopping_distance_m` plus a 5 m margin (leave room to steer around it later).slow_down — Reduce speed: the lead in the current lane is within about twice the stopping distance, or `time_to_collision_s` is under ~4 s.hold — Keep the current speed: there is a lead in the current lane but the gap is comfortable (`time_to_collision_s` between ~4 and ~8 s, or matching its speed).speed_up — Accelerate: the current lane is clear well beyond twice the stopping distance (or `time_to_collision_s` is null or above ~8 s) and ego is below the speed limit.hazardscoreRate the overall collision hazard for `ego` right now, given everything in the state.
0 — No hazard: the road ahead is clear for a long distance.1 — Low: obstacles or vehicles exist but they are far away or in other lanes.2 — Moderate: something in the current lane is within about twice the stopping distance, or a pedestrian is close to the road.3 — Severe: a collision is likely within a few seconds unless ego brakes or swerves now.pedestrian_yieldtrue/falseA pedestrian is on the road, or is walking toward the road and will reach ego's lane, within roughly `ego.stopping_distance_m`
import { experimental_evaluate as evaluate } from 'ai';
const { answers } = await evaluate({
model: 'typesafe-ai/jev',
state,
questions: {
lane_action: { type: 'choice', instructions: 'You are the driving policy of `ego`, a car on a one-way road with 3 lanes (see `road`).',
criteria: { keep_lane: 'Stay in the current lane; it is clear enough, or no adjacent lane is safer.', change_left: 'Move one lane to the left: the left lane exists, is clear ahead and no car is closing from behind, and the current lane is blocked or slower.', change_right: 'Move one lane to the right: the right lane exists, is clear ahead and no car is closing from behind, and the current lane is blocked or slower.' } },
speed_action: { type: 'choice', instructions: 'Decide how `ego` should adjust its speed in the next second. Only `lanes.current` matters for speed; objects in',
criteria: { stop: 'Brake to a full stop: a pedestrian is in or entering the path, or a stopped obstacle/vehicle is within `ego.stopping_distance_m` plus a 5 m margin (leave room to steer around it later).', slow_down: 'Reduce speed: the lead in the current lane is within about twice the stopping distance, or `time_to_collision_s` is under ~4 s.', hold: 'Keep the current speed: there is a lead in the current lane but the gap is comfortable (`time_to_collision_s` between ~4 and ~8 s, or matching its speed).', speed_up: 'Accelerate: the current lane is clear well beyond twice the stopping distance (or `time_to_collision_s` is null or above ~8 s) and ego is below the speed limit.' } },
hazard: { type: 'score', instructions: 'Rate the overall collision hazard for `ego` right now, given everything in the state.',
criteria: ['No hazard: the road ahead is clear for a long distance.', 'Low: obstacles or vehicles exist but they are far away or in other lanes.', 'Moderate: something in the current lane is within about twice the stopping distance, or a pedestrian is close to the road.', 'Severe: a collision is likely within a few seconds unless ego brakes or swerves now.'] },
pedestrian_yield: { type: 'boolean', instructions: 'A pedestrian is on the road, or is walking toward the road and will reach ego\'s lane, within roughly `ego.stopping_distance_m`' },
},
});