Commits

Robin Harper committed 47035ef

modified the grid search return to return an empty collection if no path was found

  • Participants
  • Parent commits 8b8706c

Comments (0)

Files changed (5)

AstarPath/AstarPathfinder.cs

         private const double Alpha = 0.4999;
         private const double DefaultCost = 1.0;
         private const int MaxEstimatedPathLength = 1500;
-        private readonly int DirectionalMove = 1;
+        private readonly int _directionalMove = 1;
         private const double Nudge = DefaultCost / MaxEstimatedPathLength;
         public readonly Grid Grid;
 
             switch (type)
             {
                 case PathfinderUtilities.PathfinderType.AdvancedManhattan:
-                    DirectionalMove = 4;
+                    _directionalMove = 4;
                     break;
                 case PathfinderUtilities.PathfinderType.Euclidean:
-                    DirectionalMove = 8;
+                    _directionalMove = 8;
                     break;
                 default:
-                    DirectionalMove = 1;
+                    _directionalMove = 1;
                     break;
             }
         }
                         opened.Clear();
                         break;
                     }
-                    else if (opened.Count >= MaxEstimatedPathLength)
+                    if (opened.Count >= MaxEstimatedPathLength)
                     {
                         opened.Clear();
                         closed.Clear();
                         break;
                     }
-                    else
+                    var adjacentNodes = PathfinderUtilities.FindAdjacentNodes(
+                        Grid,
+                        parent,
+                        CurrentPathfinderType);
+
+                    adjacentNodes = UpdateHeuristics(adjacentNodes, parent, start, goal);
+
+                    if (adjacentNodes.Count <= 0) continue;
+
+                    foreach (var node in adjacentNodes)
                     {
-                        var adjacentNodes = PathfinderUtilities.FindAdjacentNodes(
-                            Grid,
-                            parent,
-                            CurrentPathfinderType);
+                        var closedXList = closed.FindAll(t => t.X == node.X);
+                        var onClosed = closedXList.Find(t => t.Y == node.Y);
 
-                        adjacentNodes = UpdateHeuristics(adjacentNodes, parent, start, goal);
+                        //var openedXList = opened.FindAll(t => t.X == node.X);
+                        //var onOpened = openedXList.Find(t => t.Y == node.Y);
 
-                        if (adjacentNodes.Count > 0)
+                        if (onClosed == null)
                         {
-                            foreach (var node in adjacentNodes)
-                            {
-                                var closedXList = closed.FindAll(t => t.X == node.X);
-                                var onClosed = closedXList.Find(t => t.Y == node.Y);
-
-                                var openedXList = opened.FindAll(t => t.X == node.X);
-                                var onOpened = openedXList.Find(t => t.Y == node.Y);
-
-                                if (onClosed == null)
-                                {
-                                    opened.Add(node);
-                                }
-                            }
+                            opened.Add(node);
                         }
                     }
                 }
 
-                return PathToStart(goal);
+                return (closed.Count > 0) ? PathToStart(goal) : new List<GridNode>();
             }
-            else
-            {
-                throw new ArgumentNullException("start and/or goal could not be found in the current grid.", new Exception());
-            }
+
+            throw new ArgumentNullException("start and/or goal could not be found in the current grid.", new Exception());
         }
 
         /// <summary>
         /// <returns></returns>
         private double CalculateHWithAdvancedManhattan(GridNode neighbor, GridNode parent, GridNode start, GridNode goal)
         {
-            var h = (DefaultCost * DirectionalMove) * Math.Max(Math.Abs(neighbor.Center.x - goal.Center.x), Math.Abs(neighbor.Center.y - goal.Center.y));
+            var h = (DefaultCost * _directionalMove) * Math.Max(Math.Abs(neighbor.Center.x - goal.Center.x), Math.Abs(neighbor.Center.y - goal.Center.y));
             return CalculateSimpleNudge(h);
         }
 

AstarPath/Properties/AssemblyInfo.cs

 // You can specify all the values or you can default the Build and Revision Numbers 
 // by using the '*' as shown below:
 // [assembly: AssemblyVersion("1.0.*")]
-[assembly: AssemblyVersion("1.2010.1230.17")]
-[assembly: AssemblyFileVersion("1.2010.1230.17")]
+[assembly: AssemblyVersion("1.2010.1230.19")]
+[assembly: AssemblyFileVersion("1.2010.1230.19")]

AstarPath/bin/Debug/AstarPath.dll

Binary file modified.

PathTester/Properties/AssemblyInfo.cs

 // You can specify all the values or you can default the Build and Revision Numbers 
 // by using the '*' as shown below:
 // [assembly: AssemblyVersion("1.0.*")]
-[assembly: AssemblyVersion("1.2010.1230.8")]
-[assembly: AssemblyFileVersion("1.2010.1230.8")]
+[assembly: AssemblyVersion("1.2010.1230.9")]
+[assembly: AssemblyFileVersion("1.2010.1230.9")]

PathTester/bin/Debug/AstarPath.dll

Binary file modified.