-
Notifications
You must be signed in to change notification settings - Fork 0
/
Node.py
39 lines (34 loc) · 1.3 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
class Node:
def __init__(self, x, y):
self.x = x
self.y = y
self.f = 0
self.g = 0 # float('inf')
self.h = 0
self.neighbors = []
self.previous = None
self.obstacle = False
self.co2 = 0
self.waiting_time = 0
def add_neighbors(self, grid, columns, rows):
neighbor_x = self.x
neighbor_y = self.y
if neighbor_x < columns - 1:
self.neighbors.append(grid[neighbor_x + 1][neighbor_y])
if neighbor_x > 0:
self.neighbors.append(grid[neighbor_x - 1][neighbor_y])
if neighbor_y < rows - 1:
self.neighbors.append(grid[neighbor_x][neighbor_y + 1])
if neighbor_y > 0:
self.neighbors.append(grid[neighbor_x][neighbor_y - 1])
# diagonals
"""
if neighbor_x > 0 and neighbor_y > 0:
self.neighbors.append(grid[neighbor_x-1][neighbor_y-1])
if neighbor_x < columns -1 and neighbor_y > 0:
self.neighbors.append(grid[neighbor_x+1][neighbor_y-1])
if neighbor_x > 0 and neighbor_y <rows -1:
self.neighbors.append(grid[neighbor_x-1][neighbor_y+1])
if neighbor_x < columns -1 and neighbor_y < rows -1:
self.neighbors.append(grid[neighbor_x+1][neighbor_y+1])
"""