private Path CreatePath(Tile start, Tile end) { Path path = new Path(); List <Tile> toCheck = new List <Tile>(); HashSet <Tile> ignore = new HashSet <Tile>(); foreach (var tile in vectorsToTiles.Values) { tile.Clear(); } Tile currentTile = start; toCheck.Add(currentTile); while (toCheck.Count != 0) { currentTile = GetTileWithLowestF(toCheck); if (currentTile == end) { break; } toCheck.Remove(currentTile); ignore.Add(currentTile); foreach (var neighbour in CheckNeighboursPath(currentTile)) { if (!ignore.Contains(neighbour)) { if (!toCheck.Contains(neighbour)) { toCheck.Add(neighbour); neighbour.SetParent(currentTile); } else if (currentTile.G + neighbour.Difficulty < neighbour.G) { neighbour.SetParent(currentTile); } } } } while (currentTile != start) { path.AddPath(currentTile); currentTile = currentTile.Parent; } path.AddPath(currentTile); path.ActualPath(); return(path); }