mirror of
https://github.com/dancojocaru2000/ai-project-idastar.git
synced 2025-02-23 00:49:34 +02:00
Added option to skip showing all the steps
fixed bugs and such
This commit is contained in:
parent
65108902e6
commit
4818450ced
2 changed files with 74 additions and 51 deletions
118
Program.cs
118
Program.cs
|
@ -1,9 +1,10 @@
|
||||||
using IdaStar;
|
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)
|
foreach (string line in labyrinthIN)
|
||||||
{
|
{
|
||||||
FormattedLabRow(line);
|
FormattedLabRow(line);
|
||||||
|
@ -12,60 +13,23 @@ foreach (string line in labyrinthIN)
|
||||||
|
|
||||||
var algoBoard = new IdaStar.WorkingBoard(labyrinthIN.Select((row) => row.ToList()).ToList());
|
var algoBoard = new IdaStar.WorkingBoard(labyrinthIN.Select((row) => row.ToList()).ToList());
|
||||||
int step = 0;
|
int step = 0;
|
||||||
bool done = false;
|
|
||||||
ConsoleColor border = ConsoleColor.Magenta;
|
ConsoleColor border = ConsoleColor.Magenta;
|
||||||
|
bool printSteps = false;
|
||||||
|
|
||||||
|
Console.WriteLine();
|
||||||
|
Console.WriteLine("Show each step? (Y/N) ");
|
||||||
|
if(Console.ReadLine()?.Trim() == "Y") {
|
||||||
|
printSteps = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(printSteps) {
|
||||||
algoBoard.AlgorithmStep += (_, threshold) => {
|
algoBoard.AlgorithmStep += (_, threshold) => {
|
||||||
Console.Clear();
|
PrintBoard(threshold, false);
|
||||||
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));
|
|
||||||
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();
|
|
||||||
};
|
};
|
||||||
|
}
|
||||||
|
|
||||||
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 +70,55 @@ static void FormattedLabRow(string line) {
|
||||||
}
|
}
|
||||||
Console.ResetColor();
|
Console.ResetColor();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
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();
|
||||||
|
}
|
||||||
|
|
|
@ -1,7 +1,14 @@
|
||||||
##########
|
##########
|
||||||
#S # # F
|
#S # # #
|
||||||
### # ## #
|
### # ## #
|
||||||
# # #
|
# # #
|
||||||
## # #
|
## # #
|
||||||
# # ### #
|
# # ### #
|
||||||
|
#### ####
|
||||||
|
##### ####
|
||||||
|
# # F
|
||||||
|
### #### #
|
||||||
|
# # #
|
||||||
|
## # #
|
||||||
|
# # ### #
|
||||||
##########
|
##########
|
Loading…
Add table
Reference in a new issue