A terminal-based implementation of Conway's Game of Life written in Python. It simulates the classic cellular automaton in a toroidal grid and includes an interactive editor mode for creating custom patterns directly in the terminal.
- Real time controls: Pause, resume and adjust simulation speed.
- Interactive editor: Pause the simulation and toggle cells
- Toroidal grid: The edges wrap around
- Zero dependencies: Built entirely with Python's standard library.
This application uses sys.stdin, tty and termios and thus runs natively on Unix-like environments without requiring external packages.
git clone https://github.com/vrncff/life-cli.git
cd life-cli
python main.pyNormal mode:
- SPACE: Play/Pause
- +/-: Increase/Decrease simulation speed
- r: Generate a random grid state
- e: Enter editor mode
- q: Quit
Editor mode:
- h, j, k, l: Move cursor (left, down, up, right)
- SPACE: Toggle the current cell (alive/dead)
- e: Exit editor mode
- q: Quit
The project is structured to separate mathematical logic from state management and the user interface:
core.py: Contains stateless functional logic for grid creation, neighbor counting and application of the game's rules without mutating the input state.engine.py: TheLifeEngineclass acts as the controller. It maintains the current generation state, manages the simulation tick rate and coordinates the switch between simulation and editor modes.ui_terminal.py: Handles terminal rendering and intercepts keystrokes usingsys.stdinandtermios.patterns.py: Defines relative coordinate matrices for classic Game of Life patterns.
- Add an interactive menu to spawn predefined patterns into the grid.
- Load initial grid states from a text file.
- Make the grid dimensions adjustable
