-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNode.py
More file actions
25 lines (18 loc) · 879 Bytes
/
Node.py
File metadata and controls
25 lines (18 loc) · 879 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
from helpers import getOppositeSide
class Node:
def __init__(self, hexagon, dimensions=None):
if (dimensions == None):
raise ValueError("Dimension not defined")
self.dimensions = dimensions
self.connections = [[], []]
self.hexagon = hexagon
def connectNode(self, other, direction, weight):
otherDimensions = other.dimensions
commonDimension = [d for d in self.dimensions if d in otherDimensions][0]
selfIndex = [i for i in range(2) if self.dimensions[i] == commonDimension][0]
otherIndex = [i for i in range(2) if other.dimensions[i] == commonDimension][0]
self.connections[selfIndex].append((other, direction, weight))
other.connections[otherIndex].append((self, getOppositeSide(direction), weight))
return commonDimension
def isPortal(self):
return self.dimensions[0] != self.dimensions[1]