diff --git a/AndroidTests/AndroidTests.csproj b/AndroidTests/AndroidTests.csproj index b069a2e..9c259f5 100644 --- a/AndroidTests/AndroidTests.csproj +++ b/AndroidTests/AndroidTests.csproj @@ -17,7 +17,7 @@ armeabi-v7a;x86 .m4a - v7.1 + v9.0 Android Properties\AndroidManifest.xml True @@ -105,8 +105,8 @@ - - + + diff --git a/Demos/PathfindingDemo.cs b/Demos/PathfindingDemo.cs index e52390b..770e6a2 100644 --- a/Demos/PathfindingDemo.cs +++ b/Demos/PathfindingDemo.cs @@ -48,7 +48,7 @@ namespace Demos { this.path = foundPath != null ? foundPath.ToList() : null; // print out some info - Console.WriteLine("Pathfinding took " + this.pathfinder.LastTriesNeeded + " tries"); + Console.WriteLine("Pathfinding took " + this.pathfinder.LastTriesNeeded + " tries and "+this.pathfinder.LastTimeNeeded.TotalSeconds+" seconds"); if (this.path == null) Console.WriteLine("Couldn't find a path, press the left mouse button to try again"); } diff --git a/MLEM/Pathfinding/AStar.cs b/MLEM/Pathfinding/AStar.cs index e054006..529a169 100644 --- a/MLEM/Pathfinding/AStar.cs +++ b/MLEM/Pathfinding/AStar.cs @@ -1,3 +1,4 @@ +using System; using System.Collections.Generic; namespace MLEM.Pathfinding { @@ -10,6 +11,7 @@ namespace MLEM.Pathfinding { public int DefaultMaxTries; public bool DefaultAllowDiagonals; public int LastTriesNeeded { get; private set; } + public TimeSpan LastTimeNeeded { get; private set; } protected AStar(T[] allDirections, T[] adjacentDirections, GetCost defaultCostFunction, bool defaultAllowDiagonals, float defaultCost = 1, int defaultMaxTries = 10000) { this.AllDirections = allDirections; @@ -21,6 +23,8 @@ namespace MLEM.Pathfinding { } public Stack FindPath(T start, T goal, GetCost costFunction = null, float? defaultCost = null, int? maxTries = null, bool? allowDiagonals = null) { + var startTime = DateTime.UtcNow; + var getCost = costFunction ?? this.DefaultCostFunction; var diags = allowDiagonals ?? this.DefaultAllowDiagonals; var tries = maxTries ?? this.DefaultMaxTries; @@ -31,6 +35,7 @@ namespace MLEM.Pathfinding { open.Add(new PathPoint(start, this.GetManhattanDistance(start, goal), null, 0, defCost)); var count = 0; + Stack ret = null; while (open.Count > 0) { PathPoint current = null; var lowestF = float.MaxValue; @@ -46,8 +51,8 @@ namespace MLEM.Pathfinding { closed.Add(current); if (current.Pos.Equals(goal)) { - this.LastTriesNeeded = count; - return CompilePath(current); + ret = CompilePath(current); + break; } var dirsUsed = diags ? this.AllDirections : this.AdjacentDirections; @@ -75,8 +80,10 @@ namespace MLEM.Pathfinding { if (count >= tries) break; } + this.LastTriesNeeded = count; - return null; + this.LastTimeNeeded = DateTime.UtcNow - startTime; + return ret; } protected abstract T AddPositions(T first, T second);