Generation

generate functionSun, 13 Nov 2022

Find the shortest path between two points in a 3d grid

public static List<Point> ShortestPath(Point start, Point end) { List<Point> result = new List<Point>(); Queue<Point> queue = new Queue<Point>(); queue.Enqueue(start); while (queue.Count > 0) { Point p = queue.Dequeue(); if (result.Contains(p)) { continue; } result.Add(p); if (p.Equals(end)) { break; } List<Point> neighbors = FindNeighbors(p); foreach (Point neighbor in neighbors) { if (result.Contains(neighbor)) { continue; } queue.Enqueue(neighbor); } } return result; }

Questions about programming?Chat with your personal AI assistant