A Python implementation of Conway's Game of Life on a hexagonal grid, extended with custom rules for aging, random resurrection and no-repeat death causes.
This project implements a variant of Conway's Game of Life on a hexagonal grid, adding mechanics for cell aging, periodic random revivals, and preventing consecutive deaths for the same cause. The simulation is built with Pygame for rendering and NumPy for efficient array operations.
-
Clone the repository:
git clone https://github.com/its-adityagoyal/Game-of-Life-HexagonalGrid.git cd Game-of-Life-HexagonalGrid
-
(Optional) Create and activate a virtual environment:
python -m venv venv source venv/bin/activate # On Windows use `venv\Scripts\activate`
-
Install dependencies:
pip install -r requirements.txt
Run the simulation:
python main.py
- Draw initial live cells by clicking and dragging with the mouse.
- Press S to Start the simulation and E to Exit.
- Generated frames will be saved as
output1.png
,output2.png
, etc.
In our implementation, each hexagon in the grid is mapped to a 2D array index by projecting its center onto Cartesian coordinates. By computing the row and column offsets (using the hexagon’s radius and the √3/2 vertical spacing), we can translate any hex cell into a (row, col) pair in a regular 2D array.
Neighbours of a hex cell “shift” differently depending on whether the cell sits in an even‑numbered or odd‑numbered row. In the illustration below, you can see:
Even rows: neighbours on one side are pushed slightly right
Odd rows: neighbours on the opposite side are pushed slightly left
All of the custom rules for this hexagonal automaton are defined in rules.txt
Below are sample frames from the simulation:
(Place additional illustrative images in the Output/
folder.)
Game-of-Life-HexagonalGrid/
├── main.py # Main simulation script
├── requirements.txt # Pinned dependencies
├── rules.txt # Custom rules
├── README.md # Project documentation
├── Output/ # Sample frames and diagrams
| ├── output1.png
| ├── output2.png
| .
└── images/ # Images for theory purpose
├── hex_to_array_mapping.png
Thank you for your interest in improving Game‑of‑Life‑HexagonalGrid! To contribute:
- Fork the repository
- Create a new branch
git checkout -b feature/YourFeatureName
- Make your changes and commit
- Push to your fork
git push origin feature/YourFeatureName
- Open a Pull Request against main in this repo
This project is licensed under the MIT License. See LICENSE for details.