I’m pleased to announce that I’ve released Space Invaders Enterprise Edition (Java, cross-platform executable, ~9mbs due to Drools dependencies, source code here), the first prototype program from my newly announced research direction, Zenet.
Space Invaders EE is a clone of code of Space Invaders from Coke and Code, which is a Java tutorial for how to create games. However, it’s not the game itself we’re interested in (although it is pretty fun, and big thanks to Kevin for releasing his code as open-source!)
The magic of Space Invaders Enterprise Edition is actually under the hood. I’ve separated out the game logic from the Java source into a file parsed by a rules engine. This means we can easily view the game design, without it getting muddled with too much implementation code.
Rule engines are commonly used in enterprise-level companies to decide things like how much your car insurance premium will be. Let’s start using this for something more fun!
A description of how it all works is after the jump.
Here’s a snippet from some of the rules file, written for the Drools rule engine:
Hopefully, this is sort of readable, even to the non-programmers out there. Let’s start with the first rule, which reverses the aliens. The aliens, by default, keep moving every tick a certain amount horizontally. The rule says “find me an alien, where there is an alien somewhere in the game that has hit the edge of the screen. Then swap that alien’s movement direction and move it down by 10 pixels.” The rule repeats for all the aliens in the game, eventually being fired on every one and reversing the direction for all of them.
To help illustrate the value of this, compare the “Process bullets hitting aliens” code, to the original:
Ouch! Not too readable! Unfortunately, such code is common and unavoidable in game programming. What’s happening here? Well, the code has two loops. The first loop gets all the objects in the game. The second loop does the same. When the first element of the first loop is tried, it then tests that object against all the other objects in the game to see if they have collided. Eventually, all the objects in the game will be tested against each other. If they do collide, there’s some code elsewhere to decide what to do (a bullet and an alien colliding results in them both being removed from the game).
This is exactly the same behavior at the user-visible level (thanks Andrew for the clarification) as the collision code in the rule file gives. I much prefer the rule engine implementation, and I hope you do too. Double loops are hard enough for programmers to understand, let alone game designers who we can’t assume are able to understand all the nuts and bolts of modern games programming (which is very difficult).
Space Invaders Enterprise Edition offers a different approach. By separating the game logic from the implementation, we have a game design specification that we can give to programmers and game designers, that we can read easily and be able to spot any bugs in it. Try spotting a bug in that double loop code!
I haven’t even begun to scratch the surface of the power of the Drools rule engine yet. That’s for another post, and what forms the basis of the Zenet project that I am working on. There’s more to come!
As with all my announced work, the code is open-sourced under the BSD license, so you can see how it works, modify it and re-release it without any limitation whatsoever. It’s all hosted at GitHub. It’s easy to build with Maven, and once you get going, try changing some of the rules, or adding new ones, and see how easy it really is.
About the author: Chris Lewis is a British PhD student researching the intersection of software engineering and video game development. Read more from this author