mirror of
				https://github.com/dancojocaru2000/ai-project-idastar.git
				synced 2025-10-31 10:16:32 +02:00 
			
		
		
		
	Implemented function to format input labyrinth
This commit is contained in:
		
							parent
							
								
									4818450ced
								
							
						
					
					
						commit
						a7d4d4f11c
					
				
					 3 changed files with 44 additions and 20 deletions
				
			
		
							
								
								
									
										38
									
								
								Program.cs
									
										
									
									
									
								
							
							
						
						
									
										38
									
								
								Program.cs
									
										
									
									
									
								
							|  | @ -1,6 +1,7 @@ | ||||||
| using IdaStar; | using IdaStar; | ||||||
| 
 | 
 | ||||||
| string[] labyrinthIN = File.ReadAllLines(@"./labyrinth.txt"); | string[] labyrinthIN = File.ReadAllLines(@"./labyrinth.txt"); | ||||||
|  | string[] labyrinth = FormatLabyrinth(labyrinthIN); | ||||||
| 
 | 
 | ||||||
| Console.OutputEncoding = System.Text.Encoding.UTF8; | Console.OutputEncoding = System.Text.Encoding.UTF8; | ||||||
| 
 | 
 | ||||||
|  | @ -11,7 +12,14 @@ foreach (string line in labyrinthIN) | ||||||
|     Console.WriteLine(); |     Console.WriteLine(); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| var algoBoard = new IdaStar.WorkingBoard(labyrinthIN.Select((row) => row.ToList()).ToList()); | Console.WriteLine("The formatted labyrinth: "); | ||||||
|  | foreach (string line in labyrinth) | ||||||
|  | { | ||||||
|  |     FormattedLabRow(line); | ||||||
|  |     Console.WriteLine(); | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | var algoBoard = new IdaStar.WorkingBoard(labyrinth.Select((row) => row.ToList()).ToList()); | ||||||
| int step = 0; | int step = 0; | ||||||
| ConsoleColor border = ConsoleColor.Magenta; | ConsoleColor border = ConsoleColor.Magenta; | ||||||
| bool printSteps = false; | bool printSteps = false; | ||||||
|  | @ -71,6 +79,34 @@ static void FormattedLabRow(string line) { | ||||||
|     Console.ResetColor(); |     Console.ResetColor(); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | string[] FormatLabyrinth(string[] labIN) { | ||||||
|  |     var maxW = 0; | ||||||
|  |     List<string> lab = new List<string>(); | ||||||
|  |     foreach (string line in labIN) | ||||||
|  |     { | ||||||
|  |         if(maxW < line.Length) { | ||||||
|  |             maxW = line.Length; | ||||||
|  |         } | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     foreach (string line in labIN) | ||||||
|  |     { | ||||||
|  |         if(maxW > line.Length) { | ||||||
|  |             var dif = maxW - line.Length; | ||||||
|  |             string fLine = line; | ||||||
|  |             while (dif > 0) { | ||||||
|  |                 fLine = fLine+ "#"; | ||||||
|  |                 dif--; | ||||||
|  |             } | ||||||
|  |             lab.Add(fLine); | ||||||
|  |         }else { | ||||||
|  |             lab.Add(line); | ||||||
|  |         } | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     string[] FormattedLabyrinth = lab.ToArray(); | ||||||
|  |     return FormattedLabyrinth; | ||||||
|  | } | ||||||
| 
 | 
 | ||||||
| void PrintBoard(int threshold, bool done){ | void PrintBoard(int threshold, bool done){ | ||||||
|     Console.Clear(); |     Console.Clear(); | ||||||
|  |  | ||||||
|  | @ -1,14 +1,7 @@ | ||||||
| ########## | #### ### | ||||||
| #S  # #  # | #S    # | ||||||
| ### # ## # | ##### ## | ||||||
|  |           | ||||||
|  | ## ####  # | ||||||
| #  #     # | #  #     # | ||||||
| ##    #  # |   ##F#### | ||||||
| #  # ### # |  | ||||||
| ####  #### |  | ||||||
| ##### #### |  | ||||||
| #     #  F |  | ||||||
| ### #### # |  | ||||||
| #   #    # |  | ||||||
| ##    #  # |  | ||||||
| #  # ### # |  | ||||||
| ########## |  | ||||||
|  |  | ||||||
|  | @ -1,5 +0,0 @@ | ||||||
| ###S# |  | ||||||
| #  p# |  | ||||||
| ##pp# |  | ||||||
| #pp## |  | ||||||
| #F### |  | ||||||
		Loading…
	
	Add table
		
		Reference in a new issue