]> Dogcows Code - chaz/carfire/blobdiff - CarFire/CarFire/CarFire/PathFinder.cs
git-svn-id: https://bd85.net/svn/cs3505_group@152 92bb83a3-7c8f-8a45-bc97-515c4e399668
[chaz/carfire] / CarFire / CarFire / CarFire / PathFinder.cs
index 91724384ab2ac4cccca98b2c830b66c0bff2c1e7..02c645cc8f8ed4c71e20705b96951a627acd15b4 100644 (file)
@@ -1,4 +1,8 @@
-using System;\r
+\r
+// Uncomment this to disable diagonal movemet.\r
+//#define ALLOW_DIAGONAL_MOVEMENT\r
+\r
+using System;\r
 using System.Collections.Generic;\r
 using System.Linq;\r
 using System.Text;\r
@@ -125,7 +129,7 @@ namespace CarFire
                     List<Point> list = new List<Point>();\r
 \r
                     cell = cell.Parent;\r
-                    while (cell.Point != start)\r
+                    while (cell != null && cell.Point != start)\r
                     {\r
                         list.Add(cell.Point);\r
                         cell = cell.Parent;\r
@@ -136,23 +140,24 @@ namespace CarFire
                 }\r
 \r
                 List<Point> neighbors = new List<Point>(8);\r
+                neighbors.Add(new Point(cell.Point.X, cell.Point.Y - 1));\r
+                neighbors.Add(new Point(cell.Point.X - 1, cell.Point.Y));\r
+                neighbors.Add(new Point(cell.Point.X + 1, cell.Point.Y));\r
+                neighbors.Add(new Point(cell.Point.X, cell.Point.Y + 1));\r
+#if ALLOW_DIAGONAL_MOVEMENT\r
                 neighbors.Add(new Point(cell.Point.X - 1, cell.Point.Y - 1));\r
-                neighbors.Add(new Point(cell.Point.X + 0, cell.Point.Y - 1));\r
                 neighbors.Add(new Point(cell.Point.X + 1, cell.Point.Y - 1));\r
-                neighbors.Add(new Point(cell.Point.X - 1, cell.Point.Y + 0));\r
-                neighbors.Add(new Point(cell.Point.X + 1, cell.Point.Y + 0));\r
                 neighbors.Add(new Point(cell.Point.X - 1, cell.Point.Y + 1));\r
-                neighbors.Add(new Point(cell.Point.X + 0, cell.Point.Y + 1));\r
                 neighbors.Add(new Point(cell.Point.X + 1, cell.Point.Y + 1));\r
+#endif\r
                 foreach (Point point in neighbors)\r
                 {\r
-                    Cell inQueue = mCells[point.X, point.Y];\r
-\r
                     if (0 <= point.X && point.X < mGridWidth && 0 <= point.Y && point.Y < mGridHeight &&\r
                         mGrid[point.X, point.Y])\r
                     {\r
                         int cost = cell.G + costFunction(cell.Point, point);\r
 \r
+                        Cell inQueue = mCells[point.X, point.Y];\r
                         if (inQueue == null)\r
                         {\r
                             Cell neighbor = new Cell(point, cost, heuristic(point, finish), cell);\r
This page took 0.021811 seconds and 4 git commands to generate.