public static void OpenPoints(Point?toOpen, Map map, HashSet <Point> opened, HashSet <Point?> wantToVisit, Dictionary <Point, PathWithCost> tracks, HashSet <Point> targetSet) { wantToVisit.Remove(toOpen.Value); foreach (var dir in PossibleDirections) { var nextPoint = toOpen + dir; if (map.InBounds(nextPoint) && !opened.Contains(nextPoint.Value) && (map[nextPoint].Content.Entity == null || targetSet.Contains((Point)nextPoint))) { wantToVisit.Add(nextPoint); var currentCost = map[nextPoint].Content.Cost + tracks[toOpen.Value].Cost; if (!tracks.ContainsKey(nextPoint.Value) || currentCost < tracks[nextPoint.Value].Cost) { tracks[nextPoint.Value] = new PathWithCost(currentCost, tracks[toOpen.Value].Path .Append(nextPoint.Value) .ToArray()); } } } }