Page 1 of 1
Automatic state transitions in player states
Posted: 21 December 2016, 02:37
by Victoria_La
Lets say I have a player state "playerTurn", but sometimes the decision player would make either the only
possible one or trivial, in this case I want to automatically transition to next state with decision is made on behalf
of player to speed up the game. Example: in that state player may choose to trade 3 stone for 1 VP, but he does not have enough stone,
so there is no really point asking this specific player.
Yes I can make a game state instead but it would complicate state machine a lot (considering its not the only
one state case).
I used to handle it by java script but it has its own problems: player has to have client running to transition, and during game
replay it hits server with actions which not suppose to happened. Is there a clean way to achieve what I want with client
following proper state transitions?
Re: Automatic state transitions in player states
Posted: 21 December 2016, 11:28
by Een
Not sure if that's what you are looking for, but the usual way to automatically go to the next state in case there is nothing left to do (or if there is a single move that can be done automatically without impact on the good understanding of the game by the player whose move is done automatically) is as follows:
- at the end of your stPlayerTurn, check for the condition for going to the next state
- if true, fire the appropriate transition with $this->gamestate->nextState( 'transition' ), after sending appropriate notifications to update the client if needed.
If you are automatically doing a move, you should also be able to call the function of your game.php that matches the player action for this move in action.php that should do everything like if that move came from a javascript action.
Re: Automatic state transitions in player states
Posted: 21 December 2016, 14:20
by Victoria_La
Yes I understand, but it will not trigger transition to player state, and UI cannot react to that. Player may be puzzled
when he suddenly skips the turn without any sort of indication in the header. Currently I have
state description but I add words something like "...Auto-selected".
What if I transition to player state, then immediately do "action" without waiting for client notification on php side?
Or do check and transitions in php "action" part of state?
Re: Automatic state transitions in player states
Posted: 21 December 2016, 23:04
by Een
Victoria_La wrote:What if I transition to player state, then immediately do "action" without waiting for client notification on php side?
Or do check and transitions in php "action" part of state?
Sorry, not sure what you mean by that
If I understand well, you want to display in the status bar that the action has been auto-selected during a set amount of time instead of jumping directly to the next thing and having only the log to explain what happened. Correct?
You may try to use a
synchronous notification for that just before using $this->gamestate->nextState( 'transition' ) in your stPlayerTurn.
Inside that notification you can overwrite the text in the status bar, and it should last the time set for the synchronous notification.
(of course, for turn based the players will have to rely on the log)
Re: Automatic state transitions in player states
Posted: 22 December 2016, 00:36
by Victoria_La
The state action, I am taking about this:
Code: Select all
12 => array (
"name" => "playerPreFinal",
"description" => clienttranslate( 'Other players may exchange blueprints before final scoring' ),
"descriptionmyturn" => clienttranslate( '${you} may exchange blueprints into track advancements before final scoring (click on track)' ),
"type" => "multipleactiveplayer",
"args" => "argPlayerPreFinal",
"action" => "stPlayerPreFinal", // <-- state action
"possibleactions" => array (
"actionAck",
"actionBlueprintExchange"
),
"transitions" => array (
"next" => 17,
"loopback" => 12,
)
),
I think this would be called after entering the state on php side, which give me change to deactivate some player automatically maybe,
they would see non-active description. But if all player become non-active it will cause state transition initiated from that function which
may cause some havoc
Re: Automatic state transitions in player states
Posted: 22 December 2016, 09:38
by Een
Ok. Yes you can do that.
As far as I understand your states flow, this shouldn't cause any havoc. In stPlayerPreFinal, if you call $this->gamestate->setPlayerNonMultiactive($player_id, 'next'); and there is no more active player, it will just go to state 17. I do something like this for many multiplayer states in Puerto Rico.