Page 1 of 1

[Closed]Can't get out of private parallel state

Posted: 19 May 2025, 01:46
by JudgeWhyMe
I have two questions (in bold in the message)

Here are my states:
STATE_GAME_SETUP => array(
"name" => "gameSetup",
"description" => "",
"type" => "manager",
"action" => "stGameSetup",
"transitions" => ["" => STATE_START_OF_TURN]
),

STATE_START_OF_TURN => array (
"name" => "startOfTurn",
"type" => "game",
"description" => clienttranslate(""),
"descriptionmyturn" => clienttranslate(""),
"possibleactions" => array ("" ),
"transitions" => array ("startPlayerTurn" => STATE_PLAYER_TURN),
"action" => "stStartOfTurn",
),

STATE_PLAYER_TURN => [
"name" => "playerTurn",
"description" => clienttranslate('${msg} Waiting for other players to end their turn. (STATE_PLAYER_TURN description)'),
"descriptionmyturn" => clienttranslate(''), // Won't be displayed anyway since each private state has its own description
"type" => "multipleactiveplayer",
"initialprivate" => STATE_CHOOSE_CARD,
"action" => "stPlayerTurn",
"args" => "argPlayerTurn",
"possibleactions" => [ ],
"transitions" => [ "endTurnAllPlayers" => STATE_END_OF_TURN] // this is normal next transition which will happen after all players finish their turns
],

STATE_CHOOSE_CARD => [
"name" => "chooseCard",
"description" => clienttranslate('${players} must choose a card'),
"descriptionmyturn" => clienttranslate('${players} must choose a card'),
"type" => "private",
"args" => "argChooseCard",
"possibleactions" => [ "actChooseCard" ],
"transitions" => ["performTrade" => STATE_PERFORM_TRADE]
],

STATE_PERFORM_TRADE => [
"name" => "performTrade",
"description" => clienttranslate('Trade phase: do you want to give or receive?'),
"descriptionmyturn" => clienttranslate('Trade phase: do you want to give or receive ressources?'),
"type" => "private",
"possibleactions" => ["actTradeGive", "actTradeReceive", "actTradePass"],
"transitions" => ["chooseAction" => STATE_CHOOSE_ACTION]
],

STATE_CHOOSE_ACTION => [
"name" => "chooseAction",
"description" => clienttranslate('Other player choose action'),
"descriptionmyturn" => clienttranslate('Action phase: choose an action for your card'),
"type" => "private",
"possibleactions" => [ "actActionBuildCard", "actActionTrashCard", "actActionBuildHouse" ],
"transitions" => ["waitForOthers" => STATE_WAIT_FOR_OTHER_PLAYERS]
],

STATE_WAIT_FOR_OTHER_PLAYERS => [
"name" => "waitForOthers",
"description" => clienttranslate('${msg} Wait for other players end of turn (STATE_WAIT_FOR_OTHER_PLAYERS description)'),
"descriptionmyturn" => clienttranslate('${msg} Wait for other players End Of Turn (STATE_WAIT_FOR_OTHER_PLAYERS descriptionmyturn)'),
"type" => "private",
"action" => "stWaitForOthers",
"args" => "argWaitForOthers",
"possibleactions" => [ ],
"transitions" => [ ]
],

STATE_END_OF_TURN => [
"name" => "endOfTurn",
"description" => clienttranslate("End of turn"),
"type" => "game",
"action" => "stEndOfTurn",
"args" => "argTurnEnd",
"transitions" => array ("nextTurn" => STATE_START_OF_TURN, "endGame" => STATE_GAME_END),
],

// Final state.
// Please do not modify (and do not overload action/args methods).
STATE_GAME_END => [
"name" => "gameEnd",
"description" => clienttranslate("End of game"),
"type" => "manager",
"action" => "stGameEnd",
"args" => "argGameEnd"
],
In stStartOfTurn, I activate all the players as multi active

In stPlayerTurn , I initialize the private state for all active players

The first player performs choose card, trade and choose action step, and is in STATE_WAIT_FOR_OTHER_PLAYERS, displaying the message
"Wait for other players end of turn (STATE_WAIT_FOR_OTHER_PLAYERS description)" in the status bar, as defined in description parameter of STATE_WAIT_FOR_OTHER_PLAYERS

In stWaitForOthers, this player is set non multiactive: $this->gamestate->setPlayerNonMultiactive( $player_id, "endTurnAllPlayers" );
If I understand correctly, the transition will only apply when no player is active.

The second performs choose card, trade and choose action step, and is in STATE_WAIT_FOR_OTHER_PLAYERS, displaying the message
"Wait for other players end of turn (STATE_WAIT_FOR_OTHER_PLAYERS description)" in the status bar, as defined in description parameter of STATE_WAIT_FOR_OTHER_PLAYERS (same as first one)
At this moment, the status bar for the first player displays "Waiting for other players to end their turn. (STATE_PLAYER_TURN description) "
Why did the status bar changed?
According to player_state value in player table in the database, both players are in STATE_WAIT_FOR_OTHER_PLAYERS

The third (and last) player performs choose card, trade. When he performs the choose action step, as I set him to non multi active, triggering the transition "endTurnAllPlayers", I have the following message:
Private state can only be changed in a multiactive state with initialprivate parameter

How can I get out ot these private parallel state and go into STATE_END_OF_TURN ?

Thanks

Re: Can't get out of private parallel state

Posted: 20 May 2025, 22:21
by JudgeWhyMe
I finally found what was the problem was.
I suppressed states STATE_START_OF_TURN and STATE_WAIT_FOR_OTHER_PLAYERS, as I realised they were not useful

I set all players to multiactive for the first time in setupNewGame
I initialize the private state for all active players in stPlayerTurn
I set each player to non multiactive when they arrive at the end of the choose action step
The STATE_CHOOSE_ACTION does not have any transitions any more
in stEndOfTurn, I set all the players to multiactive and I move to STATE_PLAYER_TURN again

This topic can be closed