Emergent behavior and pathfinding are related in two ways. First, pathfinding can be a source of emergent behavior, as the agents in the system adapt their paths to the changing conditions of the environment and the goals of the game. For example, a stealth game may have enemies that patrol different routes depending on the player's location, or a strategy game may have units that form different formations depending on the terrain and the enemy. Second, emergent behavior can affect pathfinding, as the agents in the system influence each other's paths and create new obstacles or opportunities. For example, a crowd simulation may have pedestrians that form lanes, blockades, or gaps depending on their speed and direction, or a simulation game may have animals that create trails, nests, or dens depending on their behavior.