From 4818450ced425abfe4bb0cdd118a5ffe0f98ee5e Mon Sep 17 00:00:00 2001 From: DariusTFox24 Date: Thu, 2 Dec 2021 01:28:10 +0200 Subject: [PATCH 1/2] Added option to skip showing all the steps fixed bugs and such --- Program.cs | 116 ++++++++++++++++++++++++++++---------------------- labyrinth.txt | 9 +++- 2 files changed, 74 insertions(+), 51 deletions(-) diff --git a/Program.cs b/Program.cs index 3bd8475..22749d4 100644 --- a/Program.cs +++ b/Program.cs @@ -1,9 +1,10 @@ using IdaStar; -string[] labyrinthIN = System.IO.File.ReadAllLines(@"./labyrinth.txt"); +string[] labyrinthIN = File.ReadAllLines(@"./labyrinth.txt"); +Console.OutputEncoding = System.Text.Encoding.UTF8; -System.Console.WriteLine("The input labyrinth: "); +Console.WriteLine("The input labyrinth: "); foreach (string line in labyrinthIN) { FormattedLabRow(line); @@ -12,17 +13,74 @@ foreach (string line in labyrinthIN) var algoBoard = new IdaStar.WorkingBoard(labyrinthIN.Select((row) => row.ToList()).ToList()); int step = 0; -bool done = false; ConsoleColor border = ConsoleColor.Magenta; -algoBoard.AlgorithmStep += (_, threshold) => { +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){ Console.Clear(); step++; if(done){ - System.Console.WriteLine("The solved labyrinth is:"); + Console.WriteLine("The solved labyrinth is:"); }else if(step%2 == 0) { - System.Console.WriteLine($"Computing (threshold: {threshold}) [• ]"); + Console.WriteLine($"Computing (threshold: {threshold}) [• ]"); }else { - System.Console.WriteLine($"Computing (threshold: {threshold}) [ •]"); + Console.WriteLine($"Computing (threshold: {threshold}) [ •]"); } //top border @@ -63,46 +121,4 @@ algoBoard.AlgorithmStep += (_, threshold) => { Console.WriteLine(); Thread.Sleep(200); // Console.ReadLine(); -}; - -algoBoard.RunIdaStar(); - -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(); -} \ No newline at end of file +} diff --git a/labyrinth.txt b/labyrinth.txt index 46414a8..9ef6960 100644 --- a/labyrinth.txt +++ b/labyrinth.txt @@ -1,7 +1,14 @@ ########## -#S # # F +#S # # # ### # ## # # # # ## # # # # ### # +#### #### +##### #### +# # F +### #### # +# # # +## # # +# # ### # ########## \ No newline at end of file From a7d4d4f11c00364c22396e11195ac1c24108983e Mon Sep 17 00:00:00 2001 From: DariusTFox24 Date: Fri, 3 Dec 2021 12:21:31 +0200 Subject: [PATCH 2/2] Implemented function to format input labyrinth --- Program.cs | 38 +++++++++++++++++++++++++++++++++++++- labyrinth.txt | 21 +++++++-------------- labyrinthOUT.txt | 5 ----- 3 files changed, 44 insertions(+), 20 deletions(-) delete mode 100644 labyrinthOUT.txt diff --git a/Program.cs b/Program.cs index 22749d4..7214258 100644 --- a/Program.cs +++ b/Program.cs @@ -1,6 +1,7 @@ using IdaStar; string[] labyrinthIN = File.ReadAllLines(@"./labyrinth.txt"); +string[] labyrinth = FormatLabyrinth(labyrinthIN); Console.OutputEncoding = System.Text.Encoding.UTF8; @@ -11,7 +12,14 @@ foreach (string line in labyrinthIN) 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; ConsoleColor border = ConsoleColor.Magenta; bool printSteps = false; @@ -71,6 +79,34 @@ static void FormattedLabRow(string line) { Console.ResetColor(); } +string[] FormatLabyrinth(string[] labIN) { + var maxW = 0; + List lab = new List(); + 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){ Console.Clear(); diff --git a/labyrinth.txt b/labyrinth.txt index 9ef6960..16c9c72 100644 --- a/labyrinth.txt +++ b/labyrinth.txt @@ -1,14 +1,7 @@ -########## -#S # # # -### # ## # -# # # -## # # -# # ### # -#### #### -##### #### -# # F -### #### # -# # # -## # # -# # ### # -########## \ No newline at end of file +#### ### +#S # +##### ## + +## #### # +# # # + ##F#### diff --git a/labyrinthOUT.txt b/labyrinthOUT.txt deleted file mode 100644 index a56df2b..0000000 --- a/labyrinthOUT.txt +++ /dev/null @@ -1,5 +0,0 @@ -###S# -# p# -##pp# -#pp## -#F### \ No newline at end of file