This is a Python implementation of Conway's Game of Life using the Pygame library. Conway's Game of Life is a cellular automaton that simulates the evolution of a grid of cells based on a simple set of rules. Cells can be in one of two states, alive or dead, and they evolve over generations according to these rules.
- Python 3.x
- Pygame library
-
Clone this repository to your local machine:
git clone https://github.com/yourusername/conways-game-of-life.git
-
Install the Pygame library if you haven't already:
pip install pygame
To run the Conway's Game of Life simulation, follow these steps:
-
Navigate to the project directory:
cd conways-game-of-life -
Run the
conways_game_of_life.pyscript:python conways_game_of_life.py
- Left Mouse Button: Click on a cell to toggle its state (alive or dead).
- Spacebar: Start or pause the simulation.
- 'c' Key: Clear the grid, reset all cells to the dead state, and pause the simulation.
- 'g' Key: Generate a random pattern of cells on the grid.
- 'Esc' Key: Quit the simulation.
The simulation follows these rules:
- Any live cell with 2 or 3 live neighbors survives.
- Any dead cell with exactly 3 live neighbors becomes a live cell.
- All other live cells die in the next generation.
You can customize various parameters in the conways_game_of_life.py script:
WIDTHandHEIGHT: Set the dimensions of the simulation window.TILE_SIZE: Adjust the size of each cell on the grid.FPS: Control the frames per second for the simulation speed.update_freq: Set the generation update frequency.gen(num): Modify the initial random pattern generation.
Feel free to contribute to this project by adding features, fixing bugs, or improving the code. You can submit pull requests to the GitHub repository.
This project is licensed under the MIT License. See the LICENSE file for details.
- Pygame for the graphics and game development library.
- Conway's Game of Life for the fascinating cellular automaton concept.