Page 1 of 1
Evolution: Phases translating to states
Posted: 29 April 2020, 15:59
by phranklon
So, I'm developing a states file at the moment. The game has multiple phases with some where players play all at once (select food) and some where the players take turns (play cards and feeding).
When I have the play cards state, the player can create a new species, evolve a new species, or pass. Is it possible to set the transitions to loop back to the same state? (example, if they chose to create a new species and carried out that action, it would re-enter the play cards state for that player giving them the same options to create again, evolve a species, or pass)
I have 'pass' set up to go to the next player, what would I need to do to make sure that after that last player passes, we move on to the feeding phases?
Re: Evolution: Phases translating to states
Posted: 29 April 2020, 16:11
by RicardoRix
You're best is to download the source of a similar game.
For a multiplayer phase:
when they pass:
Code: Select all
$this->gamestate->setPlayerNonMultiactive( $player_id, "completeSelectFoodPhase" );
which is in your states.inc.php transitions:
Code: Select all
"transitions" => array( "completeSelectFoodPhase" => 22 )
"type" => "multipleactiveplayer",
When Players take turns and pass to the next. That's just a standard
to loopback I think there are few things you can try. You could not use a transition and just handle it all until they pass, OR
You could have an array of transitions.
Code: Select all
"transitions" => array("next" => 33, "loopback" => 31, "endGame" => 99),
And you may or may not need to manipulate the next player.
Code: Select all
$this->gamestate->changeActivePlayer($nextPlayerId);
It sounds best though not using a transition until they pass, and that you should be handling all the different things they might like to do at once....maybe..
OR they just all keep having 1 turn each until they pass. You would need to store the 'player passed' in the DB to know when to move to the next phase - use the players DB table.
Re: Evolution: Phases translating to states
Posted: 29 April 2020, 16:55
by phranklon
Thank you!
Well, that kind of works, but I have a few more questions now:
The select food phase (the only multiplayer state) has only one option. They choose a card and move on (like a SushiGo turn). So can I use the same code you suggested in that regard?
The play cards phase (players don't play all at once unless it's the six-player variant) is single active player*, but each player only goes through it once. Can I use that same code to log that each player has played so it moves to the next state?
The feeding phase should be fine because I can just set it to where they cannot play if they have no hungry species. And move to the next state once each player has no legal moves.
*I was thinking to make this multipleactiveplayer just to make this phase not seem like forever.
Re: Evolution: Phases translating to states
Posted: 29 April 2020, 21:34
by joezg
phranklon wrote: ↑29 April 2020, 15:59
So, I'm developing a states file at the moment. The game has multiple phases with some where players play all at once (select food) and some where the players take turns (play cards and feeding).
When I have the play cards state, the player can create a new species, evolve a new species, or pass. Is it possible to set the transitions to loop back to the same state? (example, if they chose to create a new species and carried out that action, it would re-enter the play cards state for that player giving them the same options to create again, evolve a species, or pass)
I have 'pass' set up to go to the next player, what would I need to do to make sure that after that last player passes, we move on to the feeding phases?
Hi!
I wouldn't transition at all. When you are in a "player turn" state (that one after all players have chosen a card for food), let players do more than one action and only after "pass" action change state.
In other words a player action doesn't have to trigger a transition.
Re: Evolution: Phases translating to states
Posted: 29 April 2020, 21:51
by joezg
phranklon wrote: ↑29 April 2020, 16:55
Thank you!
Well, that kind of works, but I have a few more questions now:
The select food phase (the only multiplayer state) has only one option. They choose a card and move on (like a SushiGo turn). So can I use the same code you suggested in that regard?
When player makes action (say "playFoodCard") you have to change data in the database and execute something like this;
Code: Select all
$this->gamestate->setPlayerNonMultiactive( $player_id, "completeSelectFoodPhase" );
This will deactivate current player. It will also transition to new state, but only after the last player is deactivated.
So yes, you can use code like this in "playFoodCard" action.
phranklon wrote: ↑29 April 2020, 16:55
The play cards phase (players don't play all at once unless it's the six-player variant) is single active player*, but each player only goes through it once. Can I use that same code to log that each player has played so it moves to the next state?
The feeding phase should be fine because I can just set it to where they cannot play if they have no hungry species. And move to the next state once each player has no legal moves.
*I was thinking to make this multipleactiveplayer just to make this phase not seem like forever.
When in activeplayer state (say playerTurn), you will respond to player actions by updating the data in database and sending a notification to clients. When player make "pass" action you should update the database, send notification and transition to next state (say nextPlayer) which is a game type state. In that state you should activate the next player and loop back to playerTurn state.
Of course, in nextPlayer state you need to check if this is the last player in which case you need to transition to nextRound state. In this state you would need to check if the game should end (transitioning to endGame state) or continue. In later case you would transition to playFoodCard state.
There is a lot more nuances, but this could be a basic state machine structure you should implement.