mirror of
https://github.com/dancojocaru2000/ai-project-idastar.git
synced 2025-04-20 23:03:54 +03:00
Merge branch 'darius'
This commit is contained in:
commit
88626505a7
4 changed files with 118 additions and 4 deletions
3
.vscode/launch.json
vendored
3
.vscode/launch.json
vendored
|
@ -17,7 +17,8 @@
|
||||||
"args": [],
|
"args": [],
|
||||||
"cwd": "${workspaceFolder}",
|
"cwd": "${workspaceFolder}",
|
||||||
// For more information about the 'console' field, see https://aka.ms/VSCode-CS-LaunchJson-Console
|
// For more information about the 'console' field, see https://aka.ms/VSCode-CS-LaunchJson-Console
|
||||||
"console": "internalConsole",
|
"console": "integratedTerminal",
|
||||||
|
"internalConsoleOptions": "neverOpen",
|
||||||
"stopAtEntry": false
|
"stopAtEntry": false
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|
107
Program.cs
107
Program.cs
|
@ -1,5 +1,106 @@
|
||||||
// See https://aka.ms/new-console-template for more information
|
using IdaStar;
|
||||||
Console.WriteLine("Hello, World!");
|
|
||||||
Console.WriteLine("this is slow");
|
string[] labyrinthIN = System.IO.File.ReadAllLines(@"C:\UNI\AI\IDAstar\labyrinth.txt");
|
||||||
|
|
||||||
|
|
||||||
|
System.Console.WriteLine("The input labyrinth: ");
|
||||||
|
foreach (string line in labyrinthIN)
|
||||||
|
{
|
||||||
|
FormattedLabRow(line);
|
||||||
|
}
|
||||||
|
|
||||||
|
var algoBoard = new IdaStar.WorkingBoard(labyrinthIN.Select((row) => row.ToList()).ToList());
|
||||||
|
int step = 0;
|
||||||
|
bool done = false;
|
||||||
|
ConsoleColor border = ConsoleColor.Magenta;
|
||||||
|
algoBoard.AlgorithmStep += (_) => {
|
||||||
|
Console.Clear();
|
||||||
|
step++;
|
||||||
|
if(done){
|
||||||
|
System.Console.WriteLine("The solved labyrinth is:");
|
||||||
|
}else if(step/2 == 0) {
|
||||||
|
System.Console.WriteLine("Computing [· ]");
|
||||||
|
}else {
|
||||||
|
System.Console.WriteLine("Computing [ ·]");
|
||||||
|
}
|
||||||
|
|
||||||
|
//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();
|
||||||
|
};
|
||||||
|
|
||||||
|
algoBoard.RunIdaStar();
|
||||||
|
|
||||||
|
|
||||||
|
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();
|
||||||
|
}
|
7
labyrinth.txt
Normal file
7
labyrinth.txt
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
##########
|
||||||
|
#S # # F
|
||||||
|
### # ## #
|
||||||
|
# # #
|
||||||
|
## # #
|
||||||
|
# # ### #
|
||||||
|
##########
|
5
labyrinthOUT.txt
Normal file
5
labyrinthOUT.txt
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
###S#
|
||||||
|
# p#
|
||||||
|
##pp#
|
||||||
|
#pp##
|
||||||
|
#F###
|
Loading…
Add table
Reference in a new issue