Single source of truth on game state

394 views Asked by At

I am newbie in game development, I want to create a multiplayer game server with node.js I want to know, what is the most common techniques and patterns to keep and change game state on the server

My game state size has little size, So I think the best place is memory to store it

I want to scale up and out my server game, so each player can connect to different server

I am worry about simultaneous events that change state of game in different servers, So having single source of truth is somehow complex, because potentially the state on each server can be get out of sync

In nutshell, What is the common approach to build a multiplayer turn based games that server has to implement some logic to control game flow such as changing turn, changing state of game in case in inactivity of the player, ...

I also don't know how to protect state against restating server, May be a redis can save the state, But how to control the game flow after losing the controller

2

There are 2 answers

4
tyChen On BEST ANSWER

Firstly, I think it's bettert to start from a little model with central server, the thing about "change state of game in different servers" may not fit your game, even if it's fit, you can do it after the simple try. The first important thing is to make the game run as you wish and as simple as possible.

Then we foucs on the how to build a multiplayer turn based game. For such a game, you need at least several things like below

  • Players infomation
    • total information for static (players number, turn count, players order, position of players, the running player now in this turn)
    • every player's infomation (name, ID, money, others)
  • Map Manager
    • Things will happen in every grid
    • Special events or some other game machenism

After that, here is the central logic of server. We need at least following functions:

  • ProcessNetwork() to receive packages and send infomation to others
    • The ending of a player's operation
    • The events happend to one/many players
    • The interaction of several players
  • CheckEnd() to see if the game is end
  • CheckPlayer() to check if we need to give the operation to next player or if it's next turn.
void run()
{
    while (!bGameEnd)
    {
        ProcessNetwork();
        CheckEnd();
        CheckPlayer();
    }
}

And that is the simplist model of a central controller, you can change it to other ways as long as they can work. After that, you can make it more and more complicated to realised your game.

0
karun On

Save the game state in the DB, you can spin up multiple application servers based on the load.