As a little post-Christmas present, I thought I’d share a little code toy I’ve been working on recently.

You might know that I’m a fan of Twitter as a messaging bus, and I’ve already built some entertainingly daft bots in my time with it. Recently, I decided to flex my programming skills a bit and build not one but four bots. And, more specifically: four bots that talk to each other.

Enter @louis_l4d, @zoey_l4d, @bill_l4d and @francis_l4d. You might notice that they’re named for the characters in Left 4 Dead.

This is not a coincidence.

One of the most wonderful things in that game (which I’ve already commented on the brilliance of) is the banter between the four player characters. There’s so much dense, specific scripting, and enough dialogue so that it rarely repeats. I thought it would be interesting to see if you could simulate the four players’ dialogue over Twitter, sharing some state between the bots, but also finding a way to make them communicate a little with each other.

Well, a bit later, I worked out how, and this is the result:


You get the picture. They run a scenario, they bump into boss zombies, they find stuff, they get hurt (and help each other), they get scared (and reassure each other). At the moment, there are some dialogue overlaps; my main work at the moment is adding more unique dialogue for each bot. Bill is sounding pretty good, but the rest of them need work. It takes about 2-3 hours for them to run a scenario, and it’s usually fun to watch. (And, as you can see, it makes sense to follow all four of them).

So how does it work?

It turned out that rather than trying to build any real AI, it was much more fun just to simulate intelligence. The bots are state machines; they have a variety of states, which they transition in or out of dependent on factors, and suitable dialogue for each state.

I wrote the bots in Ruby. There are two main components to the twit4dead code: the Actor class and the Stage class. The Stage is a singleton; it’s where the state of the world is determined, and global variables tracked. It’s also where all the probabilities are run from. The Actor class is what each of the bots are, and it’s based on the Alter Ego state-machine library for Ruby. We have a lot of states, rules for transition, a selection of methods to handle being helped or talked to by friends, and a method to choose a random piece of dialogue appropriate to the current state.

All the bots are instantiated from a YAML file. For each bot, I store its Twitter username and password, and a nested tree of dialogue for each state. This means it’s really easy to add new states and maintain the dialogue for each bot. It’s also easy to add new bots – you just create a top-level entry in the YAML file.

Originally, I thought about the bots broadcasting and listening over Twitter, but the API calls were just going to get out of hand, and it turned out that Twitter didn’t like being bombarded with messages and would drop a few over time. So I separated out writing the script and broadcasting it. A small utility generates a script file; each line of this file consists of three delimited fields for username, password, and message to send to Twitter. Then, another program – which I currently run on a screened shell – reads that file and broadcasts one line of it every minute until it’s done.

And that’s it. I have to run it by hand for now, which is fine – it’s more something I fire up every now and then, rather than something you want to permanently run. I originally was going to keep track of loads of statistics – health, zombies in play, etc – but found a cruder set of rules worked much better. Every time they’re in combat, there’s a slim chance somebody gets hurt; every time somebody’s hurt, a friend will rush to save them. That sort of thing. Simulated Intelligence, then, rather than Artificial Intelligence.

Alter Ego turned out to be a lovely library; dead simple to use, and as a result the bots are really nicely modelled (or, at least, I’m very happy with how they’re modelled). The notion of a Stage with Actors, rather than a Game with Players, feels about right, and the modularity of it all is pretty nifty. It still requires a little refactoring, but the architecture is solid, and I’m proud of that.

I think my favourite aspect of it, though, is that at times, watching the bots play together is a little like magic. The first time I saw them talk to each other, cover each other whilst reloading, help each other up after a Boomer attacked, I felt a little (only a little, mind) like a proud father. They’re dumb as a sack of hammers, but they look convincing, and that was the real goal. It’s fun to watch them fight the horde amidst all my other friends on Twitter.

Nonsense, then, but a fun learning exercise about state machines, object orientation, and simulating conversations. State machines are a ton of fun and if you’ve not seriously played with them, I thoroughly recommend it.

