Browse Source

Implemented function to format input labyrinth

pull/1/head
DariusTFox24 3 years ago
parent
commit
a7d4d4f11c
  1. 38
      Program.cs
  2. 21
      labyrinth.txt
  3. 5
      labyrinthOUT.txt

38
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<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){
Console.Clear();

21
labyrinth.txt

@ -1,14 +1,7 @@
##########
#S # # #
### # ## #
# # #
## # #
# # ### #
#### ####
##### ####
# # F
### #### #
# # #
## # #
# # ### #
##########
#### ###
#S #
##### ##
## #### #
# # #
##F####

5
labyrinthOUT.txt

@ -1,5 +0,0 @@
###S#
# p#
##pp#
#pp##
#F###
Loading…
Cancel
Save