public int NumberOfStepsToTarget(Coordinate startCoord, Coordinate targetCoord) { Queue <MazeStep> queue = new Queue <MazeStep>(); MazeStep start = new MazeStep(startCoord, 0, null); List <Coordinate> allPreviousCoordinates = new List <Coordinate>(); queue.Enqueue(start); // Keep iterating over queue until we get a result do { MazeStep currentState = queue.Dequeue(); // If hits are target - return if (currentState.ReachedDesintation(targetCoord)) { return(currentState.Step); } // Figure out other valid paths and add them to queue while iterating step EvaluateOpenSteps(currentState, queue, allPreviousCoordinates); Debug.WriteLine($"prevCoord: {allPreviousCoordinates.Count} queue: {queue.Count}."); } while (queue.Any()); return(0); }
public int MinimumNumberOfStepsToCoordinates(Coordinate startCoord, int favNumber, Coordinate targetCoord) { MazeStep start = new MazeStep(startCoord, 0, new List <Coordinate>()); _queue.Add(start); // Keep iterating over queue until we get a result do { MazeStep mazeStep = _queue[0]; _queue.RemoveAt(0); // If hits are target - return if (mazeStep.ReachedDesintation(targetCoord)) { return(mazeStep.Step); } // Figure out other valid paths and add them to queue while iterating step EvaluateOpenSteps(mazeStep, favNumber); } while (_queue.Any()); return(0); }