private GetPathDataClass GetPathHelperData(IHex t) { var data = new GetPathDataClass(); data.OpenSet = new List <IHex>() { t }; data.ClosedSet = new List <Pair <int, int> >(); data.InitPath = new Path(); data.PathsToGoal = new List <Path>(); data.PathsToGoalDict = new Dictionary <Pair <int, int>, Path>(); data.PathsToGoalDict.Add(new Pair <int, int>(t.GetCol(), t.GetRow()), data.InitPath); return(data); }
private void GetPathHelperIterateData(GetPathDataClass data, IPathable navigator) { var tile = data.OpenSet.ElementAt(0); foreach (var neighbor in tile.GetAdjacent()) { var neighborKey = new Pair <int, int>(neighbor.GetCol(), neighbor.GetRow()); if (neighbor.GetCurrentOccupant() == null) { if (!data.ClosedSet.Contains(neighborKey)) { data.OpenSet.Add(neighbor); } var pathKey = new Pair <int, int>(tile.GetCol(), tile.GetRow()); var previousPath = data.PathsToGoalDict[pathKey]; var newPath = previousPath.DeepCopy(); newPath.AddTile(neighbor, navigator); var newKey = new Pair <int, int>(neighbor.GetCol(), neighbor.GetRow()); if (!data.PathsToGoalDict.ContainsKey(newKey)) { data.PathsToGoalDict.Add(newKey, newPath); } else { if (newPath.Score < data.PathsToGoalDict[newKey].Score) { data.PathsToGoalDict[newKey] = newPath; } } data.PathsToGoal.Add(newPath); } else { data.ClosedSet.Add(neighborKey); } } data.ClosedSet.Add(new Pair <int, int>(tile.GetCol(), tile.GetRow())); data.OpenSet.Remove(tile); }