Implementing a low-cost Astar algorithm

First of all, I am very proud that I finally implemented the A*-algorithm. I took me quite a while to understand it. Of course – once you understood, it seems so simple. But the way to get there is definitely not. And I am saying this with a programmer background (but completely different industry) of over 14 years.

But what about huge maps?

But what about huge maps? For example, my world is at least 600 x 400 tiles large. This means we have 240K tiles and each request for a path would mean to calculate all possible paths, which are millions… I guess.

But I used a trick here. Since my character won’t move through the whole map at once, I just took all possible/reachable tiles from the current position which aren’t a lot. Lets say, you can move 2 fields per turn. If you reduce the map to 20 x 20 fields, we only have 400 tiles. Far better than 240K. With this solution, I was able to get quick movement paths.

Even on a huge map, we can get the path really quickly.

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *