-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMain.py
30 lines (26 loc) · 783 Bytes
/
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
# -*- coding: UTF-8 -*-
import time
from ManhattanDistance import ManhattanDistance
from AStar import AStar
from Node import Node
from pprint import pprint
heuristic = ManhattanDistance()
astar = AStar(heuristic)
start = [
[ 1, 6, 7, 5],
[ 9, 3, 10, 2],
[13, 8, 4, 12],
[14, 11, 15, 0]
]
startTime = time.time()
startComplexity = heuristic.compute(
Node(start, [], None)
)
result = astar.solve(start)
if result is None:
print('No solution found')
else:
pprint(result)
print('Heuristic said at least %d moves were needed.' % startComplexity)
print('Actually solution is %d moves away. Best solution found guaranteed!' % len(result))
print('Solved in %d seconds.' % (time.time() - startTime))