# AI for simple Bomberman game

This topic is 2426 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

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.

 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?

##### Share on other sites
You could add weights to potential bomb able tiles. I imagine that there are number of equally good options to place a bomb, and weighting the options would improve the decision making. You could weight dead-ends low, so the bot would be less inclined to bomb them. You could also adjust weights based on proximity to the player, so the bot would behave differently if danger is nearby.

##### Share on other sites
You could try one or more of the following:

1) Check the distance of the player to the bot. If the player is too close to the bot, the bot should avoid placing bombs and focus on running away.
2) Use the pathfinding algorithm (A*). If there isn't a path of escape to safety, don't put the bomb. If a path leads to a dead end, the bot should avoid it.
3) Make the map bot-friendly. Add hidden triggers or location markers on the map to make it an ideal bomb site.

##### Share on other sites

3) Make the map bot-friendly. Add hidden triggers or location markers on the map to make it an ideal bomb site.

Ha! Sneaky, I never thought of that.

1. 1
Rutin
32
2. 2
3. 3
4. 4
5. 5

• 13
• 9
• 9
• 9
• 14
• ### Forum Statistics

• Total Topics
633324
• Total Posts
3011363
• ### Who's Online (See full list)

There are no registered users currently online

×