-
Notifications
You must be signed in to change notification settings - Fork 0
/
puzzle.py
56 lines (43 loc) · 1.15 KB
/
puzzle.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
class PuzzleNode():
def __init__(self, puzzle, dim, parent=None):
self._puzzle = puzzle
self._hash = ''.join(str(x) for x in puzzle)
self._dim = dim
self._swap = 0
self._parent = parent
self._depth = parent.depth + 1 if parent != None else 0
self._cost = 0
@property
def cost(self):
return self._cost
@property
def dim(self):
return self._dim
@property
def puzzle(self):
return self._puzzle
@property
def parent(self):
return self._parent
@property
def depth(self):
return self._depth
@cost.setter
def cost(self, value):
self._cost = value
def __lt__(self, other):
return self.cost < other.cost
@staticmethod
def printPuzzle(puzzle, dim):
for block in puzzle:
print(f"|{block:>3}", end="{}".format('|\n' if (puzzle.index(block) + 1) % dim == 0 else ''))
print()
@property
def hash(self):
return self._hash
@property
def swap(self):
return self._swap
@swap.setter
def swap(self, swap):
self._swap = swap