Square grid, turn base A.I.

I didn’t want it to seem like I was intruding on a thread and not giving any suggestions, so may I share an idea with you?

Keep in mind, there are many ways to approach the same problem in programming. What I’m going to share is just the easiest way I could think of right off the top of my brain.

I’m assuming you want to move the Rat (mouse) from tile to tile, while avoiding any tile that has something on it until the Rat reaches a goal? Correct?

What I would probably try first is “nested dictionaries.” I’m assuming you’re familiar with Python Dictionaries. I would write the “Path Finding” AI for this type of game as follows –


By markjacksonguy at 2012-03-07

Lets say the Rat is starting on block A. I would find the current key in my Dictionary, which is the current block the Rat is over (A), and then I would find the connected keys (which are all the blocks that sit around the block the Rat is on. E.g. B, C, D).

I would then check to see if anything is on any of the blocks around the block the Rat is on (by using a variable or something). Once I have determined all the free blocks (empty blocks), I would then perform a distance to point check using Vector Math on each free block to determine which distance is shortest. I would then move the Rat to the block that has the shortest distance; and then repeat the process until the Rat reaches goal.

Of course, if I had the time, I could write this code since it’s not that hard. I hope I at least gave you some ideas. :smiley:

In the RTS style game I’m making, my characters do not move by grid; they move freely, that’s why I would have to write something like the example above if I was going to use a grid base movement approach.

Update-------------------------
I thought about it a little more and the approach would be to use lists and a dictionaries together. Each block is a Key and the Value is a list containing the blocks around the current block the Rat is on. I almost want to take time out from my work and write a demo since it’s so simple.

The cool thing about this approach is the fact you’re not checking every possible path (that would be many); you are in fact performing movement checks block to block, at the same time finding the shortest path (if that’s what you desire).

Now I’m getting excited about grid base movement. :laughing: