Skip to content

Commit

Permalink
[pre-commit.ci] auto fixes from pre-commit.com hooks
Browse files Browse the repository at this point in the history
for more information, see https://pre-commit.ci
  • Loading branch information
pre-commit-ci[bot] committed Oct 29, 2024
1 parent cbdd444 commit 0585b99
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 7 deletions.
20 changes: 14 additions & 6 deletions examples/color_patches/color_patches/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ class ColorCell(mesa.Agent):
"""
Represents a cell's opinion (visualized by a color)
"""

OPINIONS = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]

def __init__(self, pos, unique_id, model, initial_state):
Expand Down Expand Up @@ -91,16 +92,16 @@ def __init__(self, width=20, height=20):
# for (contents, col, row) in self._grid.coord_iter():
# replaced content with _ to appease linter
for _, (row, col) in self._grid.coord_iter():

cell = ColorCell(
(row, col), row+col*row, self, ColorCell.OPINIONS[self.random.randrange(0, 16)]
(row, col),
row + col * row,
self,
ColorCell.OPINIONS[self.random.randrange(0, 16)],
)
self._grid.place_agent(cell, (row, col))

self.running = True



def step(self):
"""
Perform the model step in three stages:
Expand Down Expand Up @@ -130,8 +131,15 @@ def change_opinion(self, radius=2):
- Randomly choose an opinion from `ColorCell.OPINIONS`.
- Set each agent's `next_state` within this neighborhood to the selected opinion.
"""
x, y = self.random.randrange(self.grid.width), self.random.randrange(self.grid.height)
agents = list(self.grid.iter_neighbors((x, y), moore=True, include_center=True, radius=radius))
x, y = (
self.random.randrange(self.grid.width),
self.random.randrange(self.grid.height),
)
agents = list(
self.grid.iter_neighbors(
(x, y), moore=True, include_center=True, radius=radius
)
)
opinion = ColorCell.OPINIONS[self.random.randrange(0, 16)]

for agent in agents:
Expand Down
3 changes: 2 additions & 1 deletion examples/color_patches/color_patches/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
handles the definition of the canvas parameters and
the drawing of the model representation on the canvas
"""

import webbrowser

import mesa
Expand Down Expand Up @@ -64,4 +65,4 @@ def color_patch_draw(cell):
{"width": grid_rows, "height": grid_cols},
)

webbrowser.open('http://127.0.0.1:8521')
webbrowser.open("http://127.0.0.1:8521")

0 comments on commit 0585b99

Please sign in to comment.