Game-Logic
-
Finite State Machines
A* tells your guard how to reach the player. It doesn’t tell the guard whether to bother. An entity that only knows how to move isn’t thinking ā it’s executing. A Finite State Machine is the decision layer: a formal description of what an entity is doing right now, what it might do instead, and exactly what must be true for it to switch.
Every guard in every stealth game runs on something like this. So does every enemy AI in a platformer, every shop NPC that goes idle when you walk away, every boss that enters its second phase at half health. FSMs are ubiquitous in games because they map directly to how designers describe behaviour: if the player is near, chase; if the player escapes, give up and return home.
-
Behaviour Trees
A Finite State Machine with four states is manageable. One with ten states, where any state might transition to any other, is a maintenance problem. Behaviour Trees solve this by replacing the transition table with a tree of composable nodes ā small, reusable pieces that combine into arbitrarily complex behaviour without the O(n²) transition explosion.
A Behaviour Tree is evaluated top-down every frame. Each node returns one of three values:
SUCCESS,FAILURE, orRUNNING. Parent nodes use these return values to decide which child to run next. The result is that you describe AI behaviour as a hierarchy of priorities rather than a flat list of states.