I’m trying to create a turn based multiplayer online game where players can be grouped in a room/lobby and play (similar to Ludo but number of players can be more than 4). There can be multiple such rooms at a time.
Here is brief overview of the game: The game is not resource heavy. Each player gets his turn to perform some actions for some time (~90 seconds) and meanwhile other players just communicates with server to get the actions performed by the player. There can be multiple game rounds and a winner is declared at the end.
The game state of each room would be different at a given time. Therefore, to manage the game states for all the rooms, I could think of two approaches:
- Multithreading approach: Spawn a new thread for each room and run/manage the game loop and corresponding game states in room specific threads. But if there are too many rooms, the number of threads would be very large and this approach is not feasible as per this answer’s comment. However this approach is preferable for mass multiplayer games online games (MMO) as per this answer. I also think this should work for considerable number of rooms because most of the time, threads are waiting for player’s actions.
- Asynchronous approach: Here, the game states of all the rooms would be stored in server’s memory and whenever any requests is received from any player, the game state object will be retrieved using player’s room ID and based on the state, the server will command players in that room. The state will then be updated. There will be only one main thread here.
So my question is what would be the better approach for this type of games, considering the future scaling requirements? Also suggest any better alternatives which I couldn’t think of.