Live Long

I have a many-decade history in Artificial Intelligence.

Now, in gaming terms, AI tends to be VERY sparse – there just aren’t the cycles to devote to seriously in depth AI. So, what you’re seeing is usually incredibly optimized heuristics – clever rules of thumb that simulate AI without being particularly ground breaking. This is, of course, perfectly fine – it gets the job done after all. Plus, as computers get faster, even this bare bones approach is getting more and more sophisticated.

This game (Conway’s Life) however is the simplest of the simplest.  Basically, each square changes colour depending on what its neighbours are doing. That’s about it, more or less. There’s some simple rules, but they are VERY simple.

So, mostly this will be tricky for me because there’ll be a LOT going on on the screen. It’s too much for Stencyl and Box 2D to handle in the default manner, so I’ll be doing a lot of manual drawing and calculating. It’ll be interesting to see if I can keep the frame rate up (since typically, once you add more than about 20 things on the screen, the whole thing grinds to a halt).

Ok, so I have the design box (top right) you can click (or drag) a pattern. It gives a satisfying alieny sound, then when you move over the main grid it shows a HUD like representation of your current design:

hover-over-plus-design

And it runs at a pretty reasonable framerate too (my biggest concern with all this hand drawing – super easy to screw that up with bad code).

Next up is to actually place that mini image onto the grid at the location, when the user clicks. Plus to do the regularly ticked update of the entire grid pattern. Now doing that efficiently will be interesting.

So I’ve got the base algorithm calculating. It’s not super great, speedwise, but it’s ok. Major issue is I have a ferocious memory leak. Garbage collection isn’t freeing the arrays up, I suspect. However, it’s all working quite well other than that. Currently looks like this:

random-start

Note the memory – top right. It should be about 30-50M tops. It was going up about 20M a second. Oops. So no, I’m not going to make this live JUST yet. Not until I find+fix that.

Aha! Ok, I have it at a nice steady 5 updates a second, and rock solid at 26M of memory (about normal). Fixed all the memory issues. Performance isn’t super great, but now I can add some neat features to the base system. Awesome.

Right. I have now spent WAY too damn long on this (as a result I’m now running a day behind). It’s quite insane. However! This is frickin’ awesome.

I realised I was spending way too much time creating buttons for each new game, so I built a nice modular way to have generic (and reasonably good looking) buttons trivially. Like, in seconds per button. So that’s cool. I also added a splash screen (first time ever) so that should be easy to do for each game now too. Oh, and there are example patterns you can add with a single click.

Oh man, this whole thing is great fun. I love it!

play