AI
Artificial intelligence, like physics and animation, is also its own field of study. We can use PCG to enhance certain aspects of AI. In Chapter 7, Adaptive Difficulty, we used PCG to rewrite a section of our AI. This isn't always the most practical approach though.
AI for games can be easily visualized as a state machine or a graph of connected behaviors. Some actions in the AI graph might lead to others or some situations might cause an AI to enact a certain behavior. In the following diagram, we see rectangles represented as states and arrows representing states transitioning into other states. This network of states can be as complex or simple as we like.
An example of a complex AI state machine is Bethesda's Radiant AI. This AI system has the NPCs react to the actions of the player, but also has them generate a daily routine. They can go to work, travel, and some might set out to attempt assassinations. These behaviors are programmed separately, but then the routine...