mirror of
https://github.com/Ellpeck/MLEM.git
synced 2024-11-26 14:38:34 +01:00
use infinite cost for astar
This commit is contained in:
parent
f4bec17448
commit
38725d7267
1 changed files with 2 additions and 1 deletions
|
@ -6,6 +6,7 @@ using System.Threading.Tasks;
|
||||||
namespace MLEM.Pathfinding {
|
namespace MLEM.Pathfinding {
|
||||||
public abstract class AStar<T> {
|
public abstract class AStar<T> {
|
||||||
|
|
||||||
|
public static readonly float InfiniteCost = float.PositiveInfinity;
|
||||||
public readonly T[] AllDirections;
|
public readonly T[] AllDirections;
|
||||||
public readonly T[] AdjacentDirections;
|
public readonly T[] AdjacentDirections;
|
||||||
public GetCost DefaultCostFunction;
|
public GetCost DefaultCostFunction;
|
||||||
|
@ -65,7 +66,7 @@ namespace MLEM.Pathfinding {
|
||||||
foreach (var dir in dirsUsed) {
|
foreach (var dir in dirsUsed) {
|
||||||
var neighborPos = this.AddPositions(current.Pos, dir);
|
var neighborPos = this.AddPositions(current.Pos, dir);
|
||||||
var cost = getCost(current.Pos, neighborPos);
|
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);
|
var neighbor = new PathPoint<T>(neighborPos, this.GetManhattanDistance(neighborPos, goal), current, cost, defCost);
|
||||||
if (!closed.Contains(neighbor)) {
|
if (!closed.Contains(neighbor)) {
|
||||||
var alreadyIndex = open.IndexOf(neighbor);
|
var alreadyIndex = open.IndexOf(neighbor);
|
||||||
|
|
Loading…
Reference in a new issue