In This Article
Scenario for Gemini CLI: Game of Life
Step 1: Creating a system instruction GEMINI.md
Create a .gemini directory in the project’s working folder. Inside .gemini, create a GEMINI.md file and insert the system instruction into it. Example instruction:
## 📘 Instructions for Python Code Generation
### 1. General Rules
* Use **Python 3.10+**.
* Adhere to a **clear, readable, and unambiguous coding style**.
* **Every function, method, and class** must have:
* Type annotations (`type hints`)
* Full and correct documentation in `docstring` format (see section 3)
* Internal comments (`#`), where necessary
---
### 2. Comments
* Comments must be **accurate** and describe **what the code does**, not "what we are doing".
* **Forbidden** to use pronouns: `we do`, `we return`, `we send`, `we go`, etc.
* **Allowed** only terms: `extraction`, `execution`, `call`, `replacement`, `check`, `sending`, `Function performs`, `Function changes value`, etc.
#### ❌ Example of incorrect comment:
For convenience, let’s create a game directory to store project files, and a scenarios directory to store scenarios for Gemini CLI:
scenarios/life-create-code.md— instructions for creating the “Game of Life” codescenarios/life-create-test.md— instructions for creating testsscenarios/life-create-doc.md— instructions for creating documentation
life-create-code.md
Inside the `game` directory, create the file life.py.
Implement Conway's "Game of Life" in Python, using an object-oriented approach.
Use libraries: `numpy`, `pygame` (for graphics).
Requirements:
1. Create a `Game` class.
2. In `__init__`, the class should take grid dimensions (width, height) and create a random initial field.
3. Create a `step()` method that updates the game state by one step according to the rules:
- A living cell with < 2 living neighbors dies (underpopulation).
- A living cell with 2 or 3 living neighbors survives.
- A living cell with > 3 living neighbors dies (overpopulation).
- A dead cell with exactly 3 living neighbors becomes alive (reproduction).
4. Create a `display()` method or override `__str__` to output the field to the console ('■' for a living cell, ' ' for a dead one).
5. Use `numpy` for efficient grid operations.
6. In the `if __name__ == '__main__':` block, add an example that creates a game and runs the simulation with a small delay between steps.
7. Use pygame or another graphics library for game visualization.
life-create-test.md
Inside the `game` directory, create the file test_life.py, using the context from the @life.py file. Use the pytest framework.
The test should check the evolution of a simple "Blinker" oscillator:
1. Import the `Game` class from `life`.
2. Create a test function, for example `test_blinker_oscillation`.
3. Create a `Game` instance with a fixed size (e.g., 5x5).
4. Manually set the initial state of the field: a horizontal line of three living cells in the center.
5. Call `game.step()`.
6. Using `assert` and `numpy.array_equal`, check that the field has changed to a vertical line of three cells.
7. Call `game.step()` again.
8. Check that the field has returned to its original horizontal state.
life-create-doc.md
Analyze the files @life.py and @test_life.py inside the `game` directory and create a documentation file doc.md based on them.
Documentation structure:
- **Title:** # Project "Game of Life"
- **Brief description:** Implementation of Conway's cellular automaton.
- **File structure:** Brief description of the purpose of `life.py` and `test_life.py` files.
- **How to run the simulation:** Command to run the main file (`python life.py`).
- **How to run tests:** Commands to install dependencies (`pip install pytest numpy`) and run tests (`pytest`).
Step 2: Creating the “Game of Life” code
Launch gemini-cli in the terminal. Important! Make sure you are in the directory where .gemini/GEMINI.md is located.
- Grant permission to create the file.
- Gemini CLI will generate the
life.pyfile in thegamedirectory. - Create a venv virtual environment, install dependencies, and run the game.
Step 3: Creating tests
- Gemini CLI generates the
test_life.pyfile in thegamedirectory. - Test simple scenarios, such as the “Blinker” oscillator.
- Fix errors if necessary.
Step 4: Creating documentation
- Gemini CLI analyzes
life.pyandtest_life.py. - Generates a
doc.mdfile with a project description, instructions for running the game and tests.
Voila! The project is ready.