-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnode.py
More file actions
38 lines (29 loc) · 958 Bytes
/
node.py
File metadata and controls
38 lines (29 loc) · 958 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
# -*- coding: utf-8 -*-
"""
Created on Wed May 13 17:19:16 2020
@author: nguye
"""
class Node:
def __init__(self, x, y, g, h):
self.x = x
self.y = y
self.g = g
self.h = h
def __eq__(self, obj):
if not isinstance(obj, Node):
return NotImplemented
return self.x == obj.x and self.y == obj.y
def __lt__(self, obj):
if not isinstance(obj, Node):
return NotImplemented
return (self.g + self.h) < (obj.g + obj.h)
'''
Returns Euclidean distance between neighbor and current node.
'''
def getGScore(self, neighbor):
return ((self.x - neighbor.x)**2 + (self.y - neighbor.y)**2)**1/2
'''
Returns the Manhattan distance between current and end node
'''
def getHScore(self, end):
return abs(self.x - end.x) + abs(self.y - end.y)