3
\$\begingroup\$

I am working on a few different AIs for a tile-based game. I'm trying to figure out one where that tries to keep a certain distance from the player. So if distance becomes small, move away.

The whole game is in a pretty small are so it can't just forever move away. The movement is 4 directional.

How do I make the AI keep going at a distance, and once caught in a corner or close to a side of the room, to ignore the rule and just try to go around the player to the other side of the room?

\$\endgroup\$
3
\$\begingroup\$

There is an algorithm that adds this in automatically. Instead of merely moving away from the player, each AI will target the closest tile that is "out of range" of the player, I'll use 4 tiles. In the case that the AI is running from the player in an open area, it will choose to just run. In the case of a corridor, the AI "knows" it would be risky to slip by a player and instead chooses to keep progressing the other direction. Finally, in the case of a cornering we are left with the closest tile "out of range" to the player being behind the player.

the safe tiles (white) are behind the player

\$\endgroup\$
  • \$\begingroup\$ Good idea. However, this might cause the agent to move right through the threat it is supposed to avoid. The question said "ignore the rule", so this answer is correct, but I think it would be better when it would choose a path which maximizes the distance to the threat. This could be done by adding an additional weight to the cost of tiles close to the threat. \$\endgroup\$ – Philipp Jun 9 '15 at 15:06
  • \$\begingroup\$ @Philipp you are correct. This algorithm, by itself, is definitely not the best algorithm to keep the AI from the player. A better algorithm would prevent the AI from entering dead ends in the first place, however, that would most likely bring the difficulty up a bit for the player. \$\endgroup\$ – newton1212 Jun 9 '15 at 15:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.