🗒 Cheat Sheet← Lesson
BitWithBite
Pygame Mastery Worksheet

🧠 Enemy AI

Module 14 of 20 · Level ★★★ · Time: 40 min
SCORE___ / 20
NameClassDate
After this worksheet you can
Implement patrol movementImplement line-of-sight chasingBuild a finite state machineDesign boss phase transitions
📚 Quick Recap

Enemy AI is built from simple behaviors — patrol between two points, chase when within a detection radius, attack when close — organized by a finite state machine that keeps the enemy in exactly one clearly-defined state at a time.

🧠 Section A · Concept Check ● ADVANCED 4 × 1 = 4

1What is a finite state machine, for an enemy?
2What does .normalize() give you on a direction vector?
3Why does straight-line chasing break around obstacles?
4What commonly triggers a boss's next phase?

🧮 Section B · Problem Solving ● INTERMEDIATE 2 + 3×3 = 11

5A patroller reverses when it reaches either endpoint.
6The FSM state that fires when distance to player is very small is usually .
7Write the condition that switches an enemy from "chase" back to "patrol" when the player gets far enough away.
8Describe a cheaper alternative to full A* pathfinding for many 2D games.
9What data does a boss typically track to decide when to attack again?

🚀 Section C · Challenge ● CHALLENGE 5

10Design a 4-state FSM (name the states) for a guard enemy that patrols, notices the player, chases, attacks when close, and gives up if the player escapes far enough. Describe the transition condition between each pair of states.
💭 Reflection — the most useful thing I learned:
A ___/4   B ___/11   C ___/5   Total ___/20 Teacher's Signature Parent's Signature
✂ answer key — fold or cut before handing out

1-B   2-A   3-B   4-B  |  5 direction   6 attack   7 = elif dist > 300: state = "patrol"   8 = hand-placed waypoint graphs or simple wall-following heuristics, which solve most practical 2D pathing needs without full A* complexity   9 = an attack_timer/cooldown that counts down each frame, triggering the next attack once it reaches zero and then resetting  |  10 = states: patrol (walks back and forth) → chase (triggered when distance < detection radius) → attack (triggered when distance < a close attack range) → back to chase if the player backs off past attack range but stays within detection range → back to patrol if distance exceeds detection radius entirely, meaning the player escaped and the enemy gives up

📄 Need offline practice?Download the print-ready PDF or open the one-page cheat sheet.
⬇ Worksheet PDF 🗒 Cheat Sheet