private static int FindAllKeysMultiMaze(string[] input) { var multiMaze = UpdateMazeToMultiMaze(input); var maze = new L1Maze(multiMaze); var l2Maze = new L2Maze(maze); var mazeRunner = new MultiMazeRunner(l2Maze, l2Maze.StartPositions, 0); var allResults = BreadthFirstSearchMulti(mazeRunner); return(allResults.First(t => t.HasAllKeys).MoveCount); }
public static IEnumerable <MultiMazeRunner> BreadthFirstSearchMulti(MultiMazeRunner startTrack) { var tracks = new Heap <MultiMazeRunner>(); tracks.Add(startTrack, startTrack.MoveCount); var visited = new HashSet <MultiMazeRunner>(); while (tracks.Any()) { var track = tracks.Pop(); if (!visited.Add(track)) { continue; } foreach (var nextTrack in track.Children()) { yield return(nextTrack); tracks.Add(nextTrack, nextTrack.MoveCount); } } }