m_iThirst += 1;
Now that you’ve seen how the Miner class operates, let’s take a look at
each of the states a miner can find itself in.
The Miner States
The gold miner will be able to enter one of four states. Here are the names
of those states followed by a description of the actions and state transitions
that occur within those states:
EnterMineAndDigForNugget: If the miner is not located at the
gold mine, he changes location. If already at the gold mine, he digs
for nuggets of gold. When his pockets are full, Bob changes state to
VisitBankAndDepositGold, and if while digging he finds himself
thirsty, he will stop and change state to QuenchThirst.
VisitBankAndDepositGold: In this state the miner will walk to the
bank and deposit any nuggets he is carrying. If he then considers
himself wealthy enough, he will change state to GoHomeAnd-
SleepTilRested. Otherwise he will change state to EnterMine-
GoHomeAndSleepTilRested: In this state the miner will return to
his shack and sleep until his fatigue level drops below an acceptable
level. He will then change state to EnterMineAndDigForNugget.
QuenchThirst: If at any time the miner feels thirsty (diggin’ for
gold is thusty work, don’t ya know), he changes to this state and vis
its the saloon in order to buy a whiskey. When his thirst is quenched,
he changes state to EnterMineAndDigForNugget.
Sometimes it’s hard to follow the flow of the state logic from reading a text
description like this, so it’s often helpful to pick up pen and paper and draw
a state transition diagram for your game agents. Figure 2.2 shows the state
transition diagram for the gold miner. The bubbles represent the individual
states and the lines between them the available transitions.
A diagram like this is better on the eyes and can make it much easier to
spot any errors in the logic flow.
54 | Chapter 2
The West World Project