Do follow the four of them, if you fancy; I’ll make sure I run them with reasonable regularity, and I’ll be fixing the dialogue over time. After all, I want to keep Francis happy.

  • "But in a game – or, at any rate, in the kind of game you used to get for Christmas – you’re literally the only person in the universe, and literally the only person with the power to fix things. No-one’s going to come and help, no-one’s going to come and tell you off or second-guess your choices: there’s just you and a world that will stay broken unless you fix it. What’s in the box isn’t a frog power fantasy – it’s a vibrant, momentary taster of the glorious pressure of being a grown-up." Margaret, being brilliant (again) on games, Christmas, childhood, and what it means to be meaningfully alone.

Favourite Games of 2008

24 December 2008

It’s the end of the year, and that means time for lists. My books and albums lists are forthcoming – hopefully tonight or tomorrow – but in the meantime, I thought I’d kick off with ten of my favourite games of the past year.

There’s lots missing here, mainly owing to the fact I haven’t finished a lot of recent titles or given them the time they’ve deserved. What this is, though, is a good summary of what the gaming year felt like to me; ten games I enjoyed a great deal, and that I would recommend in a heartbeat to anyone not sure where to begin with 2008.

And so, in no particular order:

Far Cry 2

(Xbox 360, PS3, PC)


I have written enough about this already, but suffice to say: it sunk its teeth into me, after the initial hump I couldn’t play anything else, and at the end, it left me unable to play anything else for a while. Spectacularly beautiful, too.




Trism began as an app for the jailbroken iPhone; it quickly made the transition to the official App Store platform when that opened up, and it has sold hundreds of thousands of dollars of copies since then, giving Demiforce a fantastic start to their company. And with good reason: it’s a great piece of game design, easy to learn, and hard to master. It also makes brilliant use of not only the iPhone’s capacitive touch screen, but also its tilt sensor. It’s a very pure puzzling experience, and I’ve already sunk many hours into it; it suits the pick-up/put-down rhythm of travel and play on-the-move idaelly. If you have an iPhone or iPod touch, this really is a no-brainer.

Geometry Wars Retro Evolved 2

(Xbox 360)


It’s still one of the best games on Live Arcade. It’s also still one of the best asynchronous multiplayer games you can play. Making your friends high scores the default high score table gives it a great competitive streak and really contextualises your performance: nothing’s more frustrating than having emailed a friend to say “hah, beat your high score” only to receive an response five minutes later informing you that the ball is firmly back in your court.

Adding variety to the original formula are the six game modes, slowly unlocked over time. They may all be variants on a theme, but they all still demand unique skills and become games in their own right: turning the Pacifism achievement from the first game into a mode in its own right was a great move.

Beautiful in high-def, easily explained to anyone who’s played a videogame in their life, it’s by turns accessible and challenging, and an essential purchase for new 360 players. Also, its social scoreboards give it great longevity, and prove what I already know: I’m nearly, but not quite, at the bottom of the pack when it comes to motor control. As long as I’m not last…


(Xbox 360)


If there’s a measures of Braid’s success, it’s not to be found in its sales or metacritic scores, but in the sheer volume of verbiage devoted to it in the blogs, forums, and magazines of the gaming world. Thousands of words, all expended on the game, on the hype, and on what the hell it all means.

It wouldn’t have got that discussion if it wasn’t in some way good, and it really is: beautiful, challenging, and proof of the things that only games can do. It embraces game-native storytelling, wrapping its meaning tightly around its mechanics, and tells its tale through challenging, timeless puzzles and David Hellman‘s incredible artwork.

Perhaps it is a little pretentious; perhaps the writing is weak. Regardless of those facts, it’s exciting to see a game like this getting such a major launch on a mainstream, living-room platform, and as an artefact to push forward the casual – as well as professional – criticism of games, it’s a great starting point.


(Xbox 360, PS3, PC)


I always forget how much I like racing games. GRID is a very, very fine take on the racer. It’s beautiful, it’s fast, and it’s totally stripped down. GRID demonstrated that Codemasters really understood what making a game “cinematic” might look like: you condense it down into tight, exciting drama. So races take place over two-to-five laps, and in that time the AI will give you as good a catfight as any “realistic” simulator might over an hour. The rewind-time mechanic, as well as being wonderful to watch, removes the traditional racing-game reliance on the “restart” option; giving the game a pre-credits race, not to mention an ongoing narrative of running a team only helps with the Days of Thunder feel. Mapping Le Mans to a twenty-four minute endurance race makes it both exciting and endurable.

