cover

The Game AI Cookbook

How does a computer play games against you?
You press start, and suddenly you're racing a computer driver who knows every turn, fighting a computer opponent who nev

You press start, and suddenly you're racing a computer driver who knows every turn, fighting a computer opponent who never blinks, solving puzzles against a computer that seems to read your mind. But here's the thing: the computer isn't actually thinking about beating you. It's following recipes โ€” very clever recipes โ€” that make it look like it's playing.

The simplest recipe is called "++if-then++." If you move left, then the computer moves right. If you jump, then the comp

The simplest recipe is called "if-then." If you move left, then the computer moves right. If you jump, then the computer ducks. The game programmer writes thousands of these rules ahead of time, like a giant cookbook. "If the player is close, run away. If the player is far, chase." The computer just reads the recipe and follows it, lightning-fast.

For smarter opponents, programmers use something called a "++decision tree++." Imagine the computer standing at a crossr

For smarter opponents, programmers use something called a "decision tree." Imagine the computer standing at a crossroads: "Should I attack or defend?" It looks ahead โ€” if I attack, the player might dodge, then I'll be open, then they'll hit me, bad choice. If I defend, I'll block their move, then counter, better choice. The computer walks through this invisible tree of possibilities in milliseconds, picking the path that leads to the best outcome.

Some games make the computer learn from **you**. Every time you win with a sneak attack, the computer notes it. Every ti

Some games make the computer learn from you. Every time you win with a sneak attack, the computer notes it. Every time you fall for a fake-out, it remembers. It builds a little mental map: "This player loves jumping puzzles, hates water levels, always goes left first." Next time, it adjusts. It's not personal โ€” it's pattern-matching. You're turning into data.

Chess computers use a trick called "++minimax++" โ€” they imagine you're trying to maximize your score while they're tryin

Chess computers use a trick called "minimax" โ€” they imagine you're trying to maximize your score while they're trying to minimize it, and they calculate millions of futures where both of you play perfectly. The computer doesn't "want" to win. It just explores every possible next move, then every possible move after that, like unrolling a scroll that shows twenty turns into the future, picking the path where your best play still loses.

Modern game AI uses something wild called a "++neural network++" โ€” a math structure that learns by **playing itself a mi

Modern game AI uses something wild called a "neural network" โ€” a math structure that learns by playing itself a million times. Two copies of the same AI face off: one tries strategies, the other counters. Winners get remembered, losers get erased. After a million rounds, the AI has carved a kind of instinct into its code: "corner positions feel safe, center positions feel strong." It never saw a human play, but it discovered the same tricks you use.

~~The weird part?~~ Programmers sometimes make the computer play **badly** on purpose, so you can win. **"Easy mode"** i

The weird part? Programmers sometimes make the computer play badly on purpose, so you can win. "Easy mode" isn't just a slower opponent โ€” it's an opponent with a blindfold. The computer pretends not to see that perfect move, hesitates before blocking you, aims a little off. It's throwing the match, just enough to keep the game fun. You're not beating the computer; you're beating the handicapped version the programmer decided to show you.

So when you beat that final boss, remember: **you didn't outsmart a brain**. ~~You outsmarted a recipe~~, a tree of if-t

So when you beat that final boss, remember: you didn't outsmart a brain. You outsmarted a recipe, a tree of if-thens, a pattern-matcher, or a neural net that learned by fighting itself. The computer never cared about winning. It just followed its instructions so well that it felt like it cared โ€” and that's the trick that makes every game feel alive.

How was this book?

A Wonderleaf Book

The Game AI Cookbook

โ€” How does a computer play games against you? โ€”

Wonderleaf Editions
โ€” ex libris โ€”
A Wonderleaf Book

The Game AI Cookbook

How does a computer play games against you?

Wonderleaf Editions ยท MMXXVI
Scene 1
You press start, and suddenly you're racing a computer driver who knows every turn, fighting a computer opponent who nev
The Game AI Cookbook2
Scene 1

