Skip to main content
AI Foundations

⏱ About 10 min10 XP

AI in the Games You Play

You have found AI at home. Now let's go somewhere even more fun — inside a video game! Every time a game character chases you, dodges your attacks, or suddenly gets harder to beat, something is making those decisions. Most of the time, that something is AI. Let's peek behind the screen.

Game Characters That Chase and Dodge

Imagine you are playing a game and a ghost starts following you through a maze. How does the ghost know where you are? How does it find a path to reach you? The ghost is not controlled by another player. A piece of AI code called a pathfinding algorithm figures out the shortest route from the ghost to you. It checks the maze, picks a path, and updates it every fraction of a second as you move. Algorithm is a big word for a step-by-step recipe. A pathfinding algorithm is a recipe a computer follows to find the best route from one place to another.

The Big Idea

Game characters that seem to chase, hide, dodge, or attack on their own are following AI rules. The rules are written by game designers who want the game to feel alive and exciting.

Other game characters are even cleverer. In some fighting games, the computer opponent watches how you fight and starts to copy your moves or find your weak spots. You throw a punch, it learns to block. You dodge left, it starts jumping to your left. This is AI noticing patterns in your play — just like in the last two lessons — and using them against you! Some games even change their own difficulty level based on how well you are doing. If you are winning a lot, the game secretly makes the next round a tiny bit harder. If you are struggling, it makes the next one a little easier. This is called dynamic difficulty, and it is AI doing the adjusting.

Dynamic difficulty is a perfect example of AI adapting. The game is not just following the same rules every time. It is watching your score, noticing a pattern, and changing the rules to keep the game fun. A plain machine could not do that.

Fill in the missing words about game AI.

A is a step-by-step recipe a computer follows to solve a problem. Games use this to help characters find the route to the player.

Computer opponents in chess, checkers, or card games use AI too. A chess AI looks at all the possible moves, thinks several steps ahead, and picks the one most likely to win. Some chess AIs are so strong that even the world's best human chess players cannot beat them! But remember what we learned in lesson one: the chess AI does not enjoy the game. It does not feel excited when it wins or sad when it loses. It just follows its pattern-finding recipe, very fast.

Watch the Patterns

Next time you play a game with a computer opponent, try changing your strategy on purpose. See if the computer opponent starts to change too. If it does, you have spotted AI adapting to you!

What does a pathfinding algorithm do in a video game?

What is dynamic difficulty?

Design a Game AI

  1. Imagine you are designing a video game. Your game has a monster that tries to catch the player.
  2. On paper, write or draw answers to these questions:
  3. What does the monster do when the player is far away?
  4. What does the monster do when the player is close?
  5. What does the monster do if the player hides behind something?
  6. Read your rules to a friend or family member and ask them: do these rules make the monster feel smart?
  7. Congratulations — you just wrote an AI behavior tree, the same kind game designers use!