Question

I'm currently dabbling in Java AI programming, and trying an AI challenge. In the challenge, my AI is given 2 seconds to respond to the new game state. If these two seconds are exceeded without producing a response, my AI forfeits. The game consists of a grid with goals and enemies, each enemy being an independent AI generated by the game. I have implemented a standard A* to find the nearest available goal.

I would like my A* algorithm to increase the cost of squares near an enemy that could potentially prove dangerous, thus avoiding dangerous paths. I am considering a two-dimensional array containing the estimated loss of health for each square, limited to calculating within ~2 squares of each enemy (~5x5). Each turn, for each enemy this array would have a 5x5 square set to 0 and recalculated.

Assuming I write code that only does what it must and moves on... Will a two dimensional array of between 20x20 and 100x100 elements significantly effect execution time? Is a two dimensional array of estimated threat per square a good method of calculating cost in an A* algorithm so as to avoid enemies?

UPDATE: I got it working absolutely perfectly. The cost function I used:

For each enemy
    Calculate manhattan distance
    If 0 or 1, cost += absolute(enemy health - health) / 5
    Else if 2, cost += absolute(enemy heath - health) / 10
    Else cost += 0

Using it, I saw some really impressive pathfinding and moves; the bot would often take calculated risks where there were no other moves to get to a goal, but basically avoided enemies otherwise. I was thoroughly impressed with how insignificant the performance cost was of adding the heuristic. It's not a perfect solution for the game, but it showed me how robust A* can be.

A* is generally used for pathfinding, but I'm going to modify it for the purpose of a game state lookahead. I'm pretty sure that turns it into a minimax algorithm.

Was it helpful?

Solution

If you are only calculating the content of your array once and the calculation for each cell is something simple like checking a few adjacent cells for enemies then a 100x100 array is no work at all relative to your time constraints.

Given the information in your post it sounds like a good idea to me.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top