-
Notifications
You must be signed in to change notification settings - Fork 18
Heuristic Weights
Benjamin Sommerfeld edited this page Mar 6, 2025
·
2 revisions
-
What it is: A class that defines the weights used in the A* heuristic function. These weights determine how the algorithm prioritizes different factors when searching for a path.
-
Why it's important: It allows you to fine-tune the characteristics of the paths found. Do you want the shortest path? The smoothest path? A path that avoids height changes?
HeuristicWeights
controls this. -
How to use it:
- Use the
create()
method to create a newHeuristicWeights
instance with your desired weights. - Use the predefined constants (
NATURAL_PATH_WEIGHTS
,DIRECT_PATH_WEIGHTS
) as starting points or for common scenarios.
// For natural-looking paths: HeuristicWeights naturalWeights = HeuristicWeights.NATURAL_PATH_WEIGHTS; // For the most direct path: HeuristicWeights directWeights = HeuristicWeights.DIRECT_PATH_WEIGHTS; // For custom weights: HeuristicWeights customWeights = HeuristicWeights.create( 0.4, // manhattanWeight (direct movement) 0.2, // octileWeight (diagonal movement) 0.3, // perpendicularWeight (smoothness) 0.1 // heightWeight (elevation changes) 0.5 // directionalPenatlyWeight (stay on track) );
Understanding the Weights:
-
manhattanWeight
: Higher values favor grid-like, axis-aligned movement. -
octileWeight
: Higher values encourage diagonal movement. -
perpendicularWeight
: Higher values result in smoother paths by penalizing deviations from a straight line to the target. -
heightWeight
: Higher values make the algorithm more sensitive to changes in elevation (useful for terrain).
- Use the