start on hexgrids
This commit is contained in:
parent
199d6c1908
commit
4f45d1f32d
@ -326,3 +326,33 @@ class Grid:
|
|||||||
print(spacer, end="")
|
print(spacer, end="")
|
||||||
|
|
||||||
print()
|
print()
|
||||||
|
|
||||||
|
|
||||||
|
class HexGrid(Grid):
|
||||||
|
"""
|
||||||
|
https://www.redblobgames.com/grids/hexagons/#coordinates-cube
|
||||||
|
Treat as 3d Grid
|
||||||
|
+y -x +z
|
||||||
|
y x z
|
||||||
|
yxz
|
||||||
|
z x y
|
||||||
|
-z +x -y
|
||||||
|
"""
|
||||||
|
def __init__(self, default=False):
|
||||||
|
super().__init__(default=default)
|
||||||
|
|
||||||
|
def getNeighboursOf(self, pos: Coordinate, includeDefault: bool = False, includeDiagonal: bool = None) \
|
||||||
|
-> List[Coordinate]:
|
||||||
|
"""
|
||||||
|
includeDiagonal is just here because of signature reasons, makes no difference in a hex grid
|
||||||
|
"""
|
||||||
|
vectors = [
|
||||||
|
Coordinate(-1, 1, 0), # nw
|
||||||
|
Coordinate(-1, 0, 1), # ne
|
||||||
|
Coordinate(0, -1, 1), # e
|
||||||
|
Coordinate(1, -1, 0), # se
|
||||||
|
Coordinate(1, 0, -1), # sw
|
||||||
|
Coordinate(0, 1, -1), # w
|
||||||
|
]
|
||||||
|
|
||||||
|
return [pos + v for v in vectors if includeDefault or self.get(pos + v) != self.__default]
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user