Original Post
I'm trying to code an AI for a simple Bomberman game. The game contain no power-ups, just (in)destructible walls, bombs, and players, and there's no limit on how many bombs you can place at any given time. I need to help on designing a decent algorithm for avoiding bombs.
My current algorithm goes something like this (pseudo-code):
1. Try to place a bomb and then find a cell that is safe from all the bombs, including the one that you just placed. To find that cell, iterate over the four directions; if you can find any safe divergent cell, and reach it in time (eg. if the direction is up or down, look for cell that diverge to the left or right), then it's safe to place a bomb and move in that direction.
2. If you can't find and safe divergent cells, try NOT placing a bomb and look again. This time you'll only need to look for a safe cell in only one direction (you don't have to diverge from it).
3. If you still can't find a safe cell, don't do anything.
This algorithm makes the bot very trigger-happy (it'll place bombs very frequently). It doesn't kill itself, but it does have a habit of making itself vulnerable by going into dead ends where it can be blocked and killed by the other players.
Do you have any suggestions on how I might improve this algorithm? Or maybe I should try something completely different?
My current algorithm goes something like this (pseudo-code):
1. Try to place a bomb and then find a cell that is safe from all the bombs, including the one that you just placed. To find that cell, iterate over the four directions; if you can find any safe divergent cell, and reach it in time (eg. if the direction is up or down, look for cell that diverge to the left or right), then it's safe to place a bomb and move in that direction.
2. If you can't find and safe divergent cells, try NOT placing a bomb and look again. This time you'll only need to look for a safe cell in only one direction (you don't have to diverge from it).
3. If you still can't find a safe cell, don't do anything.
for $(direction) in (up, down, left, right):
place bomb at current location
if (can find and reach divergent safe cell in current $(direction)):
bomb = true
move = $(direction)
return
for $(direction) in (up, down, left, right):
do not place bomb at current location
if (any safe cell in the current $(direction)):
bomb = false
move = $(direction)
return
else:
bomb = false
move = stay_put
This algorithm makes the bot very trigger-happy (it'll place bombs very frequently). It doesn't kill itself, but it does have a habit of making itself vulnerable by going into dead ends where it can be blocked and killed by the other players.
Do you have any suggestions on how I might improve this algorithm? Or maybe I should try something completely different?