Simple Enemy AI
wiseguy

Hey folks.

I am making basically a clone of the old Apple game Lode Runner. I did this once before a long long time ago in QBasic, but for some reason that code has just disappeared I'm dumb!. Anyway my question is this: what would you suggest would be the best way to control the enemies in the game. My original take on how the game handled it was to check the position of the enemy in relation to the position of the player. If the player is above or below the enemy, the enemy will move up or down if they can. If however, the player is on the same level as the enemy, or the player is above or below and the enemy cannot move up or down, then the enemy will move left or right. My main goal is to recreate the best I can the actual behavior of the enemies in the original game, because that's part of what made the game so fun and challenging.

Anyway, I did a lot of searching on AI and on Lode Runner and can't really find anything that talks about something as simple as what I want, so I figured I'd make a post and see what everyone else said.

thanks,

WG

kentl

Well what you had sounds good, I would guess that you have played Lodeunner a lot and analyzed the behavior of the enemies? (And that you base your previous method on these studies.)

Michael Faerber

You could check out the KGoldRunner source code.

If you have Subversion, you can check it out easily by typing: svn co http://websvn.kde.org/tags/kgoldrunner/1.0.5/kdegames/kgoldrunner/

Tobias Dammers

From your description, I guess the following algorithm should work:
- calculate the relative x and y distances to the player as (dx; dy).
- if (abs(dx) > abs(dy)), try to move in x direction; left if (dx < 0), right if (dx > 0)
- if you can't move in x direction, or abs(dy) is larger, try the same in y direction.

Shouldn't be that hard really.

wiseguy

thanks everybody,

that's basically what I was planning to do, I just was mulling over in my mind exactly how the original game did it, because it'd be nice to do it the same way. After playing with the levels a bit more I think that that method is about as close as I'm gonna get without looking at someone else's source. I am gonna look at the kgoldrunner source, thanks a lot for the link michael, and thanks Tobias and Kent for your replies

Thread #553428. Printed from Allegro.cc