-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnew_main.cpp
40 lines (34 loc) · 864 Bytes
/
new_main.cpp
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
#include <iostream>
#include "Solver.h"
using namespace std;
int main()
{
char initial[10] = "235714086";
//char initial[10] = "123045786";
char goal[10] = "123456780";
int blank = 0, inversions = 0;
for (int i = 0; i < 9; i++)
if (initial[i] == '0') {
blank = i;
break;
}
for (int i = 0; i < 9; i++)
{
for (int j = 0; j < i; j++)
{
if (initial[j] > initial[i] && initial[j] != '0' && initial[i] != '0')
inversions++;
}
}
if (inversions % 2 == 1)
{
cout << "Puzzle is unsolvable!";
return 0;
}
Solver solver = Solver(initial, goal);
cout << "Depth-first search completed in " << solver.dfs(blank) << " steps." << endl;
cout << "Breadth-first search completed in " << solver.bfs(blank) << " steps." << endl;
cout << "Astar search completed in " << solver.Astar(blank) << " steps." << endl;
cout << endl;
return 0;
}