Finite State Machines, Part II
Last time, I started exploring the finite-state machine implementation from Matt Buckland's Programming Game AI by Example. Today, we are going to continue that exploration, moving beyond that very simple example, abstracting out the implementation of the finite-state machine, adding an additional agent, and implementing a message-passing mechanism to allow our entities to communicate.
In addition to Miner Bob, we are going to add an additional entity to our quaint Wild West simulation, his wife, Elsa. Like Bob, Elsa has a pretty simple existence - she concerns herself with keeping their humble home tidy and cooking up dinner when Bob comes back home from his grubbing in the mine.
In the previous example, our entities had no knowledge of any other entities - Miner Bob was alone in his little world, and there was no necessity of him responding to any external stimuli. Now, with the introduction of Elsa, we need a mechanism for them to interact, and alert each other of their presence. To do this, we will introduce a message passing system, which will allow our entities to broadcast and respond to events, both instantaneous and delayed. To support this, we are going to need to build up some infrastructure: a structure to encapsulate a message, a centralized message queuing and dispatching system, a timing subsystem to support delayed messages, and an entity registration system, to allow indexing and cross-referencing entities.
The full code for this example can be viewed on GitHub, at https://github.com/ericrrichards/ai/tree/master/trunk/AI/WestWorld2.