Skip to content

Commit 18a1e1d

Browse files
committed
Conway's Game of Life: Restructure
- Rename cell.py to agents.py - Flatten structure - Remove unneeded viz
1 parent 98e9604 commit 18a1e1d

File tree

7 files changed

+17
-21
lines changed

7 files changed

+17
-21
lines changed

examples/basic/conways_game_of_life/Readme.md

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,19 +19,17 @@ Then open your browser to [http://127.0.0.1:8521/](http://127.0.0.1:8521/) and p
1919

2020
## Files
2121

22-
* ``conways_game_of_life/cell.py``: Defines the behavior of an individual cell, which can be in two states: DEAD or ALIVE.
23-
* ``conways_game_of_life/model.py``: Defines the model itself, initialized with a random configuration of alive and dead cells.
24-
* ``conways_game_of_life/portrayal.py``: Describes for the front end how to render a cell.
25-
* ``conways_game_of_life/server.py``: Defines an interactive visualization.
26-
* ``run.py``: Launches the visualization
22+
* ``agents.py``: Defines the behavior of an individual cell, which can be in two states: DEAD or ALIVE.
23+
* ``model.py``: Defines the model itself, initialized with a random configuration of alive and dead cells.
24+
* ``portrayal.py``: Describes for the front end how to render a cell.
25+
* ``st_app.py``: Defines an interactive visualization using Streamlit.
2726

2827
## Optional
2928

30-
* ``conways_game_of_life/app.py``: can be used to run the simulation via the streamlit interface.
29+
* ``conways_game_of_life/st_app.py``: can be used to run the simulation via the streamlit interface.
3130
* For this some additional packages like ``streamlit`` and ``altair`` needs to be installed.
32-
* Once installed, the app can be opened in the browser using : ``streamlit run app.py``
31+
* Once installed, the app can be opened in the browser using : ``streamlit run st_app.py``
3332

3433

3534
## Further Reading
3635
[Conway's Game of Life](https://en.wikipedia.org/wiki/Conway%27s_Game_of_Life)
37-

examples/basic/conways_game_of_life/conways_game_of_life/cell.py renamed to examples/basic/conways_game_of_life/agents.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import mesa
1+
from mesa import Agent
22

33

4-
class Cell(mesa.Agent):
4+
class Cell(Agent):
55
"""Represents a single ALIVE or DEAD cell in the simulation."""
66

77
DEAD = 0

examples/basic/conways_game_of_life/conways_game_of_life/model.py renamed to examples/basic/conways_game_of_life/model.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1-
import mesa
1+
from mesa import Model
2+
from mesa.space import SingleGrid
23

3-
from .cell import Cell
4+
from agents import Cell
45

56

6-
class ConwaysGameOfLife(mesa.Model):
7+
class ConwaysGameOfLife(Model):
78
"""
89
Represents the 2-dimensional array of cells in Conway's
910
Game of Life.
@@ -15,7 +16,7 @@ def __init__(self, width=50, height=50):
1516
"""
1617
super().__init__()
1718
# Use a simple grid, where edges wrap around.
18-
self.grid = mesa.space.SingleGrid(width, height, torus=True)
19+
self.grid = SingleGrid(width, height, torus=True)
1920

2021
# Place a cell at each location, with some initialized to
2122
# ALIVE and some to DEAD.

examples/basic/conways_game_of_life/conways_game_of_life/portrayal.py renamed to examples/basic/conways_game_of_life/portrayal.py

File renamed without changes.

examples/basic/conways_game_of_life/run.py

Lines changed: 0 additions & 3 deletions
This file was deleted.

examples/basic/conways_game_of_life/conways_game_of_life/server.py renamed to examples/basic/conways_game_of_life/server.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import mesa
22

3-
from .model import ConwaysGameOfLife
4-
from .portrayal import portrayCell
3+
from model import ConwaysGameOfLife
4+
from portrayal import portrayCell
55

66
# Make a world that is 50x50, on a 250x250 display.
77
canvas_element = mesa.visualization.CanvasGrid(portrayCell, 50, 50, 250, 250)

examples/basic/conways_game_of_life/app.py renamed to examples/basic/conways_game_of_life/st_app.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44
import numpy as np
55
import pandas as pd
66
import streamlit as st
7-
from conways_game_of_life.model import ConwaysGameOfLife
7+
from model import ConwaysGameOfLife
88

9-
model = st.title("Boltzman Wealth Model")
9+
model = st.title("Conway's Game of Life")
1010
num_ticks = st.slider("Select number of Steps", min_value=1, max_value=100, value=50)
1111
height = st.slider("Select Grid Height", min_value=10, max_value=100, step=10, value=15)
1212
width = st.slider("Select Grid Width", min_value=10, max_value=100, step=10, value=20)

0 commit comments

Comments
 (0)