Saturday, March 24, 2007

AI question





This is the map of the labyrinth. The blue smiley is me, and the red stars are the enemy, chasing me. How do I programme an AI to not to stuck in the corner?

I die if I a red star touches me, and my goal is to survive as long as possible. (So in this scenario I have to go into the tube.)

It's nice to have maps, which shows, how far is a given tile in the game from the enemies. But when I want to enter that tube, I have to step over "an energy gate", I have to move closer to my enemies.

2 comments:

Rami said...

I am not even close to be an AI expert, but in these type of games I think you should keep the AI pretty simple (at least at first).

IIRC, old Boulderdash games had monsters that had preconfigured movement patterns (i.e "always turn right"). Pacman also has some pretty simple, but entertaining AI. You may find its description by googling.

If you are worried being stuck in the corners, build a peeking method / collision detection to see if the monster can move in certain direction, if not select another direction (turn 90 degrees, for example).

Then you can go little bit further: get the general direction of the player and move the monster to that direction. Assuming that the monster cannot move in diagonal directions, you have to choose the axis to move. Remember to update the target location.

Make it even harder: create a movement plan to the current coordinates of the user ( 3 squares left, 2 up,5 right etc..). Update the plan at times so that it'd look like the monster is following the player.

Make a collaborative AI: recognize "hot spots" of the map and coordinate the monsters so that they'll eventually drive the user into a dead-end.

And remember that you can always do what most AI's do: cheat. :)

sourcerror said...

Sorry that for not being here a while. Now I set up regular checking with site-delta.The point would be to avoid scripted behaviours. (Ideally something that can be proved to be optimal or not very bad. Or at least intuitive enough to feel, that it's good :))

Well, if I do make breadth-first searches from all the players, and select the tile when the enemy's branch and mine touch the last.