Super confused about zombie turn handling.

Game development with Board Game Arena Studio
Post Reply
User avatar
ShashaKrismas
Posts: 15
Joined: 21 April 2013, 10:30

Super confused about zombie turn handling.

Post by ShashaKrismas »

Hello,
For my game I'm trying to implement zombie turns.
When a player turns into a zombie, the game just changes active player, goes to the end of turn state and then starts a new turn like normal. Zombie is deactivated for multiplayer states, otherwise he is never in an active state so never needed.

I get stuck with error zombie infinite loops, instead of the new real player getting a new turn.

Code: Select all

    2 => array(
        "name" => "playerChooseNumber",
        "description" => clienttranslate('${actplayer} must choose a number'),
        "descriptionmyturn" => clienttranslate('${you} must choose a number'),
        "type" => "activeplayer",
        "possibleactions" => array("chooseNumber", "zombiePass"),
        "transitions" => array("chooseNumber" => 20, "zombiePass" => 19)
    ),

    19 => array(
        "name" => "zombieChangePlayer",
        "description" => clienttranslate('Changing player'),
        "type" => "game",
        "possibleactions" => array(""),
        "transitions" => array("" => 2),
        'action' => 'st_zombieChangePlayer',
    ),
   
The active player after state 19 is not the zombie player anymore.
Why does this happen ? I don't want the game to use the transition zombiePass when it's NOT the turn of the zombie, otherwise other people wouldn't be able to play at all.

Code: Select all

    function zombieTurn( $state, $active_player )
    {
    	$statename = $state['name'];
    	
        if ($state['type'] === "activeplayer") {
            switch ($statename) {
                default:
                    if($active_player == self::getActivePlayerId()) {
                        $this->gamestate->nextState("zombiePass");
                    }
                	break;
            }

            return;
        }

        if ($state['type'] === "multipleactiveplayer") {
            // Always skipping for 
            // Choosing hand/confirming he saw the card.
            $this->gamestate->setPlayerNonMultiactive( $active_player, '' );
            return;
        }

        throw new feException( "Zombie mode not supported at this game state: ".$statename );
    }
User avatar
SwHawk
Posts: 133
Joined: 23 August 2015, 16:45

Re: Super confused about zombie turn handling.

Post by SwHawk »

You seem to be confusing some things about zombie turn handling so I'll try to clear them out.

First of all, zombies should not (except some very rare cases) execute actions. zombies will generally follow the given transition (which by default is zombiePass, but you may elect to change this if you so wish). You shouldn't define a zombiePass possibleaction in your states.inc.php file, since those actions are player actions (ie, real players in front of their computers, not zombies). Only defining the transition is enough.

This will also eliminate the risk of a player somehow triggering the zombie action while they are actually active... As a side not, there is no need to check if the zombie is the active player in the zombieTurn function. This is already done by the framework.

What I don't understand is why you are using a specific state for changing the active player for zombies. What I mean by that is that a zombie is not supposed to take any action during their turn. And I'm also assuming you already have a game state that handles changing the active player for regular players. This state should work for zombies as well with no modifications... So your zombiePass transition (in the playerChooseNumber state that is) should point to that state instead of creating a state just for this. My two cents on this is that you transition to both states and the active player is changed twice, resulting in the loop you're describing. I may be mistaken, but that seems a possible explanation.

In short, zombies should only be handled using transitions, not possibleactions (which are player actions after all...).
User avatar
ShashaKrismas
Posts: 15
Joined: 21 April 2013, 10:30

Re: Super confused about zombie turn handling.

Post by ShashaKrismas »

Thank you for your answer, I think I get it more.
I actually didn't define a zombiePass action, I filled it from a template by mistake

The reason I'm changing active players is because a zombie can be created by an active player (it's my turn and I quit), and I have to create a state for this because then the active player needs to be changed differently from the state that it's usually doing it and we need to resolve a turn without mistakes, and this is what I am trying to acthieve here. I still don't get quite why I have an infinite loop because I defined the zombiePass transition on all the states that my zombie needs to go through in order to resolve. If I make the transition point to a multiplayer state, then I get no loop. But I don't want to go through the multiplayer states.

"My two cents on this is that you transition to both states and the active player is changed twice, resulting in the loop you're describing. I may be mistaken, but that seems a possible explanation."
I don't know if I understood you correctly but 2 goes to state 19 which points back to 2, so I'm only changing the player once (in state 19)

To sum up it goes like this (or at least I would like):
- a player is active and decides to quit
- the game goes to the state to switch to a player that is not a zombie
- a new turn is started with an active player > game should take transition to state 20 not 19


When I make a player quit that is not active when he becomes a zombie, with this snippet, the game works fine and as intended.
User avatar
SwHawk
Posts: 133
Joined: 23 August 2015, 16:45

Re: Super confused about zombie turn handling.

Post by SwHawk »

Well I don't see why you would need a specific state for handling an active player becoming a zombie, but then I don't know the game you're working on, so I'll assume you're doing it out of necessity.

zombieTurn is, IMHO, one of the most difficult thing to debug. I'm assuming the player has to perform a series of actions during their turn, correct me if I'm wrong.

I'll also assume that the purpose of zombieChangePlayer is only to change the active player (btw, you don't need to fill in a description/decriptionmyturn for game states, it won't show).

In my limited experience, what you can do to debug zombieTurn is sending notifications (by using notifyAllPlayers) with messages that you will understand and help you follow the states the zombie eventually follows, which should help you find where the loop is.

Another idea, since I'm assuming a series of actions, is to start by turning a player zombie (you can type timeout() in the game chat on the Studio to automatically the active player with the least remaining thinking time) in the last state of the series and work you way up to the first.
User avatar
ShashaKrismas
Posts: 15
Joined: 21 April 2013, 10:30

Re: Super confused about zombie turn handling.

Post by ShashaKrismas »

Thank you for your advice! The zombie player has to perform actions yeah so my idea was to switch players in order to define variables that can be defined only by player input (otherwise game crashes)

Messages during loops don't show, the log is too big and messages that would be normally displayed aren't here, so it's hard to understand why the game behaves this way. Nothing worked except when I jumped straight to multiplayer states so I decided to end the game instead.
Post Reply

Return to “Developers”