And, of course, it’s very pretty and fast as hell. The open-wheel racing is some of the most exciting driving games have to offer, in particular. The drift tournaments are weak, but stick to the touring cars, touge and open-wheel and you’ve got a hell of a game. The icing on the cake is the beautiful, free-floating typography. Solid, and surprisingly good.

Grand Theft Auto IV

(Xbox 360, PS3, PC)

GTA IV screengrab

It’s on everybody else’s list, and I can’t really deny it: it’s a wonderful environment, and a staggering achievement. It’s not as smart as it likes, and it occasionally misfires but it delivers moments by the dozen. Shame the pacing of the islands feels wrong – after the majesty of Three Leaf Clover, being dumped in the New Jersey analogue is a bit underwhelming.

Also: multiplayer, with the right gang of people, is a total hoot. Whilst not the runaway online success that might have been hoped for, if you can get eight to sixteen friends online together, Cops and Crooks or Turf War will bring the fun pretty fast.

God of War: Chains of Olympus



Well, it came out this year in the UK. I played this sitting by a roaring log fire, having spent my days clambering around the Lake District. It is not the greatest game of the year by a long stretch. It is, however, a wonderfully crafted experience: short it may be, but it’s put together almost perfectly: fantastic environments that barely repeat, thrilling combat that’s not too difficult, and one of the most striking in-game sequences I’ve played this year. It helps that the lack of direct camera control translates perfectly to the single-stick PSP. On top of all that, it looks almost as good as the PS2 versions – it’s a remarkable feat of engineering. I had a lot of fun with this, and if you own Sony’s much-unloved portable, you owe yourself to play this.

Left 4 Dead

(Xbox 360, PC)


Gerard Way asked if it was any good, and the answer is yes, Gerard, it is. It’s bloody brilliant, although with the obvious caveat that it gets better with friends. Co-op gaming has slowly seen a slew of support and innovation in the past two to three years, and Left 4 Dead represents one particular pinnacle of that: an experience designed ground-up to be played not only co-operatively, but with real friends.

It’s not about team-mates, it’s about mates; how far would you go to save your friends from a Smoker? Quite far, as it turns out; I’ve noticed that in various pick-up groups, if I have to pick between someone I know in real life and someone I don’t, I’ll go with my friends first. To see such an unashamedly co-op experience – and one that could be described as reasonably hardcore if you hadn’t tried it – achieve such a level of mainstream success is very heartening. I put it down to the fact that Valve are such a talented gang of people, and so fastidious in their process. If you’ve not played through the director’s commentary, you owe it to yourself to do so, if only to understand that nothing in the final product is the result of chance.

Also: it’s great to see a game that puts the mechanic, indeed, the core technology, that really makes it – the AI – so far front-and-center. Personifying it as the AI Director was the stroke of genius that not only made players aware of it, but gave them someone to blame when they all died. Again.

World of Goo

(Mac, PC, Wii)


There are two reasons, I think, that World of Goo has captured a lot of people’s hearts this year. One is the game itself: the wonderful art; the delightful soundtrack; the just-one-more-go gameplay that carefully teaches you everything to know whilst keeping the challenge just high enough. But the other is the game’s mythology: 2D Boy, two guys working out of coffee shops for a year, giving up on the traditional industry to make the game they really wanted to. It’s the story we all wanted to believe in. The fact that both elements are so great is the real magic of World of Goo: risking it all, living the indie dream, really did lead to a wonderful game.


(Mac, PC, Linux)


I like this more than Rohrer’s previous Passage. It’s a small, simple game, available for most home desktop platforms (Windows/OSX/Linux), about “mania, melancholia, and the creative process”. To say any more is to rob it of its impact. Once I worked out what you have to do to progress, I played on with a huge lump in my throat. To be heartbroken by a game this slight, this simple, in its 100 square pixel area, is quite something, and Rohrer makes games like no-one else.