A complete Python implementation of Conway's Game of Life cellular automaton with elegant Unicode visualization and interactive evolution.
Conway's Game of Life is a Python implementation of the famous cellular automaton devised by mathematician John Conway. This project provides:
- Random grid generation with customizable sizes (1ร1 to 100ร100)
- Full cellular evolution following Conway's four rules
- Interactive modes for both automatic and manual evolution
- Professional Unicode display with box-drawing characters
- Real-time statistics and pattern detection
- Educational codebase with clear, modular architecture
- Perfect for learning cellular automata concepts
- Demonstrates modular Python architecture and best practices
- Shows algorithmic thinking with neighbor counting and rule application
- Illustrates interactive programming with user input handling
- Zero dependencies - pure Python standard library
- Type-safe implementation with comprehensive type hints
- Clean terminal UI with Unicode box-drawing characters
- Structured code following consistent commenting patterns
- Observe emergent patterns like oscillators, still lifes, and spaceships
- Study complexity arising from simple rules
- Experiment with different initial configurations
- Analyze population dynamics and pattern stability
- Python 3.6 or higher
- Terminal with Unicode support (most modern terminals)
- No external dependencies required
-
Clone the repository:
git clone https://github.com/guiiireg/tp-python.git cd tp-python
-
Run the program:
python main.py
$ python main.py
=== GAME OF LIFE ===
Generating initial grid
Enter the grid size (n for an nรn grid, max 100): 10
Current Grid:
โโโโโโโโโโโโโโโโโโโโโ
โโ โ โ โ โ โ
โ โ โ โ โ โ โ
โโ โ โ โ โ โ
โ โ โ โ โ โ โ
โโ โ โ โ โ โ
โ โ โ โ โ โ โ
โโ โ โ โ โ โ โ
โ โ โ โ โ โ
โโ โ โ โ โ โ โ
โ โ โ โ โ โ โ
โโโโโโโโโโโโโโโโโโโโโ
Grid 10ร10 successfully generated!
Living cells: 49 (49.0%)
Dead cells: 51
Start automatic evolution? (y/n): y
- ๐ Grid Generation: Create random initial configurations
- ๐ Evolution Engine: Apply Conway's rules for cell transitions
- ๐๏ธ Visualization: Unicode terminal display with professional borders
- ๐ Statistics: Live tracking of cell populations and percentages
- ๐๏ธ Interactive Controls: Choose between automatic and manual evolution
The evolution follows these four fundamental rules:
- Underpopulation: Live cell with < 2 neighbors dies
- Survival: Live cell with 2-3 neighbors survives
- Overpopulation: Live cell with > 3 neighbors dies
- Birth: Dead cell with exactly 3 neighbors becomes alive
- ๐ค Automatic Mode: Continuous evolution with timed generations
- ๐ค Manual Mode: Step-by-step control with user input
- ๐ Smart Detection: Automatic stopping for stable states or extinction
tp-python/
โโโ main.py # Core application logic and user interface
โโโ config.py # Configuration constants and symbols
โโโ utils.py # Utility functions and evolution algorithms
โโโ game/ # Future modular extensions
โโโ .github/ # Project documentation and AI instructions
โโโ copilot-instructions.md
โโโ prompts/
File | Purpose | Key Functions |
---|---|---|
main.py |
Application entry point | generate_grid() , display_grid() , run_evolution() |
config.py |
Constants and symbols | Unicode characters, evolution rules, UI messages |
utils.py |
Core algorithms | evolve_grid() , count_neighbors() , apply_evolution_rules() |
# Grid representation: 2D list of integers
grid: List[List[int]] = [
[0, 1, 0], # 0 = dead cell, 1 = alive cell
[1, 1, 1],
[0, 1, 0]
]
def evolve_grid(grid):
"""Apply Conway's rules to create next generation"""
for each cell:
neighbor_count = count_neighbors(grid, row, col)
next_state = apply_evolution_rules(current_state, neighbor_count)
return new_grid
The project follows a distinctive structured commenting pattern:
#------------------------------------------------------------------------------------
# Major section header (84 characters)
#------------------------------------------------------------------------------------
def function_name():
# Subsection logic
#--------------------------------------------------------------------------------------
implementation_code()
#--------------------------------------------------------------------------------------
# Generate a small 5ร5 grid and watch it evolve
python main.py
# Enter: 5
# Choose: y (automatic evolution)
# Generate a larger grid with manual stepping
python main.py
# Enter: 20
# Choose: n (manual evolution)
# Press Enter to advance each generation
Create interesting patterns by experimenting with different grid sizes:
- Small grids (5-10): Good for observing oscillators and still lifes
- Medium grids (15-30): Watch gliders and other moving patterns
- Large grids (50-100): Complex population dynamics and emergent behavior
Conway's Game of Life produces fascinating patterns:
- ๐ Oscillators: Patterns that repeat (blinkers, beacons)
- ๐ Spaceships: Patterns that move across the grid (gliders)
- ๐ Still Lifes: Stable patterns that never change (blocks, beehives)
- ๐ Complex Dynamics: Chaotic behavior from simple rules
This implementation is perfect for understanding:
- Cellular Automata Theory: How simple rules create complex behavior
- Algorithm Design: Neighbor counting and state transitions
- Python Programming: Modular design, type hints, and clean code
- Terminal UI: Unicode characters and interactive programming
# Main application
python main.py
# Code follows Python 3.6+ standards
# No external dependencies required
# Full type hints for IDE support
- Modular design with clear separation of concerns
- Pure functions for algorithms (no side effects)
- Constants centralized in configuration module
- Type safety with comprehensive type annotations
This project is developed for educational purposes as part of a Python programming course (TP = Travaux Pratiques).
Experience the fascinating world of cellular automata with Conway's Game of Life!