-
Notifications
You must be signed in to change notification settings - Fork 0
/
klotski.py
51 lines (49 loc) · 1.21 KB
/
klotski.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
import math
import random
import copy
from klotskiHelper import *
goal = initNBoard(9)
board = shuffleBoard(initNBoard(9))
game = Klotski(board,goal)
arr = game.getBoard()
print("Starting array:\n"+str(arr))
print("goal:\n"+str(game.getGoal())+"\n")
queue = []
states = []
depth = 0
maxDepth = 1000
queue.append(game)
result=""
print("Doing a Breadth First Search")
result = graphSearch("bf", queue, states, depth, maxDepth)
if result:
print("Path is:")
while True:
print(result.board)
if result.parent:
result = result.parent
else:
break
else:
print("didnt find with maximum depth = " + str(maxDepth))
game = Klotski(board,goal)
arr = game.getBoard()
print("Starting array:\n"+str(arr))
print("goal:\n"+str(game.getGoal())+"\n")
queue = []
states = []
queue.append(game)
depth = 0
maxDepth = 1000
print("Doing a Depth First Search")
result = graphSearch("df", queue, states, depth, maxDepth)
if result:
print("Path is:")
while True:
print(result.board)
if result.parent:
result = result.parent
else:
break
else:
print("didnt find with maximum depth = ", str(maxDepth))