Skip to content

Commit

Permalink
add: names for HexGrid
Browse files Browse the repository at this point in the history
  • Loading branch information
kurone02 committed Apr 12, 2024
1 parent 3a21a23 commit e108992
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion mesa/experimental/cell_space/grid.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,17 +199,28 @@ def _connect_cells_2d(self) -> None:
( 0, -1), ( 0, 1),
( 1, -1), ( 1, 0),
]
even_names = [
"top left", "top",
"left", "right",
"bottom left", "bottom",
]
odd_offsets = [
(-1, 0), (-1, 1),
( 0, -1), ( 0, 1),
( 1, 0), ( 1, 1),
]
odd_names = [
"top", "top right",
"left", "right",
"bottom", "bottom right",
]
# fmt: on

for cell in self.all_cells:
i = cell.coordinate[0]
offsets = even_offsets if i % 2 == 0 else odd_offsets
self._connect_single_cell_2d(cell, offsets=offsets)
names = even_names if i % 2 == 0 else odd_names
self._connect_single_cell_2d(cell, offsets=offsets, conn_names=names)

def _connect_cells_nd(self) -> None:
raise NotImplementedError("HexGrids are only defined for 2 dimensions")
Expand Down

0 comments on commit e108992

Please sign in to comment.