Browse Source

Merge pull request #1 from dancojocaru2000:darius

Darius
dan
Kenneth Bruen 3 years ago committed by GitHub
parent
commit
2c74cde949
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 150
      Program.cs
  2. 10
      labyrinth.txt
  3. 5
      labyrinthOUT.txt

150
Program.cs

@ -1,71 +1,43 @@
using IdaStar; using IdaStar;
string[] labyrinthIN = System.IO.File.ReadAllLines(@"./labyrinth.txt"); string[] labyrinthIN = File.ReadAllLines(@"./labyrinth.txt");
string[] labyrinth = FormatLabyrinth(labyrinthIN);
Console.OutputEncoding = System.Text.Encoding.UTF8;
System.Console.WriteLine("The input labyrinth: "); Console.WriteLine("The input labyrinth: ");
foreach (string line in labyrinthIN) foreach (string line in labyrinthIN)
{ {
FormattedLabRow(line); FormattedLabRow(line);
Console.WriteLine(); Console.WriteLine();
} }
var algoBoard = new IdaStar.WorkingBoard(labyrinthIN.Select((row) => row.ToList()).ToList()); Console.WriteLine("The formatted labyrinth: ");
int step = 0; foreach (string line in labyrinth)
bool done = false;
ConsoleColor border = ConsoleColor.Magenta;
algoBoard.AlgorithmStep += (_, threshold) => {
Console.Clear();
step++;
if(done){
System.Console.WriteLine("The solved labyrinth is:");
}else if(step%2 == 0) {
System.Console.WriteLine($"Computing (threshold: {threshold}) [• ]");
}else {
System.Console.WriteLine($"Computing (threshold: {threshold}) [ •]");
}
//top border
Console.BackgroundColor = border;
for (var i=0; i< algoBoard.Board[0].Count + 2; i++){
Console.Write(" ");
}
Console.ResetColor();
Console.WriteLine();
foreach (var line in algoBoard.Board)
{ {
var charlist = line.Select((state) => CellStateUtil.ToInput(state)); FormattedLabRow(line);
var str = string.Join("", charlist); Console.WriteLine();
}
//left border
Console.BackgroundColor = border;
Console.Write(" ");
Console.ResetColor();
//labyrinth line
FormattedLabRow(str);
//right border var algoBoard = new IdaStar.WorkingBoard(labyrinth.Select((row) => row.ToList()).ToList());
Console.BackgroundColor = border; int step = 0;
Console.Write(" "); ConsoleColor border = ConsoleColor.Magenta;
Console.ResetColor(); bool printSteps = false;
Console.WriteLine(); Console.WriteLine();
Console.WriteLine("Show each step? (Y/N) ");
if(Console.ReadLine()?.Trim() == "Y") {
printSteps = true;
} }
//bottom border if(printSteps) {
Console.BackgroundColor = border; algoBoard.AlgorithmStep += (_, threshold) => {
for (var i=0; i< algoBoard.Board[0].Count + 2; i++){ PrintBoard(threshold, false);
Console.Write(" ");
}
Console.ResetColor();
Console.WriteLine();
Thread.Sleep(200);
// Console.ReadLine();
}; };
}
algoBoard.RunIdaStar(); algoBoard.RunIdaStar();
PrintBoard(0, true);
static void FormattedLabRow(string line) { static void FormattedLabRow(string line) {
char[] characters = line.ToCharArray(); char[] characters = line.ToCharArray();
@ -106,3 +78,83 @@ 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){
Console.Clear();
step++;
if(done){
Console.WriteLine("The solved labyrinth is:");
}else if(step%2 == 0) {
Console.WriteLine($"Computing (threshold: {threshold}) [• ]");
}else {
Console.WriteLine($"Computing (threshold: {threshold}) [ •]");
}
//top border
Console.BackgroundColor = border;
for (var i=0; i< algoBoard.Board[0].Count + 2; i++){
Console.Write(" ");
}
Console.ResetColor();
Console.WriteLine();
foreach (var line in algoBoard.Board)
{
var charlist = line.Select((state) => CellStateUtil.ToInput(state));
var str = string.Join("", charlist);
//left border
Console.BackgroundColor = border;
Console.Write(" ");
Console.ResetColor();
//labyrinth line
FormattedLabRow(str);
//right border
Console.BackgroundColor = border;
Console.Write(" ");
Console.ResetColor();
Console.WriteLine();
}
//bottom border
Console.BackgroundColor = border;
for (var i=0; i< algoBoard.Board[0].Count + 2; i++){
Console.Write(" ");
}
Console.ResetColor();
Console.WriteLine();
Thread.Sleep(200);
// Console.ReadLine();
}

10
labyrinth.txt

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

5
labyrinthOUT.txt

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