In a shoot 'em up game I want to have AI bots that can take up the player's slot and play the game (such as in this video). However they should come with different flavors (varying competency and playstyles). The problem is the related maths and AI programming are very new to me. Where should I start?

Suggestions for existing sample code/libraries/tools, reading materials or advice on architecture/algorithms are all welcome. Thanks in advance!


2 Answers 2


Let's assume you have to write something yourself. I don't know of any middleware targeted towards 2D side-scrollers but someone may correct me.

I haven't done anything like this before, but it's an interesting intellectual exercise so here's my first thoughts. For simplicity I've talked about only avoiding bullets, not shooting at enemies.

Most side-scrollers are deterministic as to when enemies come on screen, their on-screen path and the bullets they produce. Players tend to learn how to play a level through muscle memory, which is strengthened by repetition, but at an immediate level they're reacting to what's on-screen now.

Of course we could just record human input and replay it (with several different recordings for different play-styles), but that's extremely sensitive to level design changes.

A simple steering-behaviour system could keep the AI away from bullets, maybe peeking at the type of bullet to figure out its future positions for predictive avoidance. For lots of bullets on small systems this may become expensive.

However with this approach the AI could very quickly get stuck in a dead end, with no chance of escape. So we need something above the on-screen reactions, something to replicate the muscle-memory humans use.

If we could get our AI to repeatedly play each level, recording some kind of data as it goes, it could pipe this data into the steering behaviours to avoid dead-ends. Each play-through improves the data and lets our AI make better decisions. But what form does this data take?

One immediate idea is a heat or threat map covering the whole screen, for every frame of the level. Sort of a threat movie. You could imagine it as a movie of the level, with each pixel coloured as to its danger to the AI. Spaces completely enveloped by bullets would be coloured in as very dangerous. Then you could do some post-processing to bleed danger back though time, so the AI could see the problem coming before the area is enveloped.

With this data, you could replace the steering behaviours with a kind of 4-dimensional flood-fill that tried to find the largest safest place on the screen, with each step looking at the future frames to work out a safe path.

If a pixel for every frame for every level sounds data-intensive, you could make the pixels quite blocky - I imagine you don't need resolution below the size of the hitbox of the AI's avatar, and could probably get away with blocks a bit bigger than that. You could also record only two or three frames a second to further reduce data size.

The personalities come from the real-time processing of the threat movie. With steering behaviours, you could have scardy-cat AI that prefer large distances to any threat, or bravado AI that look for pickups despite the danger. Slow AI, that flood-fill the threat movie assuming a lower top speed, which may find different routes to a faster AI, etc.

If it sounds like a lot of work, that's because it probably is, but it also sounds like a lot of fun. :)

  • 2
    \$\begingroup\$ Just a technical point: it wouldn't be a 4-dimensional flood-fill. This is a sidescroller, so it's only 3-dimensional (x, y and t) and it may even help to think of it as such. Each frame is a layer in a cube or some similar concept. \$\endgroup\$ Commented Sep 29, 2011 at 13:38
  • \$\begingroup\$ @Matthew Scharley Ah very good point. It's 3d. The cube metaphor is very good. \$\endgroup\$
    – tenpn
    Commented Sep 29, 2011 at 14:12

I assume these are AI bots that would be utilizing a game/engine you wrote. If not, then you would need to consult specific material related to the engine you use.

I picked up a copy of Game Coding Complete and was able to implement the various systems that are key in having working AI. It did a great job of explaining that the AI used to control computer players is simply an extension of the class used to control your own player. It also showed how to implement an event handler.

No, it won't detail an award winning AI language but it shows you what you need to create one. As far as libraries, I am not sure about them but again if you are just learning, try and shy away from libraries controlling things you are really interested in. For example, I love graphics rendering so I used no libraries at all when learning. Sound control is not something I am too interested in so I ended up going with a third party library.

Finally, Stanford is hosting an online AI class. I am not sure if you can still enroll but if you can it would definitely be worth your time. http://www.ai-class.com/

Even if enrollment is closed it may still be worth your time to e-mail the professor and let him know how eager you are to learn. This would most likely not be a class about the systems of AI but more about how to create AI that is lifelike and convincing.

Hope my answer helped!


  • 1
    \$\begingroup\$ "This would most likely not be a class about the systems of AI but more about how to create AI that is lifelike and convincing." It's the opposite, actually. Traditional AI systems don't attempt to emulate real life - they just use and study algorithms that are suited to the decision-making process. Some are inspired by biology but most are not. \$\endgroup\$
    – Kylotan
    Commented Sep 29, 2011 at 10:03

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .