Page 1 of 1
game state engine fail
Posted: 21 April 2013, 21:09
by ddyer
I have a case where the game state engine is apparently calling the wrong state function.
My game uses the "finish" action to move the game along from state to state. My smoking
gun trace is this:
21/04 22:05:28 [warning] [T3856] [2243333/ddyer0] Enter stFinish finish
21/04 22:05:36 [warning] [T3856] [2243338/ddyer5] Enter stFinish review
where I expect the previous to be "enter stReview review"
which comes from
function stFinish()
{ self::warn("Enter stFinish " . self::currentStateName());
// do the scoring
}
function stReview()
{ self::warn("Enter stReview " . self::currentStateName());
}
and state engine
// score and declare the winner
7 => array(
"name" => "finish",
"description" => clienttranslate('${actplayer} designate stones that should be captured'),
"descriptionmyturn" => clienttranslate('${you} wait for ${actplayer} to finish'),
"type" => "multipleactiveplayer",
"action" => "stFinish",
"possibleactions" => array("resume" , "finish", "markStone", "zombiePass"),
"transitions" => array( "finish" => 8, "resume" => 6, "markStone"=>7, "zombiePass" => 8)
),
8 => array (
"name" => "review",
"description" => clienttranslate('${actplayer} review the final position'),
"descriptionmyturn" => clienttranslate('${you} review the final position'),
"type" => "multipleactiveplayer",
"action" => "stReview",
"possibleactions" => array("resume" , "finish", "markStone", "zombiePass"),
"transitions" => array( "finish" => 99, "resume" => 6, "markStone"=>6, "zombiePass" => 99)
),
Re: game state engine fail
Posted: 21 April 2013, 21:14
by Rudolf
What about the code, where is the call of 'NextState' ?
Re: game state engine fail
Posted: 22 April 2013, 01:35
by ddyer
Rudolf wrote:What about the code, where is the call of 'NextState' ?
Nothing remarkable
function finished()
{
self::checkAction( 'finish' );
$this->gamestate->nextState("finish");
}
Re: game state engine fail
Posted: 22 April 2013, 07:36
by Rudolf
and call of nextstate in the game logic to see the previous one? not only the stfunction, but the code management.
Re: game state engine fail
Posted: 22 April 2013, 19:02
by ddyer
The intended flow is that both players pass to move to the "endgame" state,
then both players "finish" to move to "review" state, then both players "finish" again
to accept the result and end the game. At any stage of this, players can decide to resume
play and start the whole process over. I speculate that if I just used a different name
for the second pair of "finish" actions, there would be no problem.
Code: Select all
$machinestates = array(
// The initial state. Please do not modify.
1 => array(
"name" => "gameSetup",
"description" => clienttranslate("Game setup"),
"type" => "manager",
"action" => "stGameSetup",
"transitions" => array( "" => 2 )
),
// Note: ID=2 => your first state
2 => array(
"name" => "playerTurn",
"description" => clienttranslate('${actplayer} must play a stone'),
"descriptionmyturn" => clienttranslate('${you} must play a stone'),
"type" => "activeplayer",
"args" => "argPlayerTurn",
"possibleactions" => array( "playStone","pass" ),
"transitions" => array( "stonePlayed" => 3, "zombiePass" => 4, "passed" => 4 )
),
// normal transition to another turn
3 => array(
"name" => "nextPlayer",
"description" => '',
"type" => "game",
"action" => "stNextPlayer",
"transitions" => array( "" => 2 )
),
// transition to possible endgame
4 => array(
"name" => "nextPlayerPass",
"description" => '',
"type" => "game",
"action" => "stNextPlayer",
"transitions" => array( "" => 5 )
),
// player passed, two passes enter endgame, regular move resumes normal play
5 => array(
"name" => "playerPassed",
"description" => clienttranslate('${you} wait for ${actplayer} to play or pass'),
"descriptionmyturn" => clienttranslate('${actplayer} must play a stone or pass'),
"type" => "activeplayer",
"args" => "argPlayerTurn",
"possibleactions" => array( "playStone","pass" ),
"transitions" => array( "stonePlayed" => 3, "zombiePass" => 6, "passed" => 6 )
),
// both players designate stones to remove
6 => array(
"name" => "endgame",
"description" => clienttranslate('${actplayer} designate stones that should be captured'),
"descriptionmyturn" => clienttranslate('${you} designate stones that should be captured'),
"type" => "multipleactiveplayer",
"action"=>"stEndgame",
"args" => "argPlayerTurn",
"possibleactions" => array( "markStone", "finish", "resume", "zombiepass" ),
"transitions" => array( "markStone" => 6, "zombiePass" => 6, "finish" => 7, "resume" => 2)
),
// score and declare the winner
7 => array(
"name" => "finish",
"description" => clienttranslate('${actplayer} designate stones that should be captured'),
"descriptionmyturn" => clienttranslate('${you} wait for ${actplayer} to finish'),
"type" => "multipleactiveplayer",
"action" => "stFinish",
"possibleactions" => array("resume" , "finish", "markStone", "zombiePass"),
"transitions" => array( "finish" => 8, "resume" => 6, "markStone"=>7, "zombiePass" => 8)
),
8 => array (
"name" => "review",
"description" => clienttranslate('${actplayer} review the final position'),
"descriptionmyturn" => clienttranslate('${you} review the final position'),
"type" => "multipleactiveplayer",
"action" => "stReview",
"possibleactions" => array("resume" , "finish", "markStone", "zombiePass"),
"transitions" => array( "finish" => 99, "resume" => 6, "markStone"=>6, "zombiePass" => 99)
),
// Final state.
// Please do not modify.
99 => array(
"name" => "gameEnd",
"description" => clienttranslate("End of game"),
"type" => "manager",
"action" => "stGameEnd",
"args" => "argGameEnd"
)
);
Re: game state engine fail
Posted: 22 April 2013, 20:18
by Rudolf
I don't know if it's usefull, but i've read somewhere that it's better not to touch to 1 and 99...
So I suggest to make a 98 with your finish and resume choice, then when it's really finish : 99
Re: game state engine fail
Posted: 22 April 2013, 23:33
by ddyer
Rudolf wrote:I don't know if it's usefull, but i've read somewhere that it's better not to touch to 1 and 99...
So I suggest to make a 98 with your finish and resume choice, then when it's really finish : 99
I haven't messed with state 99
Re: game state engine fail
Posted: 26 April 2013, 15:56
by Rudolf
I mean that let the 99 be like all the other games, then, use another state to loop till the real end : 99.

Re: game state engine fail
Posted: 29 April 2013, 07:09
by ddyer
I papered over the problem by giving all the state transition actions unique names.
Code: Select all
6 => array(
"name" => "endgame",
"description" => clienttranslate('${actplayer} designate stones that should be captured'),
"descriptionmyturn" => clienttranslate('${you} designate stones that should be captured'),
"type" => "multipleactiveplayer",
"action"=>"stEndgame",
"args" => "argPlayerTurn",
"possibleactions" => array( "markStone", "finish_endgame", "resume", "zombiepass" ),
"transitions" => array( "markStone" => 6, "zombiePass" => 6, "finish_endgame" => 7, "resume" => 2)
),
and so on.