| 
									
										
										
										
											2021-12-02 00:16:52 +02:00
										 |  |  |  | using IdaStar; | 
					
						
							| 
									
										
										
										
											2021-12-01 20:16:53 +02:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-12-02 01:28:10 +02:00
										 |  |  |  | string[] labyrinthIN = File.ReadAllLines(@"./labyrinth.txt"); | 
					
						
							| 
									
										
										
										
											2021-12-01 20:16:53 +02:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-12-02 01:28:10 +02:00
										 |  |  |  | Console.OutputEncoding = System.Text.Encoding.UTF8; | 
					
						
							| 
									
										
										
										
											2021-12-01 21:17:53 +02:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-12-02 01:28:10 +02:00
										 |  |  |  | Console.WriteLine("The input labyrinth: "); | 
					
						
							| 
									
										
										
										
											2021-12-01 21:17:53 +02:00
										 |  |  |  | foreach (string line in labyrinthIN) | 
					
						
							|  |  |  |  | { | 
					
						
							|  |  |  |  |     FormattedLabRow(line); | 
					
						
							| 
									
										
										
										
											2021-12-02 00:02:22 +02:00
										 |  |  |  |     Console.WriteLine(); | 
					
						
							| 
									
										
										
										
											2021-12-01 21:17:53 +02:00
										 |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-12-01 22:29:43 +02:00
										 |  |  |  | var algoBoard = new IdaStar.WorkingBoard(labyrinthIN.Select((row) => row.ToList()).ToList()); | 
					
						
							|  |  |  |  | int step = 0; | 
					
						
							|  |  |  |  | ConsoleColor border = ConsoleColor.Magenta; | 
					
						
							| 
									
										
										
										
											2021-12-02 01:28:10 +02:00
										 |  |  |  | bool printSteps = false; | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | Console.WriteLine(); | 
					
						
							|  |  |  |  | Console.WriteLine("Show each step? (Y/N) "); | 
					
						
							|  |  |  |  | if(Console.ReadLine()?.Trim() == "Y") { | 
					
						
							|  |  |  |  |     printSteps = true; | 
					
						
							|  |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | if(printSteps) { | 
					
						
							|  |  |  |  |     algoBoard.AlgorithmStep += (_, threshold) => { | 
					
						
							|  |  |  |  |         PrintBoard(threshold, false); | 
					
						
							|  |  |  |  |     }; | 
					
						
							|  |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | algoBoard.RunIdaStar(); | 
					
						
							|  |  |  |  | PrintBoard(0, true); | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | static void FormattedLabRow(string line) { | 
					
						
							|  |  |  |  |     char[] characters = line.ToCharArray(); | 
					
						
							|  |  |  |  |     foreach (char c in characters) { | 
					
						
							|  |  |  |  |         switch ( c ) { | 
					
						
							|  |  |  |  |             case '#': { | 
					
						
							|  |  |  |  |                 Console.BackgroundColor = ConsoleColor.White; | 
					
						
							|  |  |  |  |                 Console.Write("   ");  | 
					
						
							|  |  |  |  |                 break; | 
					
						
							|  |  |  |  |             } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |             case ' ': { | 
					
						
							|  |  |  |  |                 Console.BackgroundColor = ConsoleColor.Black; | 
					
						
							|  |  |  |  |                 Console.Write("   ");  | 
					
						
							|  |  |  |  |                 break; | 
					
						
							|  |  |  |  |             } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |             case 'S': { | 
					
						
							|  |  |  |  |                 Console.BackgroundColor = ConsoleColor.Green; | 
					
						
							|  |  |  |  |                 Console.Write("<•>");  | 
					
						
							|  |  |  |  |                 break; | 
					
						
							|  |  |  |  |             } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |             case 'F': { | 
					
						
							|  |  |  |  |                 Console.BackgroundColor = ConsoleColor.Red; | 
					
						
							|  |  |  |  |                 Console.Write("[ ]");  | 
					
						
							|  |  |  |  |                 break; | 
					
						
							|  |  |  |  |             } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |             case 'P': { | 
					
						
							|  |  |  |  |                 Console.BackgroundColor = ConsoleColor.Blue; | 
					
						
							|  |  |  |  |                 Console.Write(" • ");  | 
					
						
							|  |  |  |  |                 break; | 
					
						
							|  |  |  |  |             } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |             default: break; | 
					
						
							|  |  |  |  |         } | 
					
						
							|  |  |  |  |     } | 
					
						
							|  |  |  |  |     Console.ResetColor(); | 
					
						
							|  |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | void PrintBoard(int threshold, bool done){ | 
					
						
							| 
									
										
										
										
											2021-12-01 22:29:43 +02:00
										 |  |  |  |     Console.Clear(); | 
					
						
							|  |  |  |  |     step++; | 
					
						
							|  |  |  |  |     if(done){ | 
					
						
							| 
									
										
										
										
											2021-12-02 01:28:10 +02:00
										 |  |  |  |         Console.WriteLine("The solved labyrinth is:"); | 
					
						
							| 
									
										
										
										
											2021-12-02 00:26:24 +02:00
										 |  |  |  |     }else if(step%2 == 0) { | 
					
						
							| 
									
										
										
										
											2021-12-02 01:28:10 +02:00
										 |  |  |  |         Console.WriteLine($"Computing (threshold: {threshold}) [• ]"); | 
					
						
							| 
									
										
										
										
											2021-12-01 22:29:43 +02:00
										 |  |  |  |     }else { | 
					
						
							| 
									
										
										
										
											2021-12-02 01:28:10 +02:00
										 |  |  |  |         Console.WriteLine($"Computing (threshold: {threshold}) [ •]"); | 
					
						
							| 
									
										
										
										
											2021-12-01 22:29:43 +02:00
										 |  |  |  |     } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |     //top border | 
					
						
							|  |  |  |  |     Console.BackgroundColor = border; | 
					
						
							| 
									
										
										
										
											2021-12-02 00:47:31 +02:00
										 |  |  |  |     for (var i=0; i< algoBoard.Board[0].Count + 2; i++){ | 
					
						
							| 
									
										
										
										
											2021-12-01 23:45:08 +02:00
										 |  |  |  |         Console.Write("   ");  | 
					
						
							| 
									
										
										
										
											2021-12-01 22:29:43 +02:00
										 |  |  |  |     } | 
					
						
							|  |  |  |  |     Console.ResetColor(); | 
					
						
							| 
									
										
										
										
											2021-12-01 23:45:08 +02:00
										 |  |  |  |     Console.WriteLine(); | 
					
						
							| 
									
										
										
										
											2021-12-01 22:29:43 +02:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  |     foreach (var line in algoBoard.Board) | 
					
						
							|  |  |  |  |     { | 
					
						
							|  |  |  |  |         var charlist = line.Select((state) => CellStateUtil.ToInput(state)); | 
					
						
							|  |  |  |  |         var str = string.Join("", charlist); | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |         //left border | 
					
						
							|  |  |  |  |         Console.BackgroundColor = border; | 
					
						
							| 
									
										
										
										
											2021-12-01 23:45:08 +02:00
										 |  |  |  |         Console.Write("   ");  | 
					
						
							| 
									
										
										
										
											2021-12-01 22:29:43 +02:00
										 |  |  |  |         Console.ResetColor(); | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |         //labyrinth line | 
					
						
							|  |  |  |  |         FormattedLabRow(str); | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |         //right border | 
					
						
							|  |  |  |  |         Console.BackgroundColor = border; | 
					
						
							| 
									
										
										
										
											2021-12-01 23:45:08 +02:00
										 |  |  |  |         Console.Write("   ");  | 
					
						
							| 
									
										
										
										
											2021-12-01 22:29:43 +02:00
										 |  |  |  |         Console.ResetColor(); | 
					
						
							| 
									
										
										
										
											2021-12-01 23:45:08 +02:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  |         Console.WriteLine(); | 
					
						
							| 
									
										
										
										
											2021-12-01 22:29:43 +02:00
										 |  |  |  |     } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |     //bottom border | 
					
						
							|  |  |  |  |     Console.BackgroundColor = border; | 
					
						
							| 
									
										
										
										
											2021-12-02 00:47:31 +02:00
										 |  |  |  |     for (var i=0; i< algoBoard.Board[0].Count + 2; i++){ | 
					
						
							| 
									
										
										
										
											2021-12-01 23:45:08 +02:00
										 |  |  |  |         Console.Write("   ");  | 
					
						
							| 
									
										
										
										
											2021-12-01 22:29:43 +02:00
										 |  |  |  |     } | 
					
						
							|  |  |  |  |     Console.ResetColor(); | 
					
						
							| 
									
										
										
										
											2021-12-01 23:45:08 +02:00
										 |  |  |  |     Console.WriteLine(); | 
					
						
							| 
									
										
										
										
											2021-12-02 00:16:52 +02:00
										 |  |  |  | 	Thread.Sleep(200); | 
					
						
							| 
									
										
										
										
											2021-12-02 00:44:28 +02:00
										 |  |  |  | 	// Console.ReadLine(); | 
					
						
							| 
									
										
										
										
											2021-12-02 01:28:10 +02:00
										 |  |  |  | } |