Space Invaders Enterprise Edition

Wednesday, February 17th, 2010

The whole notion of Space Invaders Enterprise Edition is jarring, but it’s meant to demonstrate a particular technical approach to solving business IT problems:

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!

The “business” rules are written for the questionably named Drools engine:

rule "Reverse aliens if one reachs the edge of the screen"
when
$alien : AlienEntity()
exists (AlienEntity(x <> 750))
then
$alien.setHorizontalMovement(-$alien.getHorizontalMovement());
$alien.setY($alien.getY() + 10);
end

rule "Process bullets hitting aliens"
when
$shot : ShotEntity()
$alien : AlienEntity(this != $shot, eval($shot.collidesWith($alien)))
$otherAlien : AlienEntity()
then
game.getEntities().remove($shot);
game.getEntities().remove($alien);
$otherAlien.setHorizontalMovement($otherAlien.getHorizontalMovement() * 1.04);
end

rule "End the game when all aliens are killed"
salience 1
when
not AlienEntity()
exists ShipEntity()
then
game.notifyWin();
game.getEntities().clear();
end

rule "End the game when an alien reaches the bottom"
when
exists AlienEntity(y > 570)
then
game.notifyDeath();
game.getEntities().clear();
end

I’m sure if we just write code in an English-like language, non-technical business experts will be able to write their own business rules, right?

Leave a Reply