From 38725d72672b6ee34b6f2fb27065f942cf37e9fc Mon Sep 17 00:00:00 2001 From: Ellpeck Date: Wed, 8 Apr 2020 17:45:12 +0200 Subject: [PATCH] use infinite cost for astar --- MLEM/Pathfinding/AStar.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/MLEM/Pathfinding/AStar.cs b/MLEM/Pathfinding/AStar.cs index 53e5a70..59cfc4c 100644 --- a/MLEM/Pathfinding/AStar.cs +++ b/MLEM/Pathfinding/AStar.cs @@ -6,6 +6,7 @@ using System.Threading.Tasks; namespace MLEM.Pathfinding { public abstract class AStar { + public static readonly float InfiniteCost = float.PositiveInfinity; public readonly T[] AllDirections; public readonly T[] AdjacentDirections; public GetCost DefaultCostFunction; @@ -65,7 +66,7 @@ namespace MLEM.Pathfinding { foreach (var dir in dirsUsed) { var neighborPos = this.AddPositions(current.Pos, dir); var cost = getCost(current.Pos, neighborPos); - if (cost < float.MaxValue) { + if (!float.IsInfinity(cost) && cost < float.MaxValue) { var neighbor = new PathPoint(neighborPos, this.GetManhattanDistance(neighborPos, goal), current, cost, defCost); if (!closed.Contains(neighbor)) { var alreadyIndex = open.IndexOf(neighbor);