Zombie mode in two-player games

Game development with Board Game Arena Studio
Post Reply
User avatar
Brainchild
Posts: 71
Joined: 31 January 2014, 19:42

Zombie mode in two-player games

Post by Brainchild »

I tried to implement a simple zombie mode in my 2-player game that immediately ends the game if one player leaves. It looks like this:

Code: Select all

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

            return;
        }

        if ($state['type'] === "multipleactiveplayer")
        {
            // Make sure player is in a non blocking status for role turn
            $this->gamestate->setAllPlayersNonMultiactive("zombieEnd");
            
            return;
        }

        throw new feException("Zombie mode not supported at this game state: " . $statename);
    }
When a player leaves, I get:

Code: Select all

Unexpected error: BGA gameserver 1 do not respond (method: zombie) (timeout: cluster)
Here's the state code for "zombieEnd":

Code: Select all

    function stZombieEnd()
    {
        // It's a two-player game, so if a player leaves, just end it.
        $this->gamestate->nextState("gameEnd");
    }
And, in case it is relevant, here's the state machine:

Code: Select all

    STATE_ZOMBIE_END => array(
        "name" => "zombieEnd",
        "description" => "",
        "descriptionmyturn" => "",
        "type" => "game",
        "action" => "stZombieEnd",
        "transitions" => array(
            "gameEnd" => STATE_GAME_END)
    ),
User avatar
paramesis
Posts: 398
Joined: 28 April 2020, 05:00

Re: Zombie mode in two-player games

Post by paramesis »

Is it consistently happening? That looks more like a server problem than anything in your code.
User avatar
Brainchild
Posts: 71
Joined: 31 January 2014, 19:42

Re: Zombie mode in two-player games

Post by Brainchild »

Yes, every time. And the game doesn't end either. I suspect I'm doing something fundamentally wrong.
User avatar
paramesis
Posts: 398
Joined: 28 April 2020, 05:00

Re: Zombie mode in two-player games

Post by paramesis »

Hmm... I've had errors where the state machine gets stuck in an infinite loop, but the error that usually produces is something like "Fatal Error, execution time exceeded 1 second".

There have been a few threads about studio games in progress getting broken because of a recent update enabling the upgradeTableDb feature for the studio. If that were the problem here, the behavior might be different if you tried it in a new game.

If you've already tried that, I would see if the zombieEnd transition works from a normal activeplayer state without a zombie...
User avatar
Inaofr
Posts: 142
Joined: 26 March 2020, 22:26

Re: Zombie mode in two-player games

Post by Inaofr »

Code: Select all

        $statename = $state['name'];
        
        if ($state['type'] === "activeplayer")
        {
            switch ($statename)
            {
                default:
                    $this->gamestate->nextState("zombieEnd");
                    break;
            }

            return;
        }
These lines of code implies that all your states of type "activeplayer" must have a transition called "zombieEnd".
The next bloc of code implies the same for all states of type "multipleactiveplayer".

It might be the root of your issue.

By the way, I think you don't need a STATE_ZOMBIE_END, you probably could set-up your zombieEnd transition to go directly to the STATE_GAME_END.
User avatar
Brainchild
Posts: 71
Joined: 31 January 2014, 19:42

Re: Zombie mode in two-player games

Post by Brainchild »

Inaofr wrote: 02 July 2020, 22:03 These lines of code implies that all your states of type "activeplayer" must have a transition called "zombieEnd".
The next bloc of code implies the same for all states of type "multipleactiveplayer".

It might be the root of your issue.

By the way, I think you don't need a STATE_ZOMBIE_END, you probably could set-up your zombieEnd transition to go directly to the STATE_GAME_END.
You are correct, every player state (active and multiactive) has the zombieEnd transition. I could go straight to game_end but I wanted it to be clear reading the state machine that it only applies to zombies.
User avatar
Een
Posts: 3861
Joined: 16 June 2010, 19:52

Re: Zombie mode in two-player games

Post by Een »

Brainchild wrote: 02 July 2020, 21:12 Yes, every time. And the game doesn't end either. I suspect I'm doing something fundamentally wrong.
Yes :D
The zombie is there... to allow the game to continue, not to end it. So trying to end the game going wrong is not so surprising.
The idea is that the players left in the game can choose either to continue (even a player left alone) till the normal end of the game, with the zombie not playing or doing the minimal move needed (such as passing in many games) to allow the game to move forward, or to quit the game (without penalties since another player has already left). The game should not end automatically.
User avatar
Brainchild
Posts: 71
Joined: 31 January 2014, 19:42

Re: Zombie mode in two-player games

Post by Brainchild »

Een wrote: 03 July 2020, 09:19 The zombie is there... to allow the game to continue, not to end it. So trying to end the game going wrong is not so surprising.
The idea is that the players left in the game can choose either to continue (even a player left alone) till the normal end of the game, with the zombie not playing or doing the minimal move needed (such as passing in many games) to allow the game to move forward, or to quit the game (without penalties since another player has already left). The game should not end automatically.
Ok thanks Een, I will try to come up with something reasonable for the lonely player to do without messing up the code too much. But it's a trick-taking game... Should the zombie choose a random card to play or is it better to choose nothing?
User avatar
Een
Posts: 3861
Joined: 16 June 2010, 19:52

Re: Zombie mode in two-player games

Post by Een »

Brainchild wrote: 03 July 2020, 10:06 Ok thanks Een, I will try to come up with something reasonable for the lonely player to do without messing up the code too much. But it's a trick-taking game... Should the zombie choose a random card to play or is it better to choose nothing?
Both are acceptable. In any case, the game is broken, so anything is ok, the zombie is not meant to be clever :)

That's just to allow the players left in play to finish the game on their terms rather than having it abruptly cut off. For example, if it's the last turn, the player may want to do it to get the feeling of completing the game. Or even if it's the beginning of the game, they may want to continue to see some more turns to learn the game before leaving.
Post Reply

Return to “Developers”