-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNodeClass.py
More file actions
38 lines (31 loc) · 1023 Bytes
/
Copy pathNodeClass.py
File metadata and controls
38 lines (31 loc) · 1023 Bytes
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
class Node:
def __init__(self,x,y,parent,hValue,gValue):
self.x=x
self.y=y
self.parent=parent
self.hValue=hValue
self.gValue=gValue
self.fValue=gValue+hValue
def getXY(self):
return (self.x,self.y)
def getParent(self):
return self.parent
def getFValue(self):
return self.fValue
def updateGValue(self,newValue,newParent):
self.gValue=newValue
self.fValue=self.hValue+newValue
self.parent=newParent
def getGValue(self):
return self.gValue
def __str__(self):
coord=str(self.getXY())
coordParent=str(self.getParent().getXY())
Fval=str(self.getFValue())
return "Il nodo ha coordinate: "+coord+"\nLe coordinate del padre sono: "+coordParent+"\nIl suo valore di f(n)= "+Fval
def __eq__(self, other):
if isinstance(other,Node):
if(self.x==other.x and self.y==other.y):
return True
else:
return False