1
0
Fork 0
mirror of https://github.com/Ellpeck/MLEM.git synced 2024-12-25 17:59:24 +01:00

use infinite cost for astar

This commit is contained in:
Ellpeck 2020-04-08 17:45:12 +02:00
parent f4bec17448
commit 38725d7267

View file

@ -6,6 +6,7 @@ using System.Threading.Tasks;
namespace MLEM.Pathfinding {
public abstract class AStar<T> {
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<T>(neighborPos, this.GetManhattanDistance(neighborPos, goal), current, cost, defCost);
if (!closed.Contains(neighbor)) {
var alreadyIndex = open.IndexOf(neighbor);