Skip to content

Thoughts on not returning from method (StateMachine) #2

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
clankill3r opened this issue Oct 26, 2019 · 1 comment
Open

Thoughts on not returning from method (StateMachine) #2

clankill3r opened this issue Oct 26, 2019 · 1 comment

Comments

@clankill3r
Copy link

https://github.com/wangchen/Programming-Game-AI-by-Example-src/blob/master/Buckland_Chapter2-State%20Machines/WestWorld1/MinerOwnedStates.cpp#L60

In the StateMachine for EnterMineAndDigForNugget there is the following:

//if enough gold mined, go and put it in the bank
if (pMiner->PocketsFull())
{
pMiner->ChangeState(VisitBankAndDepositGold::Instance());
}

if (pMiner->Thirsty())
{
pMiner->ChangeState(QuenchThirst::Instance());
}

Now I wonder, wouldn't it be better to return on after the lines where ChangeState is called.
Cause now for example if the miners pockets are full it would go to the bank.
But if the miner is also thirsty, then the if statement for that block is still executed.
This will change the state to QuenchThirst from the bank location.
This could lead to really unexpected behaviour.

@AleksandrHovhannisyan
Copy link

@clankill3r I think the idea here was to establish an order of precedence. If the miner is thirsty, he will most likely prefer to go get a drink instead of depositing his money, since the latter is something he could easily do later, whereas prolonged thirst may kill him (depending on the game mechanics).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants