-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathNode.py
37 lines (28 loc) · 982 Bytes
/
Node.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
import copy
class Node:
# Node class for A-Star Search Algorithm
def __init__(self, state, parent, action, depth, heuristic):
self._state = state
self._parent = parent
self._action = action
self._depth = depth
self._heuristic = heuristic
self._cost = None
def getState(self):
return copy.deepcopy(self._state)
def getParent(self):
return self._parent
def getAction(self):
return self._action
def getDepth(self):
return self._depth
def getCost(self):
if not self._cost: # calculate if the cost has not been set
# f(n) = g(n) + h(n)
self._cost = self._depth + self._heuristic.calc_SCBD(self)
return self._cost
def getValuePos(self, value):
for i in range(4):
for j in range(4):
if self._state[i][j] == str(value):
return i, j