Imagine a very simple shoot-em-up, something we all know:
You're the player (green). Your movement is restricted to the
X axis. Our enemy (or enemies) is at the top of the screen, his movement is also restricted to the
The player fires bullets (yellow) at the enemy.
I'd like to implement an A.I. for the enemy that should be really good at avoiding the players bullets. My first idea was to divide the screen into discrete sections and assign weights to them:
There are two weights: The "bullet-weight" (grey) is the danger imposed by a bullet. The closer the bullet is to the enemy, the higher the "bullet-weight" (
0..1, where 1 is highest danger). Lanes without a bullet have a weight of 0. The second weight is the "distance-weight" (lime-green). For every lane I add
0.2 movement cost (this value is kinda arbitrary now and could be tweaked).
Then I simply add the weights (white) and go to the lane with the lowest weight (red). But this approach has an obvious flaw, because it can easily miss local minima as the optimal place to go would be simply between two incoming bullets (as denoted with the white arrow).
So here's what I'm looking for:
- Should find a way through bullet-storm, even when there's no place that doesn't impose a threat of a bullet.
- Enemy can reliably dodge bullets by picking an optimal (or almost optimal) solution.
- Algorithm should be able to factor in bullet movement speed (as they might move with different velocities).
- Ways to tweak the algorithm so that different levels of difficulty can be applied (dumb to super-intelligent enemies).
- Algorithm should allow different goals, as the enemy doesn't only want to evade bullets, he should also be able to shoot the player. That means that positions where the enemy can fire at the player should be preferred when dodging bullets.
So how would you tackle this? Contrary to other games of this genre, I'd like to have only a few, but very "skilled" enemies instead of masses of dumb enemies.