This repository was archived by the owner on Nov 13, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnode.py
68 lines (52 loc) · 1.59 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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
import math
class Node:
isOpen = False
isClosed = False
isBeginning = False
isDestination = False
isTraversable = True
isPath = False
weight = 1
gValue = 100000
hValue = 0
parentX = -1
parentY = -1
def __init__(self, xCord, yCord):
self.cordX = xCord
self.cordY = yCord
self.fValue = self.gValue + self.hValue
#Funkcja obliczająca odległość euklidesową do punktu końcowego
def hEuc(self,xDestination , yDestination):
distance = math.sqrt(pow(xDestination - self.cordX, 2) + pow(yDestination - self.cordY, 2))
distance = round(distance,3)
self.hValue = distance
self.resetF()
def hMan(self,xDestination , yDestination):
distance = abs(xDestination - self.cordX) + abs(yDestination - self.cordY)
self.hValue = distance
self.resetF()
def resNode(self):
self.isOpen = False
self.isClosed = False
self.isPath = False
self.gValue = 100000
self.hValue = 0
self.parentX = -1
self.parentY = -1
def resetF(self):
self.fValue = self.gValue + self.hValue
def printCoords(self):
print(self.cordX, end=' ')
print(self.cordY)
def checkNode(self, node):
x = node.cordX
y = node.cordY
g = node.gValue + self.weight
if self.isClosed | (self.isTraversable == False) :
return
if self.gValue > g:
self.gValue = g
self.parentX = x
self.parentY = y
self.resetF()
self.isOpen = True