-
Notifications
You must be signed in to change notification settings - Fork 0
/
Program.cs
87 lines (80 loc) · 2.91 KB
/
Program.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
using System;
using System.IO;
using n_queens_solution.solvers;
namespace n_queens_solution
{
class Program
{
static void Main(string[] args)
{
ISolver solver;
int dimension = 0;
string input = "";
do {
Console.WriteLine("Choose an algorithm and Dimension (Enter for Exit)");
Console.WriteLine("");
Console.WriteLine("BFS");
Console.WriteLine("DFS");
Console.WriteLine("UCS");
Console.WriteLine("For example [ DFS 8 ] means [ Solve 8 Queens with DFS ]");
string[] read = Console.ReadLine().Split(' ');
try
{
input = read[0].Trim();
if (input != "")
{
dimension = Convert.ToInt32(read[1]);
}
}
catch
{
Console.WriteLine("Invalid Input");
continue;
}
switch (input.ToUpper())
{
case "":
{
break;
}
case "BFS":
{
solver = new BFSSolver(dimension);
if (solver.Solve())
{
Console.WriteLine("Solved in " + solver.ElapsedTime + " ms");
File.AppendAllText("log.txt","BFS:"+ dimension+":"+solver.ElapsedTime + "ms\r\n" );
}
break;
}
case "DFS":
{
solver = new DFSSolver(dimension);
if (solver.Solve())
{
Console.WriteLine("Solved in " + solver.ElapsedTime + " ms");
File.AppendAllText("log.txt","DFS:"+ dimension+":"+solver.ElapsedTime + "ms\r\n" );
}
break;
}
case "UCS":
{
solver = new UCSSolver(dimension);
if (solver.Solve())
{
Console.WriteLine("Solved in " + solver.ElapsedTime + " ms");
File.AppendAllText("log.txt","UCS:"+ dimension+":"+solver.ElapsedTime + "ms\r\n" );
}
break;
}
default:
{
Console.WriteLine("Invalid input");
break;
}
}
Console.WriteLine("----------------------------");
} while (input != "");
}
}
}