-
Notifications
You must be signed in to change notification settings - Fork 0
/
Node.py
50 lines (37 loc) · 1.26 KB
/
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
39
40
41
42
43
44
45
46
47
48
49
50
import constants
class Node:
"""The node the robot uses to represent a case"""
# The x position
x = None
# The y position
y = None
# The previous node, chosen by efficiency
came_from = None
# The weight value of this node
weight = 0
# The cost of getting from the start node to that node
g_score = 0
# The total cost of getting from the start node to the goal, using this node
f_score = constants.INFINITY
def __init__(self, x, y, cell):
"""Create a new node"""
self.x = x
self.y = y
# Weight calculation
if cell is not None:
if cell is constants.EMPTY:
self.weight = constants.EMPTY_WEIGHT
if cell is constants.DUST:
self.weight = constants.DUST_WEIGHT
if cell is constants.JEWEL:
self.weight = constants.JEWEL_WEIGHT
if cell is constants.BOTH:
self.weight = constants.BOTH_WEIGHT
self.g_score = self.weight
def equals(self, node):
return (self.x == node.x) and (self.y == node.y)
def belongs_to(self, nodes):
for node in nodes:
if (self.x == node.x) and (self.y == node.y):
return True
return False