The 4 Ghosts
1980: four rules, zero neurons. Blinky hunts you, Pinky cuts you off — and you still sweated.
42 seconds · English captions included · 9.3 Mo
The 7 things you'll know how to do
Lesson 5: the AI before AI
Regarde la leçon (42 s) : quatre fantômes, zéro neurone — et une leçon de plus sur ce qu'est vraiment un programme qui décide.
Blinky chases, period
Écris la méthode `cible_blinky(pos)` : elle renvoie exactement `pos` — la poursuite directe, zéro détour. Exemple : cible_blinky([3, 4]) → [3, 4].
Pinky cuts the route
Écris `cible_pinky(pos)` : il vise QUATRE cases devant toi — `[pos[0] + 4, pos[1] + 4]`. Exemple : cible_pinky([0, 0]) → [4, 4].
Inky: two inputs, one decision
Écris `cible_inky(pos, detail)` : sa cible ADDITIONNE ta position et le détail — les deux infos dans la décision. Exemple : cible_inky([0, 0], [2, 3]) → [2, 3].
Clyde chases… then flees
Écris `cible_clyde(pos, distance)` : distance STRICTEMENT supérieure à 8 → il poursuit (renvoie `pos`), sinon il FUIT et renvoie le symbole `:fuite`.
One ghost, one rule
Écris `cible(nom, pos)` : "blinky" poursuit (renvoie `pos`), "pinky" vise quatre cases devant, tout autre nom → `nil`. La règle choisie par un mot.
Lesson 5: OK
Sans aide : `cible(nom, pos, distance = 20)` pour les TROIS — "blinky" → pos · "pinky" → quatre cases devant · "clyde" → distance > 8 ? pos : :fuite · sinon nil.
📄 The cheat sheet
print it, stick it on your monitor, pretend it was your idea📄 Cheat sheet — The 4 Ghosts (the AI before AI)
A ghost is a function. A behavior is a well-written
if.
Why Pac-Man is your best AI teacher
In 1980, zero neurons, zero GPUs — yet the four ghosts each had a personality. They were only rules: position → target → direction. That's exactly what an "agent" does today. Understand a ghost, you understand an LLM: behavior, written by someone.
The lexicon of the four (one sentence each)
| Ghost | His rule | Ruby translation |
|---|---|---|
| 🔴 Blinky | he chases you, period | def cible_blinky(pos); pos; end |
| 🩷 Pinky | he cuts you off — 4 tiles ahead | [pos[0] + 4, pos[1] + 4] |
| 🔵 Inky | two inputs → one decision | [pos[0] + d[0], pos[1] + d[1]] |
| 🟠 Clyde | distance > 8 ? chase : flee | distance > 8 ? pos : :fuite |
The structure that shows up everywhere: case
def cible(nom, pos, distance = 20)
case nom
when "blinky" then pos
when "pinky" then [pos[0] + 4, pos[1] + 4]
when "clyde" then (distance > 8 ? pos : :fuite)
end # other name → nil: no rule, no behavior
end
One word → one rule. It's a dispatch, a state machine, a "router" — the same word everywhere.
The 3 player traps
>vs>=: Clyde flees from 8 on — test the edges (8 and 9) like in the video.- Mutating the input (
pos[0] += 4) instead of computing a new one: your Pac-Man moved, not your ghost. - Forgetting the default case: without
else, an unknown name →nil→ the ghost stops. (An agent without a rule is a dead agent.)
The sentence that unlocks everything
AI is well-written
ifs. Today's difference? Theifs are written by other machines. The reader is still you.
Never say again
"it's magic / it's AI"→ it's a rule someone wrote. Read it."a script isn't AI"→ Blinky is a script. And he scared you for 40 years. 😉
SlopCourse — from slop to clean code.