astar: diagonal movement cost makes path end in loop not at goal
i'm somewhat stumped here.
i've been working on the bbox astar for Caveman. its regular astar, but you can pass it a bbox radius for determining if a tile is impassable. if any tile in a bbox radius around a given tile is impassable, the tile is considered impassable. this effectively creates a buffer of depth bbox_radius around all obstacles on the map. this keeps entities from clipping corners when moving diagonally around the corner of an obstacle. it also means you can use a single astar map for entities of different sizes! with a bbox radius of zero, it becomes normal astar.
so far everything has worked fine. limiting it to horizontal and vertical movement, i have perfect astar behavior. even with bboxes (it would seem - at least so far).
but at first, diagonal movement had a cost of 1, just like horizontal and vertical movement. as a result, the path would sometimes go out diagonally then come back in diagonally instead of going straight. my estimate to goal heuristic was bbox distance in tiles.
since the code used ints for cost, i decided to use a form of "fixed point", and make horiz and vert cost 10, diagonal 14, and make the heuristic bbox dist * 10.
but when i do this, the path will sometimes go part way, then end in a loop with the next node (the parent) pointing to the previous node. IE node 6's parent is node 7, and 7's parent is 6!
so on a path of length 10, it might get as far as node 7, then think that node 6 is the next node. when you extract the path by chasing the parents, it jumps back and forth between nodes 6 and 7 until you exceed MAX_PATH_LENGTH for an entity (currently set to 10000).
i thought the bbox_dist*10 heuristic might be overestimating the distance to goal, so i tried replacing the heuristic with true 2d distance * 10 converted to an int, but no difference.
i changed it back to cost =1 for everything and it works- even with the new true 2d distance heuristic, but the paths may be diagonal not straight. then i changed it back to cost = 10 or 14, and now it loops again, instead of reaching the goal. so its definitely the change in cost values that's causing the problem - somehow.
i guess using floats for cost is the next step.
anyone ever run into this kind of bug? i'm obviously doing something wrong. just haven't figured out what yet.
changing the heuristic to true diagonal distance (i forget the proper name) should only tighten the search area....