Wednesday, December 19, 2012

Networky Updatey

The good news is that the infrastructure for multiplayer Chaos games is in place and functioning. This includes:

  • Account creation
  • Login
  • Create game (2-4 players)
  • Join game
  • Leave game
  • Map initialisation and deployment of wizards
The only thing you can do at the moment is end your turn - so there no game play yet. Before I get onto that I need to figure out how to make both synchronous and asynchronous games work properly. The underlying functionality is basically the same. Synchronous games operate under tighter rules - you have a relatively short time limit for your turn. If you fail to respond in time your turn is ended automatically. If you get disconnected your wizard will be taken over by the AI, but I want to allow players a chance to reconnect to the game if they just experiencing internet glitches.
Asynchronous games are played over a much longer period of time, but still with a time limit. This will most likely be some modified chess clock style of timer, where you have a total time limit for completing all your turns, and the time counter counts down while it is your turn. The other thing I need to do with asynchronous games is store and retrieve the game state in a database. Synchronous games are totally 'live' and they reside in the servers memory until the game is over.

The game state is represented by an initial state and a list of game events, which can be anything that happens in the game, such as moving a creature to a hex or an attack. This list of events allows players, or even observers, to view a game from the start - or even to watch completed games. I also want this playback feature to operate with rewind controls so you can step backwards or forwards in the game sequence. This requires a little extra data storage because for each event I have to store the state 'changed from' as well as state 'changed to'. I also need to pack the data into the smallest possible size for network transmission, which means using the minimum number of bits for a piece of data. The Lidgren network library handles this pretty well. I am pretty confident that an average game will be packed into around 20-30kb in size, which is pretty small, but the smaller it is the more games a single server can handle.
Finally, before I start on the game player proper, I need a system for local games. Internally the same message transfer occurs between the client and server functions, but I don't need to update the game state on both server and client side since there will only be one representation of the game. It's a bit more fiddly than it sounds, but I hope it won't take too long. Then the game will have solid foundations for local and network play and I will proceed to creature summoning, movement and combat.
Here is a three player game set up from a client point of view with three wizards deployed. Note, the final game will not look like this, so please don't make fun of my little wizard models!


12 comments:

  1. Great insight Julian. Thanks, Merry Christmas to you, Nick, and family.

    ReplyDelete
  2. Aww, look at his wittle wizard models! So cute!

    ReplyDelete
  3. You HAVE to make your little Programmer Art wizard an unlockable.

    ReplyDelete
  4. I quite like the art as it is, it reminds me of the Escape From Atlantis boardgame: http://boardgamegeek.com/boardgame/24037/escape-from-atlantis.

    ReplyDelete
  5. Can the asynchronous value be modifiable, that is, will the players involved be able to stipulate the maximum time limit? Of course there has to be a maximum threshold, however we may have people playing on opposite sides of the world and one player may skip a day or two, have to [magic] sleep :P etc.

    The reply is an interesting function as if a game hasn't been played for several days, each player could replay the game to catch up on what had happened and cast their next move.

    ReplyDelete
    Replies
    1. Yes, the time limits are configurable when setting up the game.
      The replay function will normally be used to show the opponent's moves since your last turn, but you can always rewind the game to any point and play it back.

      Delete
  6. Thanks for the update.

    Instead of storing a previous and current game state, wouldn't it be possible to rebuild the game world at any point in time given that you already know the initial state and the list of game events that have occurred until that point in time?

    ReplyDelete
    Replies
    1. Yes its possible, but a bit slow. Every time you go back one event you have to build the game from the start.

      Delete
  7. I like the idea of someone being able to re-join if they have network difficulties. Having experienced that recently on XBox Live, it is frustrating.

    You've already made considerable progress with the game Julian. I hope you are going to give yourself a breather over the festive period. Are you having a Bulgarian Xmas Eve dinner?

    ReplyDelete
    Replies
    1. Yeah progress is good, but I will only have a short breather. Indeed we will have the traditional Bulgarian meal on бъдни вечер, composed of the appropriate number of meat-free and dairy-free dishes. Probably not much different to what I normally eat.

      Delete