I have written an implementation of the A* search algorithm. The problem is that the heuristic I'm currently using only works accurately on square grids. As my map is isometric, the heuristic doesn't take into account actual the layout of the map and thus, the distance between cells.
Update: After extensive logging and analysis (read as spending lots of time trying to figure out a banality), I have come to the conclusion that my current heuristic works quite well, with one little exception: the end result is reversed for real straight and diagonal movement.
inline int Pathfinder::calculateDistanceEstimate(const CellCoord& coord) const
{
int diagonal = std::min(abs(coord.x-goal->position.x), abs(coord.y-goal->position.y));
int straight = (abs(coord.x-goal->position.x) + abs(coord.y-goal->position.y));
return 14 * diagonal + 10 * (straight - 2 * diagonal);
}
This means that a straight move, which really costs sqrt(2)
times more than a diagonal move on an isometric map, is calculated to be the that of a diagonal one. The question is: how can I modify my current heuristic so it will produce correct results for an isometric layout? Simply replacing diagonal
with straight
and vice versa will not work.