A fast, interactive terminal-based implementation of Conway's Game of Life written in Zig.
- Interactive Terminal Display: Real-time visualization with ANSI colors and smooth animations
- Configurable Parameters: Customize grid size, generation count, and animation speed
- Multiple Input Methods: Command-line arguments, configuration file, or interactive prompts
- Toroidal Topology: Grid edges wrap around for seamless cellular automaton behavior
- Efficient Implementation: Double-buffered rendering with optimized memory management
# Clone and build
git clone <repository-url>
cd cgol
zig build
# Run with default settings
zig build run
# Run with custom parameters
zig build run -- --height 30 --width 50 --generations 100 --delay 150- Zig 0.11.0 or later
# Debug build (default)
zig build
# Release build
zig build -Doptimize=ReleaseSafe
# Install to zig-out/bin/
zig build installzig build testThe application supports multiple ways to configure the simulation:
cgol --height 40 --width 60 --generations 100 --delay 80
cgol --height=40 --width=60 --generations=100 --delay=80cgol 40 60 100 80 # rows cols generations delay_mscgol --prompt-for-config # Force prompts even if config exists
cgol -p # Short formCreate a cgol.toml file in the working directory:
# Game of Life configuration
rows = 40
cols = 60
generations = 0 # 0 = infinite
delay_ms = 100--height <rows>: Grid height (default: 25)--width <cols>: Grid width (default: 80)--generations <n>: Number of generations to simulate (0 = infinite, default: 0)--delay <ms>: Delay between generations in milliseconds (default: 100)--prompt-for-config: Force interactive config prompts--help: Show help message
- The simulation runs automatically once started
- Use
Ctrl+Cto exit - Grid automatically adjusts to fit your terminal size
The project is organized into focused modules:
main.zig: Application entry point and main game loopgame.zig: Conway's Game of Life rules and grid operationsconfig.zig: Configuration file parsing and managementcli.zig: Command-line argument processingrenderer.zig: Terminal rendering and ANSI escape sequencesinput.zig: User input handling for promptsconstants.zig: Application constants and defaults
- Follow Zig conventions:
UpperCamelCasefor types,lowerCamelCasefor functions/variables - Use explicit types (
u8,usize) and preferconstovervar - Format code with
zig fmt .before committing - Keep functions focused and separate I/O from pure logic
- Add unit tests using inline
testblocks - Run tests locally with
zig build test - Focus tests on pure functions and edge cases
- Fork the repository
- Create a feature branch
- Make your changes following the code style guidelines
- Add tests for new functionality
- Run
zig fmt .andzig build test - Submit a pull request
This project is licensed under the MIT License - see the LICENSE file for details.
Conway's Game of Life was devised by mathematician John Horton Conway in 1970.