// Given a valid finish node with a linked list back to the start node // will draw a path on the bitmap image from finish to start public void ColorPathFromFinishToStart(MazeNode finishNode) { MazeNode current = finishNode; while (current != null) { maze.SetPixel(current.GetX(), current.GetY(), pathColor); current = current.GetParent(); } }
//Will count the current level of the current node based on its fathers recursively public int getCurrentLevel(MazeNode node) { int nLevel = 0; MazeNode current = node; while (current != null) { nLevel += 1; current = current.GetParent(); } return(nLevel); }
private void BTN_Solve_Click(object sender, RoutedEventArgs e) { DateTime startedTime; DateTime finalizedTime; // Get the file names that will be working on from command line string outputPath = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetEntryAssembly().Location); // For this project these define the start, end, wall and path colors for the maze // Just change these if you want to solve a maze with different requirements System.Drawing.Color start = System.Drawing.Color.Red; System.Drawing.Color end = System.Drawing.Color.Blue; System.Drawing.Color wall = System.Drawing.Color.Black; System.Drawing.Color path = System.Drawing.Color.GreenYellow; // Load the maze from the first argument filename Bitmap mazeImage = new Bitmap(ImagePath); // initialize path finder with the image and colors to operate with PathFinder pf = new PathFinder(mazeImage, start, end, wall, path); // get the solved maze bitmap from pathfinder startedTime = DateTime.Now; MazeNode resultPath = pf.SolveMaze(COMBO_Type.SelectedValue.ToString()); finalizedTime = DateTime.Now; Lbl_coordinates.Content = "Elapsed Time:" + finalizedTime.Subtract(startedTime).TotalSeconds.ToString() + " seconds. "; mazeImage = pf.Maze; if (mazeImage == null) { MessageBox.Show("Could not solve maze"); } else { LIST_Solution.Items.Clear(); MazeNode current = resultPath; while (current != null) { LIST_Solution.Items.Add("(" + current.GetX() + ", " + current.GetY() + ")"); current = current.GetParent(); } Lbl_coordinates.Content = Lbl_coordinates.Content + LIST_Solution.Items.Count.ToString() + " elements"; // Save the solved maze image into the output file path mazeImage.Save(outputPath + @"\solved_maze.png"); fileUri = new Uri(outputPath + @"\solved_maze.png"); IMG_Maze.Source = new BitmapImage(fileUri); } }