-
Notifications
You must be signed in to change notification settings - Fork 0
/
node.py
38 lines (30 loc) · 989 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
38
from settings import *
class Node:
def __init__(self, coordinates, walkable, weight = 0):
# wall or path
self.walkable = walkable
# weight (for future adjustments)
self.weight = weight
# coordinates in maze
self.x, self.y, self.z = coordinates
# distance from starting node
self.G_cost = 0
# distance from end node
self.H_cost = 0
# parent
self.parent = None
# color of node
if walkable:
self.color = BG_COLOR
else:
self.color = WALL
self.heapIndex = 0
def cmp(self, a, b):
return int(a > b) - int(a < b)
def get_F_cost(self):
return self.G_cost + self.H_cost
def compareTo(self, nodeToCompare):
compare = self.cmp(self.get_F_cost(), nodeToCompare.get_F_cost())
if compare == 0:
compare = self.cmp(self.H_cost, nodeToCompare.H_cost)
return -compare