Fast AI for turn-based action game Space Grunts

Game designer Pascal Bestebroer of OrangePixel explains how Pac-man inspired him to make his turn-based game feel like an all-out-action-shooter.

Space Grunts is a fairly fast paced turn-based game, as you might have noticed when playing it, or seen in videos. Every time you take your turn, all monsters act pretty much within a second, finding their path towards you, and keeping the gameplay pace high.

How is this magic done so quickly? well it’s: PAC-MAN man!

I decided to use the fastest possible AI code that still gives a lot of variation for different monster types.  This is probably also the oldest code to do something like this, as it was used by Blinky, Inky, Pinky and Clyde, aka: the ghosts of Pac-man past.

In Pac-man you have these four different ghosts, and what these ghosts do is look at where the player is (grid-based) and decide to either target that exact grid location, a location or two in front-of the player, or a few locations behind or above the player.

Then it’s just a matter of checking if the ghost has to move horizontally to the right or horizontally to the left, or move vertically upwards or downwards. The priority of horizontal or vertical moves depends on the distance between the target and the ghost. It’s all very quick, very fast, and very smart.

screenshot01

In Space Grunts I add a few more things to the mix, so some monsters will only come towards you if you have your back turned to them, and then run away if you are just looking at them. Other monsters are targeting your exact spot, and others are checking which direction you are looking at and then target your next most likely spot on the map.

Since these are all very fast calculations to make, you can add only a few more things to all this logic. We can check if we have a lot of health, because if not we rather keep our distance and change our behavior according to our stats.

And finally we also add a “lazy” parameter to each monster, which is basically the willingness of a monster to actually attack you in a turn. Some monsters are less aggressive and will not move on every turn, other monsters are very aggressive and will keep moving every chance they get.

All these variations add to the tactical part of the game, once a player figures out who the aggressive monsters are, and who is most likely going to step away if you look into their direction, you can make your decisions on clearing a room based on the knowledge of how these creatures work. Or you can just try to run away.

Pascal Bestebroer
Pascal Bestebroerhttp://www.orangepixel.net
Orangepixel is a Dutch one-man game developer comprised of Pascal Bestebroer (Game design, code, graphics and sound effects).

Related articles