Chapter 12: The Capstone (Building a Game)

We have reached the end of the road.

We started with a minimal script that could barely echo “Hello.” We ended with Nanocode v1.0: an autonomous agent with:

  • Brains: Support for Claude, DeepSeek, and local models via Ollama
  • Hands: Tools to read, write, and edit files
  • Eyes: Tools to map and search the codebase
  • Memory: A persistent scratchpad
  • Safety: A plan mode harness
  • Curiosity: A web search tool to learn new things

Now, we must answer the only question that matters: Can it actually code?

In this final chapter, we perform a “Zero Code Challenge.” We will build a classic Snake game using Python and Pygame. The rule: you are not allowed to write a single line of Python. You can only speak to the agent in English.

An icon of a info-circle1

Aside: This demo involves many API calls. If you hit rate limits (HTTP 429), the agent will retry automatically. For long sessions, consider using a local model via Ollama to avoid limits entirely.

Step 1: Preparation

Create a working directory for the game and navigate into it:

1 mkdir -p snake_game
2 cd snake_game

If you are using the book’s code repository, copy the agent from ch11:

1 cp ../ch11/nanocode.py .
2 cp ../.env .  # Your API key

(If you built nanocode.py from scratch, copy your latest version and .env file into this folder instead.)

Install Pygame:

1 pip install pygame
An icon of a info-circle1

Aside: On Windows, this should work out of the box. On macOS, you may need to install SDL libraries first: brew install sdl2 sdl2_image sdl2_mixer sdl2_ttf. On Linux, install the SDL dev packages: sudo apt install libsdl2-dev libsdl2-image-dev libsdl2-mixer-dev libsdl2-ttf-dev.

Step 2: The Architect (Plan Mode)

Start the agent. We begin in plan mode because we want a blueprint before we lay bricks.

1 python nanocode.py

The Prompt:

1 Build a classic Snake game using Pygame. Include a score counter and Game Over screen with restart. Put ALL code in ONE file: snake.py. Write the plan in PLAN.md.

The agent will use write_file to create PLAN.md. Read it. It should outline the Snake class, the Food class, and the game loop—all in a single file.

If it looks good, approve it.

Step 3: The Builder (Act Mode)

Switch to act mode:

1 /mode act

The Prompt:

1 Implement the plan in snake.py. All code in one file.

Watch the terminal:

1   → Writing snake.py

The agent is generating code based on the context it stored in PLAN.md.

Step 4: The Reality Check

Now, we run it.

The Prompt:

1 Run the game with: python snake.py

The agent executes run_command. A window pops up. You play Snake.

If it crashes: LLMs are non-deterministic. Your agent might produce a bug on the first try. If the game crashes with an error like AttributeError: 'Snake' object has no attribute 'draw', don’t fix it yourself. Let the agent see the stderr.

The Prompt:

1 The game crashed. Read the error and fix it.

The agent will read the traceback, use read_file to find the bug, use edit_file to patch it, and run again.

Step 5: The Pivot (Feature Creep)

The game works, but it’s ugly. The snake is just green squares. Let’s stress-test the agent’s ability to refactor.

The Prompt:

1 The game looks boring. Make the snake change color as it eats food, increase speed every 5 points, and search the web for 'cool retro game color palettes' to apply.

The agent should:

  1. Use search_web to find color palettes
  2. Use read_file to understand the current rendering logic
  3. Use edit_file to inject the new features
  4. Run the game to verify

This is the full toolkit in action: search, read, edit, run.

The Result

If everything worked, you now have a playable Snake game. You didn’t write a single line of Python. You spoke English, and the agent translated your intent into working code.

An icon of a warning1

Warning: Your results may vary. LLMs are non-deterministic. The agent might take a different approach, produce different bugs, or need more iterations. That’s normal. The point isn’t that it works perfectly on the first try—it’s that it converges on a working solution through iteration.

Wrapping Up

In this chapter, you put Nanocode through its final exam: building a complete game from scratch using only English prompts.

You experienced:

  1. Plan mode: The agent architected the solution in PLAN.md
  2. Act mode: The agent implemented the code
  3. The feedback loop: The agent debugged its own crashes
  4. The full toolkit: read, write, edit, search, run—all working together

The key insight: an autonomous coding agent isn’t magic. It’s the combination of simple tools (file I/O, subprocess, web search) orchestrated by a language model. You built every piece yourself.

Epilogue: The End of the Beginning

You have just built a video game without writing code.

But you built something more important than a Snake game. You built the machine that builds the machine.

You now possess a tool that grants you:

  • Leverage: Spin up prototypes in minutes, not hours
  • Fearlessness: Dive into unknown codebases because your agent can map and explain them
  • Independence: Run local models and keep your data private

Where to go from here?

This nanocode.py is yours. It’s under 700 lines of Python. You understand every line because you wrote it.

Some ideas:

  • Add Git: Write a tool to commit changes automatically
  • Add Vision: Give Claude screenshots of your frontend so it can fix CSS
  • Add Voice: Hook up Whisper so you can talk to your agent while walking
  • Add MCP: Connect to external services via the Model Context Protocol

The AI revolution isn’t about waiting for a god-like model to save us. It’s about engineers like you building the harnesses that make these models useful.

You are no longer just a coder. You are an AI engineer.

Now, go build something impossible.