X-Git-Url: https://git.dogcows.com/gitweb?p=chaz%2Fcarfire;a=blobdiff_plain;f=CarFire%2FCarFire%2FCarFire%2FPathFinder.cs;h=ef41370ef4a3fc442b623d3a7d1d2be3c4748ab0;hp=c37e51863d7ad4b4abe9b18c707de8a8126fcaf8;hb=122c062297acac44673e947b666c1d72cd23fb1b;hpb=d167160264cd2c33de81a71039eddbb959c40bb2
diff --git a/CarFire/CarFire/CarFire/PathFinder.cs b/CarFire/CarFire/CarFire/PathFinder.cs
index c37e518..ef41370 100644
--- a/CarFire/CarFire/CarFire/PathFinder.cs
+++ b/CarFire/CarFire/CarFire/PathFinder.cs
@@ -68,7 +68,7 @@ namespace CarFire
/// The cell to start at.
/// The desired destination.
/// A list of points representing the path through the grid,
- /// ends points not included, or null if no path could be found.
+ /// starting point not included, or null if no path could be found.
public List GetPath(Point start, Point finish)
{
return GetPath(start, finish, GetManhattanDistance, GetCost);
@@ -82,7 +82,7 @@ namespace CarFire
/// The desired destination.
/// The heuristic function.
/// A list of points representing the path through the grid,
- /// ends points not included, or null if no path could be found.
+ /// starting point not included, or null if no path could be found.
public List GetPath(Point start, Point finish, Heuristic heuristic)
{
return GetPath(start, finish, heuristic, GetCost);
@@ -96,7 +96,7 @@ namespace CarFire
/// The desired destination.
/// The cost function
/// A list of points representing the path through the grid,
- /// ends points not included, or null if no path could be found.
+ /// starting point not included, or null if no path could be found.
public List GetPath(Point start, Point finish, CostFunction costFunction)
{
return GetPath(start, finish, GetManhattanDistance, costFunction);
@@ -110,7 +110,7 @@ namespace CarFire
/// The heuristic function.
/// The cost function.
/// A list of points representing the path through the grid,
- /// ends points not included, or null if no path could be found.
+ /// starting point not included, or null if no path could be found.
public List GetPath(Point start, Point finish, Heuristic heuristic, CostFunction costFunction)
{
mFringe = new BinaryHeap();
@@ -127,13 +127,10 @@ namespace CarFire
if (cell.Point == finish)
{
List list = new List();
+ list.Add(cell.Point);
cell = cell.Parent;
- while (cell != null && cell.Point != start)
- {
- list.Add(cell.Point);
- cell = cell.Parent;
- }
+ if (cell != null) for (; cell.Point != start; cell = cell.Parent) list.Add(cell.Point);
list.Reverse();
return list;
@@ -152,13 +149,12 @@ namespace CarFire
#endif
foreach (Point point in neighbors)
{
- Cell inQueue = mCells[point.X, point.Y];
-
if (0 <= point.X && point.X < mGridWidth && 0 <= point.Y && point.Y < mGridHeight &&
mGrid[point.X, point.Y])
{
int cost = cell.G + costFunction(cell.Point, point);
+ Cell inQueue = mCells[point.X, point.Y];
if (inQueue == null)
{
Cell neighbor = new Cell(point, cost, heuristic(point, finish), cell);
|