Paused
How It Works
Every AI technique from the course is a visible mechanic. The key in brackets toggles its demo during the game.
1. Kinematic vs steering movement (K)
Kinematic: velocity is set directly, at full speed towards the target, and the unit faces its new direction instantly. Exact, but robotic. Steering: behaviors return forces; the unit accelerates (a = F / m, v += a dt, p += v dt), so it speeds up, curves and slows down naturally. Press K to switch every unit live; overlay 3 shows the forces. Files: movement/kinematic.js, movement/steering.js, movement/agent.js.
2. Steering behaviors (overlay 3, AI Lab)
Seek, flee, arrive (slows inside a radius), pursue and evade (predict where the target will be: T = distance / maxSpeed), wander (a jittering point on a circle ahead), obstacle avoidance (feeler rays), separation (inverse-square push), path following and formation slots. They are blended with weights AND priority: avoidance and separation get the force budget first. Overlay 3 draws each force in its own colour.
3. A* pathfinding (overlay 1)
Click to move the Commander. A* expands the tile with the lowest f = g + h (g: cost so far, h: octile distance to the goal) on an 8-direction grid with tile costs (forest costs 3) and no corner-cutting. The path is then smoothed with line-of-sight checks. Overlay 1: orange = raw A* tiles, cyan = the smoothed waypoints units follow.
4. Hierarchical pathfinding, HPA* (overlay 2, AI Lab)
The map is cut into 24 clusters of 16 x 16. Entrances on cluster borders and the paths between them are precomputed, so a long trip is first planned on a small abstract graph and then refined one segment at a time, only when needed (lazy refinement). Squads share routes through a cache. Paths are a few percent longer than A*'s because they must pass through entrance tiles; the AI Lab benchmark measures this.
5. Time-aware planning at the bridges (overlay 5)
The river has 3 bridges. A unit crossing it estimates WHEN it will reach each bridge (ETA = path length / speed), checks the reservation table for room in that time window, and picks the bridge with the smallest travel time + expected wait. It then reserves its slot and waits at the entrance if needed (yellow ring). Units that make no progress for 1.5 s replan only their next 2 waypoints (magenta ring, overlay 1). This is a simplified, chokepoint-only version of space-time planning such as SIPP.
6. Many NPCs: performance (overlay 7, T)
A spatial hash puts units into 24 px buckets so "who is near me?" only checks nearby buckets (overlay 7; the stats panel compares checks with brute force). Path requests wait in a queue and only a few are answered per step (time slicing), with a cache for repeated queries. Press T to add 300 marching enemies.
7. Decision making with finite state machines (overlay 4)
Enemies: MARCH, DECIDE, ATTACK, REPOSITION, RETREAT, REGROUP, SIEGE. Allies: FOLLOW, ENGAGE, GUARD (G). Every state has enter / update / exit and the transitions live in one explicit table. Overlay 4 shows each unit's state. The enemy's goal chain: attack the base, fight defenders in the way, retreat when HP drops below 30%.
8. Uncertainty (overlay 4)
When an enemy sees a defender it waits its reaction time, then rolls weighted dice with the seeded random generator: attack 70%, flank 20%, retreat 10% (Normal). The same seed always gives the same game, so demos are reproducible.
9. The complexity fallacy (P)
P switches enemies to predictable rules: attack if the Commander's HP is below 30%, retreat if their own HP is below 50%, otherwise always flank to the same side. After seeing each rule once a player can exploit them: stay above 30% HP and they never commit, hurt them to half and they always leave, and every flank arrives on the same, known side. Adding more rules would not help: the behaviour would still be a fixed table from situation to action, just a longer one to learn, with new gaps where rules interact. More complexity is not more unpredictability; a little well-placed randomness gives varied behaviour with less logic.
10. Difficulty: smarter, not stronger
Easy / Normal / Hard change only reaction time (0.8 / 0.5 / 0.25 s), squad coordination (Normal: squads share targets; Hard: also pincer flanking), how often enemies flank, and how far they see. HP and damage are identical on every difficulty.
Controls
Left click: move the Commander. F: formation (Line / V / Box). G: guard the base / rejoin. K: kinematic / steering. P: predictable / uncertain AI. 1-7: overlays. T: stress test. H: help. Esc: pause.