Skip to content

its-adityagoyal/Game-of-Life-HexagonalGrid

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

34 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Hexagonal Game of Life

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.


Table of Contents

  1. Introduction
  2. Installation
  3. Usage
  4. Theory
  5. Visualization
  6. File Structure
  7. Contributions
  8. License

Introduction

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.

Installation

  1. Clone the repository:

    git clone https://github.com/its-adityagoyal/Game-of-Life-HexagonalGrid.git
    cd Game-of-Life-HexagonalGrid
  2. (Optional) Create and activate a virtual environment:

    python -m venv venv
    source venv/bin/activate  # On Windows use `venv\Scripts\activate`
  3. Install dependencies:

    pip install -r requirements.txt

Usage

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.

Theory

Hexagonal Grid to Array Mapping

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.

Neighbour Positioning

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

Hex Grid to Array Mapping

Rules

All of the custom rules for this hexagonal automaton are defined in rules.txt

Visualization

Below are sample frames from the simulation:

Generation 2 Generation 3

(Place additional illustrative images in the Output/ folder.)

File Structure

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

Contributions

Thank you for your interest in improving Game‑of‑Life‑HexagonalGrid! To contribute:

  1. Fork the repository
  2. Create a new branch
    git checkout -b feature/YourFeatureName
  3. Make your changes and commit
  4. Push to your fork
    git push origin feature/YourFeatureName
  5. Open a Pull Request against main in this repo

License

This project is licensed under the MIT License. See LICENSE for details.

About

Hexagonal Game of Life with Custom Rules

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages