Skip to content

Commit

Permalink
examples: Convert hex_snowflake to simple namespace
Browse files Browse the repository at this point in the history
  • Loading branch information
rht authored and tpike3 committed May 22, 2022
1 parent c7fae5c commit c34e5a0
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 12 deletions.
4 changes: 2 additions & 2 deletions examples/hex_snowflake/hex_snowflake/cell.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from mesa import Agent
import mesa


class Cell(Agent):
class Cell(mesa.Agent):
"""Represents a single ALIVE or DEAD cell in the simulation."""

DEAD = 0
Expand Down
10 changes: 4 additions & 6 deletions examples/hex_snowflake/hex_snowflake/model.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
from mesa import Model
from mesa.time import SimultaneousActivation
from mesa.space import HexGrid
import mesa

from hex_snowflake.cell import Cell


class HexSnowflake(Model):
class HexSnowflake(mesa.Model):
"""
Represents the hex grid of cells. The grid is represented by a 2-dimensional array of cells with adjacency rules specific to hexagons.
"""
Expand All @@ -21,10 +19,10 @@ def __init__(self, width=50, height=50):
# computing their next state simultaneously. This needs to
# be done because each cell's next state depends on the current
# state of all its neighbors -- before they've changed.
self.schedule = SimultaneousActivation(self)
self.schedule = mesa.time.SimultaneousActivation(self)

# Use a hexagonal grid, where edges wrap around.
self.grid = HexGrid(width, height, torus=True)
self.grid = mesa.space.HexGrid(width, height, torus=True)

# Place a dead cell at each location.
for (contents, x, y) in self.grid.coord_iter():
Expand Down
7 changes: 3 additions & 4 deletions examples/hex_snowflake/hex_snowflake/server.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
from mesa.visualization.modules import CanvasHexGrid
from mesa.visualization.ModularVisualization import ModularServer
import mesa

from hex_snowflake.portrayal import portrayCell
from hex_snowflake.model import HexSnowflake

width, height = 50, 50

# Make a world that is 50x50, on a 500x500 display.
canvas_element = CanvasHexGrid(portrayCell, width, height, 500, 500)
canvas_element = mesa.visualization.CanvasHexGrid(portrayCell, width, height, 500, 500)

server = ModularServer(
server = mesa.visualization.ModularServer(
HexSnowflake, [canvas_element], "Hex Snowflake", {"height": height, "width": width}
)

0 comments on commit c34e5a0

Please sign in to comment.