-
Notifications
You must be signed in to change notification settings - Fork 74
Expand file tree
/
Copy pathnode.py
More file actions
53 lines (42 loc) · 1.37 KB
/
node.py
File metadata and controls
53 lines (42 loc) · 1.37 KB
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
# -*- coding: utf-8 -*-
class Node(object):
"""
basic node, saves X and Y coordinates on some grid and determine if
it is walkable.
"""
def __init__(self, x=0, y=0, walkable=True, weight=1):
# Coordinates
self.x = x
self.y = y
# Whether this node can be walked through.
self.walkable = walkable
# used for weighted algorithms
self.weight = weight
# values used in the finder
self.cleanup()
def __lt__(self, other):
"""
nodes are sorted by f value (see a_star.py)
:param other: compare Node
:return:
"""
return self.f < other.f
def cleanup(self):
"""
reset all calculated values, fresh start for pathfinding
"""
# cost from this node to the goal (for A* including the heuristic)
self.h = 0.0
# cost from the start node to this node
# (calculated by distance function, e.g. including diagonal movement)
self.g = 0.0
# overall cost for a path using this node (f = g + h )
self.f = 0.0
self.opened = 0
self.closed = False
# used for backtracking to the start point
self.parent = None
# used for recurion tracking of IDA*
self.retain_count = 0
# used for IDA* and Jump-Point-Search
self.tested = False