# Path finding: avoid being surrounded by enemies

I'm building a bot that plays a simplified version of Pac-Man. The bot does a pretty good job, but sometimes it chooses a path where it ends up surrounded by enemies.

Here is an example:

XXXXXXXXXXXXXXXX         XXXXXXXXXXXXXXXX         Legend:
xxxxO1   E1              xxxxPE1
XXXX XXXXXXXXXXX    ---> XXXX XXXXXXXXXXX         O Objective
E2   P        O2            E2 E3      O2         P Player
XXXXXXXX XXXXXXX         XXXXXXXX XXXXXXX         E Enemy
XXXXXXXX XXXXXXX         XXXXXXXX XXXXXXX         X Wall
XXXXXXXXE3XXXXXX         XXXXXXXX XXXXXXX         x Wall

In this situation, my bot is at the point of no return. It will choose to move
to and pick up objective one (O1), as it is the closest objective in sight,
and in theory is still a safe path. However, in doing so, enemies will surround
him and he will die. (Map on the right).


I'm trying to come up with ideas on how to make my bot avoid that path, and go for a safer one. The bot should determine if completing the current path (to O1) is a good idea or not, in advance, and make a decision.

How would I go about this? I'm using a simple A* for path finding over a grid.

• I think one easy way to handle this is to change up the AI between different enemies (this is what pacman does). One enemy can follow the optimal path, the other can take the second best/ higher cost paths, other enemies could move randomly, etc – CobaltHex Feb 3 '17 at 22:48
• Perhaps you could show an example via screenshots of what you already have? ASCII Character diagrams look so bad. – Gnemlock Feb 4 '17 at 0:05
• Maybe I didn't explain myself correctly, I'm not developing a game, I'm programming a bot to play a Pacman-like game. I'm trying to make the player character not put himself in the situation I just described. Obviously i cannot change the enemy behavior – GenderBender Feb 4 '17 at 1:50