← Writing

HUNTED: my spin on Pac-Man

Pac-Man flipped around: an AI agent plays Pac, and you hunt it with the four ghosts.

HIVEMIND take-home~5 min readTypeScriptBunViteCanvas 2DJevOpenAI Realtime

My favourite game growing up was Pac-Man: whether it was at an arcade or playing at home on my PS4, the simplicity and addicting nature of the game had me hooked. HUNTED is my spin on Pac-Man.

The HUNTED title screen

What I built

HUNTED is Pac-Man flipped around: Jev (the agent) plays as Pac-Man, and you hunt it with the four ghosts. To win a round, catch Pac 3 times before the 2-minute clock runs out. Pac wins the round if it survives or eats every pellet. A match is best of 3.

What’s different from the original

Here’s what changes compared to the arcade version:

  • You are the ghosts: you steer one ghost and can swap to any of the four at any time. The other three run on classic AI styles: chase, ambush, flank and keep away.
  • Ghosts have powers. Shoot fires a bolt that stuns Pac for 1.2 s, and Phase lets a ghost move through walls for 1.5 s. Both show a short wind-up first, so Pac can react. Ghosts gotta have something cool going for them too!
  • Before each round, Pac picks 2 of 4 power-ups: Speed Burst, Shield, Wall Sense and Decoy. GPT-6-Luna makes the pick, using a breakdown of everything that happened in the previous round to counter how you play.
  • The maze has a secret tunnel that only Pac knows. It opens for you once you see Pac come out of it, or phase into it.
  • You can talk to Pac. Hold V and tell it where you’re coming from: Pac checks whether you’re bluffing, and sometimes believes you. Getting angry at Pac? Hold V and tell it exactly how you feel. Reasoning and voice are powered by GPT Realtime models.
  • Pac keeps a model of your habits between sessions and uses it to counter you next time.
Before each round, Pac reads your habits and picks its loadout
Before each round, Pac reads your habits and picks its loadout

How the agent works

Pac’s brain has three layers, split by how fast each decision has to be:

  • A local reflex handles split-second dodges.
  • Jev picks the route at every junction.
  • OpenAI handles the slower talking and planning.

Why Jev

Pac makes a new choice at every junction, often several times a second. Each answer has to arrive before Pac reaches that junction, which leaves 120 to 600 ms. I needed a model that is fast, picks one option from a fixed list, and gives a probability for every option.

Jev does exactly that. It returns typed answers with calibrated probabilities instead of text, so code can act on them directly. An LLM was too slow for this: my OpenAI calls took about 2 s each.

What happens at a junction

Every junction goes through the same steps:

  1. The moment Pac leaves a junction, it starts working on the next one. That gives Jev the whole travel time to answer.
  2. Code works out the facts for each route: how close the nearest ghost gets, how many ways out are left after, pellets, power pellets, shot lanes, phase risk, and where it predicts you’re going.
  3. A single Jev request asks three questions: a Choice (which route?) and two yes/no Nouls (use Speed Burst now? drop a Decoy now?). They run in parallel, so it’s still one round trip.
  4. If Jev is confident, or Pac is fleeing, Pac takes the top route. Otherwise it samples from the probabilities, so it’s harder to predict.

Memory and talk

Pac also keeps track of how you play, and listens to what you say:

  • Pac remembers your habits between sessions: which way you turn at each junction, which ghost you play most, where you shoot and phase. Your turn habits feed the “you expect the hunter to come this way” fact that Jev sees.
  • After a lopsided round, the game nudges how random Pac is and how fast the helper ghosts are, within set bounds.
  • Pac can call your bluff. Holding V streams your voice to OpenAI’s Realtime API. Code picks out claims like “coming from the left” or “about to shoot”, and a Jev yes/no question decides within 300 ms whether it’s a bluff, using your bluff history. If Pac believes you, it avoids that side for the next 4 s.

How it performed

Over 2,216 logged Jev decisions, the median answer took 124 ms and the 95th percentile took 192 ms. In a live game, Jev made about 90% of the decisions and the fallback made the rest.

Deliberate design choices

Everything is built to feel like one real arcade board, while showing what the AI is thinking.

  • The game draws at a small fixed size (576 × 312 pixels) and scales up by whole numbers, with black around it. It feels like looking into an arcade cabinet!
  • The colours are the originals: black background, blue walls, yellow Pac, red, pink, cyan and orange ghosts, and dark-blue frightened ghosts that flash white. Anyone who’s played Pac-Man recognises it right away.
  • The helper ghosts are deliberately simple. Your ghost is faster than they are but slower than Pac, so you win by cutting Pac off with the team, not by chasing it.
  • A catch gets a 2 pixel screen shake and a split-second freeze, plus small particle bursts. It’s enough to feel good without getting noisy.
A round in progress: Pac’s brain on the left, the maze in the middle, voice and chat on the right
A round in progress: Pac’s brain on the left, the maze in the middle, voice and chat on the right

Watching Pac think

The brain panel sits on the left, and it’s where you watch the agent think. It shows Pac’s mood (forage, flee, hunt or bait), every route it’s weighing with a probability bar, and any route it ruled out (marked with a skull). It also shows whether Jev or the fallback made the call and how long it took.

The brain panel mid-flee: one route vetoed, Jev 100% sure, answered in 256 ms
The brain panel mid-flee: one route vetoed, Jev 100% sure, answered in 256 ms
Vibhor Sharma, October 2026