The Game of Life is a cellular automaton created by John H. Conway in 1970. The game is a zero-player game in which an initially configured 2D grid of cells evolves according to the Game of Life ruleset.
Built using Python 3.14.0, this implementation of Conway's Game of Life allows the user to easily run the Game of Life using a 2D grid of chosen number of rows and columns in either a MacOS or Windows terminal/console.
This project is licensed under the terms of the MIT license.
Using the following ruleset the 2D grid of cells will evolve from generation to generation until it reaches a static state of either all dead cells or a mix of still, oscillating, or moving (spaceship) cells.
- Underpopulation - If a live cell is surrounded by fewer than two surrounding neighbours, it dies and does not make it to the next generation.
- Equilibrium - If a live cell is surrounded by two or three living neighbors, the cell stays alive and makes it to the next generation.
- Overpopulation - If a live cell is surrounded by more than three living neighbors, the cell dies and does not make it to the next generation.
- Reproduction - If a dead cell is surrounded by three living neighbor,s the cell stays alive and makes it to the next generation.
Python: High-level, interpreted programming language known for its simplicity, readability, and versatility across web development, data science, automation, and AI.
TOML: Minimal configuration file format thatβs convenient to read and parse and primarily used for configuration, separating code from settings for flexibility.
Visual Studio Code: Primary code editor used for development.
- Implement the Game of Life algorithm, including the life grid and the seeds or patterns
- Provide a way to visualize the life grid and its evolution
- Allow the user to set a pattern and run the game a given number of generations Following these ideas, here's the directory structure for this Python Implementation of the Game of Life project:
Python-Implementation-Conways_Game_of_life/ βββ __pycache__/ # Compiled Python bytecode cache β βββ __init__.cpython-314.pyc β βββ __main__.cpython-314.pyc β βββ cli.cpython-314.pyc β βββ grid.cpython-314.pyc β βββ patterns.cpython-314.pyc β βββ views.cpython-314.pyc β βββ rplife/ # Core Python package for the project β βββ __init__.py # Marks rplife as a Python package β βββ __main__.py # Entry point for running the program β βββ cli.py # Command-line interface logic β βββ grid.py # Grid implementation (core game logic) β βββ patterns.py # Predefined Conwayβs Game of Life patterns β βββ patterns.toml # Configuration file for patterns β βββ views.py # Handles rendering or visualization β βββ .DS_Store # macOS system file (can be ignored) βββ LICENSE # License information for the project βββ README.md # Project documentation βββ example.gif # Demo animation for README βββ pyproject.toml # Project metadata & build configuration This project is built using Python 3.14.0 and requires that the user has at least Python 3 installed in order to run the program. Python 3+ can be installed here.
cd "Path to directory where you want to clone the repo" git clone https://github.com/deep0505sharma/Python-Implementation-Conways_Game_of_life.git cd Python-Implementation-Conways_Game_of_life python3 -m rplife -aThe project has a user-friendly command-line interface that allows you to run it with different options. You can run the game/project with a single pattern, with all the available patterns, and more. Before doing this, you need to setup the virtual python environment in your system and have pyproject.toml file present in the project folder to run the project using single commands.
python3 -m venv myvenv source myvenv/bin/activate python3 -m pip install -e .Running the project as a stand-alone CLI application.
Python-Implementation-Conways_Game_of_life --all #will show all available patterns in a sequence Python-Implementation-Conways_Game_of_life -p "Beacon" -g 10 #will show next 10 gens of Beacon pattern Python-Implementation-Conways_Game_of_life --version #will show the program's version number and namefrom rplife.views import CursesView, TextView from rplife.patterns import get_pattern TextView(get_pattern("Glider Gun"), gen=100).show()To implement and evolve any other random pattern of your choice
from rplife import grid, patterns blinker = patterns.Pattern("Hearts", {(3, 1), (4, 2), (2, 2),(3,2),(3,3)}) grid = grid.LifeGrid(blinker) print(grid.as_string((0, 0, 5, 5)))
grid.evolve() print(grid.as_string((0, 0, 5, 5)))
- Implemented Conwayβs Game of Life using Python and object-oriented programming.
- To make the game usable, built a user-friendly command-line interface using argparse. In the process, Iβve learned how to structure and organize a CLI app and set up the application for distribution and installation.
- Learned about TOML config files and writing them.
Go a step further by implementing a few additional features. Here are some ideas for new features:
- Implement other views: Having other views apart from the one based on curses would be a great addition to the project. For example, writing a Tkinter view where we can display the life grid in a GUI window.
- Add exciting new life patterns: Adding new life patterns to patterns.toml will allow exploring other behaviors of the game.
- Change the rules: So far, the project has been implemented with the traditional rules, where dead cells with three living neighbors are born, and living cells with two or three living neighbors survive. But there are several variations that use different rules to evolve to a new generation. Changing the rules allows experiencing other life-like universes.
if youLiked : β Star_Repository # Thank You! π
