five-on-it / packages/ai/src/police-precrime
packages/ai/src/police-precrime
PreCrime™ (GAME_DESIGN §12, four stars and up): where the police predict a driving player goes, so the units, the roadblocks and the red lights wait for them ahead. The prediction walks the road graph from the player's car the way it goes (its velocity, or where it faces when slow), node after node, taking at every junction the straightest way on (the stretch that turns least from the way in; a tie goes to the lower road id, then the lower node id), up to a reach: a deterministic best guess, often right on an avenue and wrong where a player feints a turn, which is the point. Along it, the chokepoints a roadblock prefers: a bridge (a road over a gap or water, its surface well above the ground under it) or a tunnel (a road under a roof of the level), then a long stretch with no junction, then any road (chokepointAhead). Pure: functions of the level, the graph and the pose.