Terminal Snake in C with:
- Interactive menu (
./snake.out) - Agent protocol mode (
./snake.out agent) - Dynamic
agents/discovery - Difficulty stages 1-7
settings.jsondefaults
Install WSL2, then follow the Linux steps above:
wsl --installOpen the Ubuntu terminal from the Start menu and continue with the Linux instructions.
sudo apt update && sudo apt install build-essential libncurses5-devxcode-select --install
brew install ncursesRetrieve the repository:
git clone https://github.com/p2c2-acacia/snake.git
cd snakeBuild the project:
makeVerify the build succeeded:
ls -l snake.outcd agents/cpp && makeThis produces agents/cpp/agent.out. The Python agent (agents/python/agent.py)
requires no build step.
./snake.out— menu (Play / Agent Mode)./snake.out play— direct play mode./snake.out agent— protocol mode (stdin state, stdout action)
- Snake starts in a corner; one apple in the center.
- Snake starts center (right); fixed apples at fixed board positions.
- Snake starts center (random direction); one apple at random location.
- Snake starts center (random direction); fixed number of apples at random locations.
- Snake starts center (random direction); one apple regenerates randomly.
- Snake starts center (random direction); fixed number of apples regenerate randomly.
- Snake starts center (random direction); regenerating apples with increasing active count.
- Snake increases in length by 1 after eating an apple.
Scoring (Goal):
- Stages 1-5: pass/fail
- Stages 6-7: time ranking (ticks)
Your agent reads one state and must write one action:
- Actions:
straight,left,right - Agent mode is static by default (waits for agent output before next tick)
Example state:
{
"tick": 4,
"alive": true,
"score": 2,
"apples_eaten": 2,
"goal_apples": 10,
"difficulty": 5,
"outcome": "running",
"score_mode": "pass_fail",
"width": 20,
"height": 20,
"dir": "right",
"snake": [[10,10],[9,10],[8,10]],
"apples": [[13,7]]
}State is sent as text with a bordered board image:
STATE_BEGIN
tick:12
alive:true
score:3
...
board:
+--------------------+
|....@oo....*.......|
|....................|
...
+--------------------+
STATE_END
You parse that text and convert it into your own internal representation.
settings.json is loaded at startup and created automatically if missing or corrupt.
Users can edit it while keeping the game running. For agent add/remove edits,
the menu flow refreshes agents/ dynamically.
Key fields:
{
"width": 20,
"height": 20,
"speed_ms": 200,
"play_difficulty": 1,
"agent_difficulty": 1,
"agent_games": 1,
"agent_watch": true,
"agent_output_mode": "json",
"default_agent": "Built-in Naive"
}Stage tuning fields are also available:
stage2_fixed_applesstage4_fixed_applesstage5_goal_applesstage6_fixed_applesstage6_goal_applesstage7_initial_applesstage7_increment_everystage7_increment_bystage7_max_applesstage7_goal_apples
You may change the settings for the current session using the in-game settings menu.
- Create
agents/my_agent/agent.json - Create code that reads stdin state lines and prints one action line
- Use
--pipeincommand
Example manifest:
{
"name": "My Agent",
"command": "python3 agent.py --pipe",
"description": "My first snake agent"
}The bundled Python/C++ agents are simplified templates and contain
DO NOT TOUCH labels for protocol glue boundaries.
- Use
agent_output_mode: "raw_board"for image-like board parsing. - Use stage 6/7 for time ranking benchmarks.
- Enable action logs in Agent Mode to analyze decisions per tick.
| Problem | Fix |
|---|---|
ncurses.h: No such file |
Install ncurses headers: sudo apt install libncurses5-dev (Linux) or brew install ncurses (macOS) |
make: gcc: not found |
Install build tools: sudo apt install build-essential (Linux) or xcode-select --install (macOS) |
| C++ agent won't start | Run make inside agents/cpp/ first |
| settings.json corrupted | Delete it and relaunch ./snake.out — a fresh default is created automatically |
| Terminal too small | Resize your terminal to at least 24 rows by 80 columns |
src/ game engine + TUI + agent runner
agents/python/ Python template agent
agents/cpp/ C++ template agent
settings.json default game/agent configuration
MIT