I'm trying to implement an AI algorithm for Bomberman. Currently I have a working but not very smart rudimentary implementation (the current AI is overzealous in placing bombs).
This is the first AI I've ever tried implementing and I'm a bit stuck. The more sophisticated algorithms I have in mind (the ones that I expect to make better decisions) are too convoluted to be good solutions.
What general tips do you have for implementing a Bomberman AI? Are there radically different approaches for making the bot either more defensive or offensive?
Edit: Current algorithm
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 a cell that is found to the left or right of this path), 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?
One of the problems with this algorithm is that it tends to leave the bot with very few (frequently just one) safe cells on which it can stand. This is because the bot leaves a trail of bombs behind it, as long as it doesn't kill itself.
However, leaving a trail of bombs behind leaves few places where you can hide. If one of the other players or bots decide to place a bomb somewhere near you, it often happens that you have no place to hide and you die.
I need a better way to decide when to place bombs.