Pathfinding problems
August 11th 2011 -
Lately I have been working my small project (made just for fun), a hex-grid based strategy game. One of the biggest problems I’ve encountered was checking if unit has enough movement points left to move to a specific hex.
For two days I was trying to design an algorithm that would check if unit can go from hex A to hex B in real time – i.e when you move mouse over the battlefield. I’ve tried a lot of algorithms, recursive and non-recursive, I’ve searched the web. Still, nothing.
Until I’ve started up HoMM 2 (or, to be exact, FreeHeroes on my tablet), and… bingo! I understood that I should not try to find if unit can go from hex A to hex B. I should instead move the unit and see where it can go, and store that information. 15 minutes of coding later units moved on the battlefield as they should.
Tags: Games, HoMM, Programming