-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.py
executable file
·80 lines (71 loc) · 1.73 KB
/
main.py
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
from lib.solver import PuzzleSolver
"""
PuzzleSolver.solve takes in one positional argument
goalState (bool) if it is set to True, the start
function will read the Goal State
else it will create a default Goal State
Examples
--------
$ python main.py < in.txt
Start State .............
+----+----+----+
| 08 | 07 | 06 |
+----+----+----+
| | 05 | 04 |
+----+----+----+
| 03 | 02 | 01 |
+----+----+----+
Goal State ..............
+----+----+----+
| | 08 | 07 |
+----+----+----+
| 06 | 05 | 04 |
+----+----+----+
| 03 | 02 | 01 |
+----+----+----+
**************************************
Algorithm name :: A star
Total optimal moves to solve :: 13
Total steps required to get to Goal :: 1022
Time required to find the Goal state :: 0.039 s
+----+----+----+
| | 08 | 07 |
+----+----+----+
| 06 | 05 | 04 |
+----+----+----+
| 03 | 02 | 01 |
+----+----+----+
**************************************
**************************************
Algorithm name :: BFS
Total optimal moves to solve :: 13
Total steps required to get to Goal :: 4366
Time required to find the Goal state :: 10.451 s
+----+----+----+
| | 08 | 07 |
+----+----+----+
| 06 | 05 | 04 |
+----+----+----+
| 03 | 02 | 01 |
+----+----+----+
**************************************
**************************************
Algorithm name :: DFS
Total optimal moves to solve :: 4831
Total steps required to get to Goal :: 8809
Time required to find the Goal state :: 50.325 s
+----+----+----+
| | 08 | 07 |
+----+----+----+
| 06 | 05 | 04 |
+----+----+----+
| 03 | 02 | 01 |
+----+----+----+
**************************************
"""
print("Use 0 to denote the space in the board")
solver = PuzzleSolver(n=3)
solver.start(goalState=False)
solver.solveAStart()
solver.solveBFS()
solver.solveDFS()