public List<Tile> FindPath()
{
if (startTile == goalTile)
{
return new List<Tile>();
}
Node startNode = new Node(startTile);
Node currentNode = startNode;
List<Tile> neighborTiles;
List<Tile> path = new List<Tile>();
//Add current node to open nodes
openNodes.Add(startNode);
openDict.Add(startNode.tile.ID, startNode.tile);
do
{
//Switch the lowest cost node to the closed list
currentNode = GetLowestCostNodeFromOpenNodes();
closedNodes.Add(currentNode);
closedDict.Add(currentNode.tile.ID, currentNode.tile);
openNodes.Remove(currentNode);
openDict.Remove(currentNode.tile.ID);
//Find walkable neighbor tiles not on the closed list
neighborTiles = GetWalkableNeighborsNotOnClosedList(currentNode);
//Handle if neighbor node is on the open list already
//and add to open list
AddNeighborNodesToOpenList(currentNode, neighborTiles);
} while (openNodes.Count > 0 && currentNode.tile != goalTile);
if (openNodes.Count == 0 && currentNode.tile != goalTile)
return new List<Tile>();
path.Add(currentNode.tile);
do
{
for (int i = 0; i < closedNodes.Count; i++)
{
if (closedNodes[i].tile == currentNode.parentTile)
{
currentNode = closedNodes[i];
break;
}
}
//currentNode = closedNodes.Find(new Predicate<Node>(delegate(Node node)
//{
// return node.tile == currentNode.parentTile;
// }));
path.Add(currentNode.tile);
} while (currentNode.parentTile != null);
path.Reverse();
return path;
}