public void ReadInMazeImage_ColorsAreUnsupportedShadeOfBlue_ThrowsException() { const string mazeImageFilePath = @"..\..\..\TestingMazes\SuperSimpleMazePurpleEnd.png"; var mazeReader = new MazeReaderUtility(mazeImageFilePath); mazeReader.ReadInMazeImage(); }
public void ReadInMazeImage_MazeHasNoFinishPoint_ThrowsException() { const string mazeImageFilePath = @"..\..\..\TestingMazes\SuperSimpleMazeNoEnd.png"; var mazeReader = new MazeReaderUtility(mazeImageFilePath); mazeReader.ReadInMazeImage(); }
public void MazeIsSolvedAndSolutionIsComplete() { // Test that start of solution path IsStartPoint and end IsFinishPoint const string mazeImageFilePath = @"..\..\..\TestingMazes\UltraTinyMaze.png"; var mazeReader = new MazeReaderUtility(mazeImageFilePath); var mazeToTest = mazeReader.ReadInMazeImage(); var mazeSolution = new BruteForceMazeSolution(mazeToTest); mazeSolution.SolveMaze(); Assert.IsTrue(mazeSolution.PathToSolveMaze.First().MazeGridpoint.IsStartPoint); Assert.IsTrue(mazeSolution.PathToSolveMaze.Last().MazeGridpoint.IsFinishPoint); // Test that solution path is connected all the way through, distance between each point is unity var lastSolutionElement = mazeSolution.PathToSolveMaze.First(); foreach (var solutionElement in mazeSolution.PathToSolveMaze.Skip(1)) { var lastCoordinate = lastSolutionElement.MazeGridpoint.Position; var thisCoordinate = solutionElement.MazeGridpoint.Position; Assert.AreEqual(lastCoordinate.Distance(thisCoordinate), 1.0, 0.000001); lastSolutionElement = solutionElement; } }
public void ReadInMazeImage_ColorsAreInvalid_ThrowsException() { const string mazeImageFilePath = @"..\..\..\TestingMazes\SmileyFace.png"; var mazeReader = new MazeReaderUtility(mazeImageFilePath); mazeReader.ReadInMazeImage(); }
public void PreTreatMazeToSolve_SuperSimpleMaze_RedundantWhiteSpaceIsRemovedThenDeadEndsAreFound() { const string mazeImageFilePath = @"..\..\..\TestingMazes\SuperSimpleMaze.png"; var mazeReader = new MazeReaderUtility(mazeImageFilePath); var mazeToPreTreat = mazeReader.ReadInMazeImage(); var preTreatmentOne = new RemoveAllEasilyIdentifiableDeadEnds(mazeToPreTreat); preTreatmentOne.PreTreatMazeToSolve(); Assert.AreEqual(mazeToPreTreat.MazeGridpoints.Values.Count(m => m.HasBeenVisited), 0); var preTreatmentTwo = new RemoveRedundantWhiteSpace(mazeToPreTreat); preTreatmentTwo.PreTreatMazeToSolve(); var gridpointsRemovedAsRedundant = mazeToPreTreat.MazeGridpoints.Values.Count(m => m.HasBeenVisited); Assert.AreEqual(gridpointsRemovedAsRedundant, 710); var preTreatmentThree = new DetermineAllOpenPaths(mazeToPreTreat); preTreatmentThree.PreTreatMazeToSolve(); var preTreatmentFour = new RemoveAllEasilyIdentifiableDeadEnds(mazeToPreTreat); preTreatmentFour.PreTreatMazeToSolve(); Assert.IsTrue(mazeToPreTreat.MazeGridpoints.Values.Count(m => m.HasBeenVisited) > gridpointsRemovedAsRedundant); }
public void SolveMaze_SuperSimpleMazeCannotBeSolved_ThrowsException() { const string mazeImageFilePath = @"..\..\..\TestingMazes\SuperSimpleMazeCannotBeSolved.png"; var mazeReader = new MazeReaderUtility(mazeImageFilePath); var mazeToTest = mazeReader.ReadInMazeImage(); var mazeSolution = new RecursiveBreadthFirstMazeSolution(mazeToTest); mazeSolution.SolveMaze(); }
public void ReadInMazeImage_SuperSimpleMaze_MazeGridpointsMatchHeightTimesWidth() { const string mazeImageFilePath = @"..\..\..\TestingMazes\SuperSimpleMaze.png"; var mazeReader = new MazeReaderUtility(mazeImageFilePath); var maze = mazeReader.ReadInMazeImage(); var mazeHeight = maze.MazeHeight; var mazeWidth = maze.MazeWidth; Assert.AreEqual(maze.MazeGridpoints.Count, mazeHeight * mazeWidth); }
public void PreTreatmentMakesMazeEasierToSolve() { const string mazeImageFilePath = @"..\..\..\TestingMazes\SuperSimpleMaze.png"; var mazeReader = new MazeReaderUtility(mazeImageFilePath); var mazeToTest = mazeReader.ReadInMazeImage(); var mazeSolution = new BruteForceMazeSolution(mazeToTest); mazeSolution.SolveMaze(); var stepsToSolveMazeWithoutPreTreatment = mazeSolution.PathToSolveMaze.Count(); mazeToTest = mazeReader.ReadInMazeImage(); mazeSolution = new BruteForceMazeSolution(mazeToTest); mazeSolution.PreTreatmentLogics.Add(new RemoveRedundantWhiteSpace(mazeToTest)); mazeSolution.SolveMaze(); var stepsToSolveMazeWithPreTreatment = mazeSolution.PathToSolveMaze.Count(); Assert.IsTrue(stepsToSolveMazeWithPreTreatment < stepsToSolveMazeWithoutPreTreatment); }
public void PreTreatMazeToSolve_AllWhiteSpaceMaze_RedundantWhiteSpaceIsRemoved() { const string mazeImageFilePath = @"..\..\..\TestingMazes\AllWhiteSpaceMaze.png"; var mazeReader = new MazeReaderUtility(mazeImageFilePath); var mazeToPreTreat = mazeReader.ReadInMazeImage(); Assert.AreEqual(mazeToPreTreat.MazeGridpoints.Values.Count(m => m.HasBeenVisited), 0); var preTreatment = new RemoveRedundantWhiteSpace(mazeToPreTreat); preTreatment.PreTreatMazeToSolve(); Assert.AreEqual(mazeToPreTreat.MazeGridpoints.Values.Count(m => m.HasBeenVisited), 144); }
public void PreTreatMazeToSolve_UltraTinyMaze_CellsHaveFourOpenPaths() { const string mazeImageFilePath = @"..\..\..\TestingMazes\UltraTinyMaze.png"; var mazeReader = new MazeReaderUtility(mazeImageFilePath); var mazeToPreTreat = mazeReader.ReadInMazeImage(); Assert.IsTrue(mazeToPreTreat.MazeGridpoints .All(g => g.Value.DirectionsAvailable.Count == 4)); var preTreatment = new DetermineAllOpenPaths(mazeToPreTreat); preTreatment.PreTreatMazeToSolve(); Assert.IsTrue(mazeToPreTreat.MazeGridpoints .All(g => g.Value.DirectionsAvailable.Count != 4)); }
public void SolveMaze_UltraTinyMaze_NumberOfStepsToSolveAsExpected() { const string mazeImageFilePath = @"..\..\..\TestingMazes\UltraTinyMaze.png"; var mazeReader = new MazeReaderUtility(mazeImageFilePath); var mazeToTest = mazeReader.ReadInMazeImage(); var mazeSolution = new BruteForceWallHuggingMazeSolution(mazeToTest); mazeSolution.SolveMaze(); var stepsToSolveMaze = mazeSolution.PathToSolveMaze.Count(); Assert.AreEqual(stepsToSolveMaze, 95); var gridpointsVisited = mazeSolution.MazeToSolve.MazeGridpoints.Values.Count(m => m.HasBeenVisited); Assert.AreEqual(gridpointsVisited, 166); }
public void SolveMaze_SuperSimpleMaze_NumberOfStepsToSolveAsExpected() { const string mazeImageFilePath = @"..\..\..\TestingMazes\SuperSimpleMaze.png"; var mazeReader = new MazeReaderUtility(mazeImageFilePath); var mazeToTest = mazeReader.ReadInMazeImage(); var mazeSolution = new RecursiveBreadthFirstMazeSolution(mazeToTest); mazeSolution.SolveMaze(); var stepsToSolveMaze = mazeSolution.PathToSolveMaze.Count(); Assert.AreEqual(stepsToSolveMaze, 689); var gridpointsVisited = mazeSolution.MazeToSolve.MazeGridpoints.Values.Count(m => m.HasBeenVisited); Assert.AreEqual(gridpointsVisited, 768); }
public void PreTreatMazeToSolve_SuperSimpleMaze_NoStartPointCellsHaveFourOpenPaths() { const string mazeImageFilePath = @"..\..\..\TestingMazes\SuperSimpleMaze.png"; var mazeReader = new MazeReaderUtility(mazeImageFilePath); var mazeToPreTreat = mazeReader.ReadInMazeImage(); Assert.AreEqual(mazeToPreTreat.MazeGridpoints .Where(m => m.Value.IsStartPoint) .Count(g => g.Value.DirectionsAvailable.Count == 4), 6); var preTreatment = new DetermineAllOpenPathsAtStartPoint(mazeToPreTreat); preTreatment.PreTreatMazeToSolve(); Assert.AreEqual(mazeToPreTreat.MazeGridpoints .Where(m => m.Value.IsStartPoint) .Count(g => g.Value.DirectionsAvailable.Count != 4), 5); }
public void PreTreatMazeToSolve_UltraTinyMaze_TwentyNineDeadEndPointsAreMarked() { const string mazeImageFilePath = @"..\..\..\TestingMazes\UltraTinyMaze.png"; var mazeReader = new MazeReaderUtility(mazeImageFilePath); var mazeToPreTreat = mazeReader.ReadInMazeImage(); var preTreatmentOne = new DetermineAllOpenPaths(mazeToPreTreat); preTreatmentOne.PreTreatMazeToSolve(); var preTreatmentTwo = new RemoveAllEasilyIdentifiableDeadEnds(mazeToPreTreat); preTreatmentTwo.PreTreatMazeToSolve(); var deadEndsMarked = mazeToPreTreat.MazeGridpoints.Values.Count(m => m.HasBeenVisited); Assert.AreEqual(deadEndsMarked, 29); }
// This test was used for tracking the progress of some solver algorithms running in release mode public void ConvertTextOutputToSolutionPathOnMazeImage() { const string mazeImageFilePath = @"..\..\..\SampleMazes\Maze2.png"; const string mazeSolutionTextFilePath = @"..\..\..\SampleMazesSolutions\SampleMaze2\WallHugging.txt"; const string mazeImageSolutionFilePath = @"..\..\..\SampleMazesSolutions\SampleMaze2\Maze2SolutionProgress.png"; var mazeReader = new MazeReaderUtility(mazeImageFilePath); var maze = mazeReader.ReadInMazeImage(); var fileLines = File.ReadAllLines(mazeSolutionTextFilePath); var count = fileLines.Count(); var mazeSolutionPath = new List <MazeSolutionElement>(); for (var i = 0; i < count; i++) { var line = fileLines[i]; var splitLine = line.Split(' ', ','); var xPosition = Convert.ToInt32(splitLine[2]); var yPosition = Convert.ToInt32(splitLine[6]); var coordinate = new CartesianCoordinate(xPosition, yPosition); var mazeGridpoint = maze.MazeGridpoints[coordinate]; var solutionElement = new MazeSolutionElement { MazeGridpoint = mazeGridpoint, }; mazeSolutionPath.Add(solutionElement); fileLines[i] = null; } var mazeSolution = new MazeSolution(maze) { PathToSolveMaze = mazeSolutionPath }; var mazeWriter = new MazeWriterUtility(mazeImageSolutionFilePath, mazeSolution.MazeToSolve); mazeSolution.MarkSolutionPath(); mazeWriter.SaveMazeImage(); }
/// <summary> /// Solves an input maze by outputting an image with the solution traced in green /// and any spaces visited colored gray. /// /// Arguments Usage: /// [0] - Required - Path to the maze image (string) /// [1] - Required - Path to write the solution image (string) /// [2] - Optional - Specify to have the solution image be updated in real time (bool) /// [3] - Optional - Specify which solver logic to use (int) /// </summary> static void Main(string[] args) { var stopwatch = System.Diagnostics.Stopwatch.StartNew(); var watchMazeGetSolved = false; var pathToMazeImageFile = args[0]; var mazeReader = new MazeReaderUtility(pathToMazeImageFile); var mazeSolutionType = -1; if (args.Length > 3) { mazeSolutionType = Convert.ToInt32(args[3]); } var mazeToSolve = mazeReader.ReadInMazeImage(); var mazeSolution = InstantiateMazeSolution(mazeToSolve, mazeSolutionType); var pathToMazeSolutionImageFile = args[1]; var mazeWriter = new MazeWriterUtility(pathToMazeSolutionImageFile, mazeSolution.MazeToSolve); if (args.Length > 2) { watchMazeGetSolved = bool.Parse(args[2]); } var mazeUpdatedListener = new MazeUpdatedListener(); if (watchMazeGetSolved) { mazeUpdatedListener.Subscribe(mazeSolution, mazeWriter); } mazeSolution.SolveMaze(); mazeSolution.MarkSolutionPath(); mazeUpdatedListener.UnSubscribe(mazeSolution); mazeWriter.SaveMazeImage(); stopwatch.Stop(); var elapsedTimeInMilliseconds = stopwatch.ElapsedMilliseconds; Console.WriteLine("Elapsed Time in Seconds: " + elapsedTimeInMilliseconds / 1000d); Console.WriteLine("Number of Steps: " + mazeSolution.PathToSolveMaze.Count); }