You press start, and suddenly you're racing a computer driver who knows every turn, fighting a computer opponent who never blinks, solving puzzles against a computer that seems to read your mind. But here's the thing: the computer isn't actually thinking about beating you. It's following recipes โ€” very clever recipes โ€” that make it look like it's playing.

3The Game AI Cookbook
Scene 2
The simplest recipe is called "++if-then++." If you move left, then the computer moves right. If you jump, then the comp
The Game AI Cookbook4
Scene 2

The simplest recipe is called "if-then." If you move left, then the computer moves right. If you jump, then the computer ducks. The game programmer writes thousands of these rules ahead of time, like a giant cookbook. "If the player is close, run away. If the player is far, chase." The computer just reads the recipe and follows it, lightning-fast.

5The Game AI Cookbook
Scene 3
For smarter opponents, programmers use something called a "++decision tree++." Imagine the computer standing at a crossr
The Game AI Cookbook6
Scene 3

For smarter opponents, programmers use something called a "decision tree." Imagine the computer standing at a crossroads: "Should I attack or defend?" It looks ahead โ€” if I attack, the player might dodge, then I'll be open, then they'll hit me, bad choice. If I defend, I'll block their move, then counter, better choice. The computer walks through this invisible tree of possibilities in milliseconds, picking the path that leads to the best outcome.

7The Game AI Cookbook
Scene 4
Some games make the computer learn from **you**. Every time you win with a sneak attack, the computer notes it. Every ti
The Game AI Cookbook8
Scene 4

Some games make the computer learn from you. Every time you win with a sneak attack, the computer notes it. Every time you fall for a fake-out, it remembers. It builds a little mental map: "This player loves jumping puzzles, hates water levels, always goes left first." Next time, it adjusts. It's not personal โ€” it's pattern-matching. You're turning into data.

9The Game AI Cookbook
Scene 5
Chess computers use a trick called "++minimax++" โ€” they imagine you're trying to maximize your score while they're tryin
The Game AI Cookbook10
Scene 5

Chess computers use a trick called "minimax" โ€” they imagine you're trying to maximize your score while they're trying to minimize it, and they calculate millions of futures where both of you play perfectly. The computer doesn't "want" to win. It just explores every possible next move, then every possible move after that, like unrolling a scroll that shows twenty turns into the future, picking the path where your best play still loses.

11The Game AI Cookbook
Scene 6
Modern game AI uses something wild called a "++neural network++" โ€” a math structure that learns by **playing itself a mi
The Game AI Cookbook12
Scene 6

Modern game AI uses something wild called a "neural network" โ€” a math structure that learns by playing itself a million times. Two copies of the same AI face off: one tries strategies, the other counters. Winners get remembered, losers get erased. After a million rounds, the AI has carved a kind of instinct into its code: "corner positions feel safe, center positions feel strong." It never saw a human play, but it discovered the same tricks you use.

13The Game AI Cookbook
Scene 7
~~The weird part?~~ Programmers sometimes make the computer play **badly** on purpose, so you can win. **"Easy mode"** i
The Game AI Cookbook14
Scene 7

The weird part? Programmers sometimes make the computer play badly on purpose, so you can win. "Easy mode" isn't just a slower opponent โ€” it's an opponent with a blindfold. The computer pretends not to see that perfect move, hesitates before blocking you, aims a little off. It's throwing the match, just enough to keep the game fun. You're not beating the computer; you're beating the handicapped version the programmer decided to show you.

15The Game AI Cookbook
Scene 8
So when you beat that final boss, remember: **you didn't outsmart a brain**. ~~You outsmarted a recipe~~, a tree of if-t
The Game AI Cookbook16
Scene 8

So when you beat that final boss, remember: you didn't outsmart a brain. You outsmarted a recipe, a tree of if-thens, a pattern-matcher, or a neural net that learned by fighting itself. The computer never cared about winning. It just followed its instructions so well that it felt like it cared โ€” and that's the trick that makes every game feel alive.

17The Game AI Cookbook

~ finis ~

Tiny picture books for big little questions.

โ€” a small constellation of questions โ€”
โœฆWonderleaf
Editions