O'Reilly logo

Programming Game AI by Example by Mat Buckland

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Introducing Elsa
To demonstrate these improvements, I’ve created the second project for
this chapter: WestWorldWithWoman. In this project, West World has
gained another inhabitant, Elsa, the gold miners wife. Elsa doesn’t do
much just yet; she’s mainly preoccupied with cleaning the shack and emp
-
tying her bladder (she drinks way too much cawfee). The state transition
diagram for Elsa is shown in Figure 2.5.
State-Driven Agent Design | 67
Introducing Elsa
Figure 2.4. The updated design
When you boot up the project into your IDE, notice how the VisitBathroom
state is implemented as a blip state (i.e., it always reverts back to the previ-
ous state). Also note that a global state has been defined,
WifesGlobalState,
which contains the logic required for Elsa’s bathroom visits. This logic is
contained in a global state because Elsa may feel the call of nature during
any state and at any time.
Here is a sample of the output from WestWorldWithWoman. Elsa’s
actions are shown italicized.
Miner Bob: Pickin' up a nugget
Miner Bob: Ah'm leavin' the gold mine with mah pockets full o' sweet gold
Miner Bob: Goin' to the bank. Yes siree
Elsa: Walkin' to the can. Need to powda mah pretty li'l nose
Elsa: Ahhhhhh! Sweet relief!
Elsa: Leavin' the john
Miner Bob: Depositin' gold. Total savings now: 4
Miner Bob: Leavin' the bank
Miner Bob: Walkin' to the gold mine
Elsa: Walkin' to the can. Need to powda mah pretty li'l nose
Elsa: Ahhhhhh! Sweet relief!
Elsa: Leavin' the john
Miner Bob: Pickin' up a nugget
Elsa: Moppin' the floor
Miner Bob: Pickin' up a nugget
Miner Bob: Ah'm leavin' the gold mine with mah pockets full o' sweet gold
Miner Bob: Boy, ah sure is thusty! Walkin' to the saloon
Elsa: Moppin' the floor
Miner Bob: That's mighty fine sippin' liquor
Miner Bob: Leavin' the saloon, feelin' good
Miner Bob: Walkin' to the gold mine
Elsa: Makin' the bed
Miner Bob: Pickin' up a nugget
Miner Bob: Ah'm leavin' the gold mine with mah pockets full o' sweet gold
Miner Bob: Goin' to the bank. Yes siree
68 | Chapter 2
Introducing Elsa
Figure 2.5. Elsa’s state transition diagram. The global state is not shown in the figure
because its logic is effectively implemented in any state and never changed.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required