Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tune the A* land distance cost heuristic to handle railroads better #568

Open
wants to merge 1 commit into
base: Development
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion C7Engine/AI/Pathing/PathingAlgorithmChooser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,17 @@ namespace C7Engine.Pathing {
*/
public class PathingAlgorithmChooser {
private static PathingAlgorithm landAlgorithm = new AStarAlgorithm(new WalkerOnLand(), (Tile from, Tile to) => {
return from.distanceTo(to);
// HACK: for land-based movement we have to deal with railroads,
// which have zero movement cost. If our heuristic is too strong it
// will result in units taking a direct path between points A and B,
// even if a more indirect path could be taken entirely by railroad.
// To avoid this problem we scale our heuristic function down by a
// constant (arbitraily chosen to work well in practice) so that a
// typical tile movement cost (around 1/3 to 3, depending on roads
// and terrain) dwarfs the heuristic. The heuristic is still enough
// to point the search in the proper direction, and since it is
// still an underestimate in most cases, it works properly.
return from.distanceTo(to) / 100.0;
});
private static PathingAlgorithm waterAlgorithm = new AStarAlgorithm(new WalkerOnWater(), (Tile from, Tile to) => {
return from.distanceTo(to);
Expand Down