Slick Forums
http://slick.ninjacave.com/forum/

[BUG] AStar is not finding the shortest Path at all
http://slick.ninjacave.com/forum/viewtopic.php?f=1&t=5337
Page 1 of 1

Author:  ben [ Thu Aug 02, 2012 8:07 am ]
Post subject:  [BUG] AStar is not finding the shortest Path at all

Hey,

i was wondering why movement via astar pathfinding of the slick library was so unexpected. while avoiding an obstacle, the mover object was always moving towards the obstacle directly before travelling around.

in the implementation of the astar, it calculates the "distance" just by the cost of the given TileBasedMap. As suggested, the map could return 1 for each tile. But doing this, the cost for travelling diagonal is equal to the cost for travelling horizontal or vertical. the problem is, u cant use another value for getCost in the TileBasedMap since u dont know, from which tile u came from outside the algorithm.

Quote:
// the cost to get to this node is cost the current plus the movement
// cost to reach this node. Note that the heursitic value is only used
// in the sorted open list
float nextStepCost = current.cost + getMovementCost(mover, current.x, current.y, xp, yp);


a quick solution to this bug could be to multiply the cost by square root of 2 for diagonal movement.

greetz Ben

Page 1 of 1 All times are UTC
Powered by phpBB® Forum Software © phpBB Group
http://www.phpbb.com/