Rotates.org

January 4, 2012 - Expressing my love

Over the last few days I’ve been planning, and then implementing the RESTful communication part of the server, and this has been built on top of Express‘s fantastic routing. The next few days will see me implementing the rest of the current game logic on top of this routing, using the HTTP GET and POST methods and simple URI schemes in order to provide any client with a stateless, efficient way of communicating with the server.

For example, a client could request ‘/games‘ from the server and receive a list of games, each with its vital stats (players, board size etc). A client can then request to see more on an individual game by requesting ‘/games/game01‘ for instance. A client can then finally choose to get the status of the game from a particular point via ‘/games/game01/update/20‘ which will return all the actions from action 20 and above, or alternatively the client can request ‘/games/game01/update/1325635230240‘ which retrieves the actions from after that timestamp. The server determines whether a request called for a timestamp or an action ID easily because of the huge numerical difference between the likely amount of actions in a game and the value of a typical timestamp.

I have also decided (for now at least) to focus on JSON as the primary format for data from the server – I had intended to explore other formats such as XML, BSON and MessagePack but keeping things in JSON seems to be efficient enough at the moment.

Once the server is returning everything correctly using this new URI structure, I’ll shift my focus to the client for a while, and get some of the boring stuff such as creating/editing users and access control sorted out. I’m being purposely very careful about having something solid and playable before I go and start with the spell phase, and all of the delightful things that brings with it!

December 18, 2011 - Errors and actions

I’ve been getting into a routine of testing, re-writing and bolstering everything over the past week or two. This is in direct contrast to my usual routine of writing massive blocks of code without testing, then firing it up and watching it fail in multiple places, then lose the will to continue (something perhaps familiar to many developers) – so this time making sure every routine is working efficiently and giving me verbose feedback in every possible situation has been high on my priority list.

Tonight I implemented error codes and matching error messages – boring I know, but it’s just one of many steps I’ve taken to make sure I know when things aren’t working, and to make the client/server architecture as bullet-proof as possible. All this work at the front-end is to make sure that when the server’s launched, it’ll have a really easy to use API. One of my major goals after all is to make this an ‘open’ Chaos server, and invite front-end developers to produce their own ports for various platforms – indeed it should be very possible to write a front-end for a Spectrum using the same graphics, sounds and so on!

One of the other things I’ve implemented is a step-by-step list of actions for each game. The stored game data contains a current snapshot of the game, active players, unit positions etc – but it also now contains a blow-by-blow account of the entire game from when it’s created, as players join and then start playing. Clients will then be able to store a timestamp (returned from the server after each action they perform) and then put out polled or long-polled requests for updates from the server, quoting that timestamp. Once the server processes new actions, it can return those actions to the requesting client in the correct order (so for instance, if a player moves their wizard in the first turn, the server automatically advances to the next player as they no longer have any units to move – this logs two actions, a unit movement and then a “next user’s turn” action). Clients may choose to return actions from any timestamp, so as long as the client knows when it last got an update, it can always stay in sync. The client may also optionally request all the actions, in effect providing a way of replaying an entire game, or it can just request a ‘refresh’, which sends the client a snapshot of the game as it stands, with all the data it needs to resume the game from scratch.

Here’s an example of a typical update:

{

    "response": {
        "success": [
            {
                "id": 8,
                "action": {
                    "turn": 3,
                    "currentPlayer": 0
                },
                "time": 1324168638420
            },
            {
                "id": 9,
                "action": {
                    "moved": {
                        "id": "wizard_0",
                        "from": {
                            "x": 3,
                            "y": 5
                        },
                        "to": {
                            "x": 4,
                            "y": 5
                        }
                    }
                },
                "time": 1324168655828
            },
            {
                "id": 10,
                "action": {
                    "turn": 3,
                    "currentPlayer": 1
                },
                "time": 1324168655828
            }
        ]
    },
    "currentTime": 1324168722155

}

So far, I have a very solid base – board sizes and player counts are limitless and the server will automatically position wizards in a ‘Chaos-like’ arrangement around the board, regardless of size, shape or number of wizards, or at least up to 8 wizards, after that I need to write a routine to automatically space them – probably via some kind of circular distribution. Although spell casting isn’t yet implemented, units are and can be created by manually editing the game data – so I’ve had a wizard and his hydra happily moving around the board to my infinite satisfaction.

Next to be done is the combat routines – which will lead to the invariably sticky (though hopefully MUCH more manageable) death routine, which is always a bit of a pain with Chaos. Remember, some units die, some units disappear, some units (wizards) disappear and trigger a player defeated routine, blobs engulf, magic fire destroys outright and leaves no corpse, wizards on mounts if attacked by units lose their mount, but if overrun by magic fire disappear and trigger a player defeated routine and so on and on.

Plainly remaking Chaos is not as simple as it seems.

November 26, 2011 - Multiplayer!

March 12, 2011 - Merry Christmas, happy new year and so on

First of all, apologies for not updating in yonks – I could give you the usual programmer excuses about real life, work and so on but you’ve heard them all before, so I’ll dive right in to what I’ve been doing:

Archaos is very, very slowly moving along – we’re talking geologically slow here, but nonetheless there’s still a roadmap and there’s still progress on it. My aim now is to have a release before my 30th birthday (next year) and I’ll be damned if I don’t make it!

I’ve been experimenting with presentation and so on, and came up with a little thing tonight which I thought was quite cute.  I’m really feeling the love for CSS3 and HTML5 now.

WordPress has become my new powerhouse tool at work, and I’ve been churning out sites left, right and centre in this wonderful blog engine turned CMS (as of 3.1 especially so) – check out some of the following:

The last is our most recent project, and is very much not a site you’d expect to be WordPress powered – such is its flexibility!

I don’t update on Twitter much anymore, as it’s become a bit of a joke now with all of the celebrities and ridiculous trends; it pains me to say it but I think Twitter is more about Justin Bieber now than anything sensible. Alas, I spend most of my social networking time now on Facebook.

Finally, I’ve booked a flight to Arizona in September for a two week photography road trip with two of my good friends – should be awesome!

Anyway, hopefully that’s got everyone up to speed on what I’m doing – keep your eyes peeled in the coming months for updates on Archaos and other projects.