Skip to content

Commit

Permalink
Conway's Game of Life: Restructure
Browse files Browse the repository at this point in the history
- Rename cell.py to agents.py
- Flatten structure
- Remove unneeded viz
  • Loading branch information
EwoutH committed Oct 15, 2024
1 parent 98e9604 commit 18a1e1d
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 21 deletions.
14 changes: 6 additions & 8 deletions examples/basic/conways_game_of_life/Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,17 @@ Then open your browser to [http://127.0.0.1:8521/](http://127.0.0.1:8521/) and p

## Files

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

## Optional

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


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

Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import mesa
from mesa import Agent


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

DEAD = 0
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import mesa
from mesa import Model
from mesa.space import SingleGrid

from .cell import Cell
from agents import Cell


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

# Place a cell at each location, with some initialized to
# ALIVE and some to DEAD.
Expand Down
3 changes: 0 additions & 3 deletions examples/basic/conways_game_of_life/run.py

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import mesa

from .model import ConwaysGameOfLife
from .portrayal import portrayCell
from model import ConwaysGameOfLife
from portrayal import portrayCell

# Make a world that is 50x50, on a 250x250 display.
canvas_element = mesa.visualization.CanvasGrid(portrayCell, 50, 50, 250, 250)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
import numpy as np
import pandas as pd
import streamlit as st
from conways_game_of_life.model import ConwaysGameOfLife
from model import ConwaysGameOfLife

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

0 comments on commit 18a1e1d

Please sign in to comment.