-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
42 lines (39 loc) · 1.72 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
from puzzle import PuzzleNode
from puzzleSolver import PuzzleSolver
from visualizer import NpuzzleVisualizer
from puzzleParser import Parser
from argumentHandler import getExectionParameters
import time
if __name__ == "__main__":
execParameters = getExectionParameters()
parserIstance = Parser(execParameters.path)
parserIstance.loadData()
parserIstance.cleanPuzzle()
start_puzzle = parserIstance.flattenedPuzzle
firstNode = PuzzleNode(start_puzzle, parserIstance.shape, None)
endNode = PuzzleNode(execParameters.goal(parserIstance.shape), parserIstance.shape, None)
solver = PuzzleSolver(firstNode, endNode, execParameters.heuristic, execParameters.algorithm)
start = time.time()
goal = solver.solve()
puzzleStates = []
while goal:
puzzleStates.append(goal.puzzle)
goal = goal.parent
puzzleStates.reverse()
if execParameters.v:
vs = NpuzzleVisualizer(parserIstance.shape, puzzleStates, 400)
vs.startVisualization()
else:
for puzzle in puzzleStates:
if puzzle == puzzleStates[-1]:
PuzzleNode.printPuzzle(puzzle, parserIstance.shape)
print("--------------------------------------------")
print("Goal State !")
print("--------------------------------------------")
print(f"-Time taken: {time.time() - start}")
print(f"-Number of moves: {len(puzzleStates) - 1}")
print(f"-Time Complexity: {solver.timeComplexity}")
print(f"-Space Complexity: {solver.spaceComplexity}")
print("--------------------------------------------")
else:
PuzzleNode.printPuzzle(puzzle, parserIstance.shape)