Conway's Game of Life Implementation in Python
Welcome to this repository containing an implementation of Conway's Game of Life in Python. This simple yet fascinating cellular automaton simulates the evolution of a grid of cells based on a set of rules. The game showcases emergent behavior as cells live, die, and reproduce over generations.
Table of Contents
Introduction
The provided code implements Conway's Game of Life, which is a cellular automaton devised by mathematician John Conway in 1970. The game consists of a grid of cells, each of which can be in one of two states: alive (1) or dead (0). The state of a cell evolves over generations according to the following rules:
- Any live cell with fewer than two live neighbors dies (underpopulation).
- Any live cell with two or three live neighbors lives on to the next generation.
- Any live cell with more than three live neighbors dies (overpopulation).
- Any dead cell with exactly three live neighbors becomes a live cell (reproduction).
These simple rules can lead to complex and captivating patterns.
Dependencies
To run this implementation, you need:
- Python 3.x
- The
random
module (usually included in Python standard library)
Installation
-
Clone this repository to your local machine:
git clone https://github.com/joethesaint/game-of-life-python.git cd game-of-life-python
-
Ensure you have Python 3.x installed. You can check by running:
python3 --version
If Python is not installed, you can download it from the official Python website.
Usage
-
Navigate to the project directory containing the
game_of_life.py
file. -
Open the
game_of_life.py
file in your preferred text editor or IDE. -
Inside the file, you'll find a function
random_state(width, height)
which generates a random initial state for the game. -
If you want to customize the grid size, modify the
width
andheight
parameters of therandom_state
function. -
Run the
game_of_life.py
script using the following command:python3 game_of_life.py
-
The script will generate a random initial state and simulate the evolution of the grid based on the rules of Conway's Game of Life. Each generation will be printed to the console.
Example
Here's a brief example of how to run the code:
git clone https://github.com/joethesaint/game-of-life-python.git
cd game-of-life-python
python3 game_of_life.py
You will see the grid evolve with each generation, displaying the changes in cell states over time.
Contributions
Contributions to this repository are welcome! If you have any improvements or feature suggestions, feel free to fork this repository, make your changes, and submit a pull request.
License
This project is licensed under the MIT License - see the LICENSE file for details.
Have fun exploring Conway's Game of Life and experimenting with different initial configurations! If you have any questions or run into issues, don't hesitate to ask for help.