GitHub - cnqso/bloonsbench

GitHub

10 min read Original article ↗

BloonsBench gameplay gpt-5-mini playing on Monkey Lane

A benchmark for evaluating LLM agents by having them play Bloons Tower Defense 5.

The agent sees screenshots of the game, reads cash/lives/round via OCR, and uses tools to place towers, upgrade them, and start rounds.

A run ends on Game Over. After Medium is completed, the harness observes and clicks through the three post-victory dialogs, verifies that freeplay appeared, and continues from round 66.

Quickstart

git clone https://github.com/cnqso/bloonsbench.git
cd bloonsbench
./scripts/setup.sh

Add an OpenRouter API key to the .env file created by setup, then run any compatible vision + tool-calling model:

.venv/bin/python scripts/run_agent.py --model openai/gpt-5-nano

The browser is visible by default so the run can be reviewed live. The setup script is safe to rerun. It creates the virtual environment, installs dependencies and Chromium, downloads the game file if missing, and prepares .env. The first launch also downloads the pinned Ruffle build and can spend roughly a minute on the offline Guest startup flow before reaching round 1.

Leaderboard

Model Runs Best Round Avg Round Avg Towers Avg Tokens
google/gemini-3.8-flash 3 71 65.7 9 2.2M
google/gemini-3-flash-preview 7 65 44.0 5 1.6M
openai/gpt-5-mini 3 65 49.3 4 2.8M
anthropic/claude-sonnet-4.6 1 59 59.0 13 2.5M
openai/gpt-5.6-luna 4 49 42.8 7 1.1M
Qwen3.5 27B 5 43 37.8 6 1.0M
openai/gpt-5-nano 9 40 15.3 2 302K
Qwen3.5 35B A3B 3 37 32.0 4 1.3M
nex-agi/nex-n2-mini 2 31 30.5 6 1.8M
Qwen3.5 9B 2 30 30.0 6 1.2M

Best Runs

🥇 google/gemini-3.8-flash — Round 71 · 12 towers · 3.1M tokens · 25m
# Tower Position Upgrades Target
1 Ninja Monkey (290, 240) 4 / 1 First
2 Bomb Tower (450, 240) 2 / 4 First
3 Monkey Apprentice (350, 240) 3 / 2 First
4 Spike Factory (90, 430) 3 / 2 First
5 Bomb Tower (450, 410) 0 / 3 First
6 Ninja Monkey (240, 240) 4 / 1 First
7 Bomb Tower (500, 410) 0 / 3 First
8 Super Monkey (450, 330) 2 / 2 First
9 Bomb Tower (550, 410) 0 / 3 First
10 Bomb Tower (400, 410) 0 / 3 First
11 Bomb Tower (595, 410) 0 / 3 First
12 Super Monkey (450, 145) 1 / 2 First

Stopped: Game Over · View run

🥈 google/gemini-3-flash-preview — Round 65 · 8 towers · 2.4M tokens · 1h 5m
# Tower Position Upgrades Target
1 Ninja Monkey (280, 350) 4 / 2 First
2 Bomb Tower (250, 235) 4 / 2 First
3 Ninja Monkey (200, 235) 4 / 2 First
4 Monkey Apprentice (150, 320) 4 / 2 First
5 Bomb Tower (280, 390) 2 / 4 First
6 Ninja Monkey (715, 240) 4 / 2 First
7 Super Monkey (400, 145) 2 / 2 First
8 Bomb Tower (675, 240) 2 / 4 First

Stopped: Game Over · Submission JSON

🥈 openai/gpt-5-mini — Round 65 · 0 towers · 4.8M tokens · 37m

Tower data was not recorded for this run.

Stopped: Game Over · Submission JSON

anthropic/claude-sonnet-4.6 — Round 59 · 13 towers · 2.5M tokens · 43m
# Tower Position Upgrades Target
1 Dart Monkey (420, 145) 2 / 3 First
2 Dart Monkey (585, 145) 2 / 3 First
3 Dart Monkey (150, 320) 2 / 3 First
4 Dart Monkey (715, 240) 2 / 3 First
5 Dart Monkey (280, 350) 2 / 3 First
6 Bomb Tower (500, 430) 3 / 2 Strong
7 Ninja Monkey (350, 145) 4 / 2 First
8 Tack Shooter (260, 235) 4 / 2 First
9 Bomb Tower (480, 235) 2 / 4 Strong
10 Sniper Monkey (400, 350) 2 / 2 Strong
11 Ice Tower (470, 145) 2 / 4 First
12 Ninja Monkey (530, 145) 4 / 2 First
13 Super Monkey (100, 430) 2 / 2 Strong

Stopped: Game Over · Submission JSON

openai/gpt-5.6-luna — Round 49 · 7 towers · 1.4M tokens · 17m
# Tower Position Upgrades Target
1 Dart Monkey (280, 350) 2 / 3 First
2 Boomerang Thrower (150, 320) 3 / 2 First
3 Tack Shooter (240, 235) 4 / 2 First
4 Sniper Monkey (715, 240) 2 / 2 First
5 Glue Gunner (585, 145) 3 / 2 First
6 Bomb Tower (400, 145) 2 / 4 Strong
7 Ninja Monkey (200, 235) 4 / 2 First

Stopped: Game Over · View run

Qwen3.5 27B — Round 43 · 8 towers · 1.3M tokens · 21m
# Tower Position Upgrades Target
1 Dart Monkey (280, 350) 2 / 3 First
2 Dart Monkey (150, 320) 2 / 3 First
3 Glue Gunner (240, 235) 2 / 1 First
4 Tack Shooter (260, 145) 3 / 2 First
5 Ice Tower (715, 240) 2 / 2 First
6 Bomb Tower (400, 145) 2 / 4 First
7 Ninja Monkey (500, 145) 2 / 4 First
8 Spike Factory (600, 145) 0 / 0 First

Stopped: Game Over · Submission JSON

openai/gpt-5-nano — Round 40 · 5 towers · 708K tokens · 15m
# Tower Position Upgrades Target
1 Dart Monkey (150, 320) 2 / 3 First
3 Dart Monkey (210, 235) 2 / 3 First
4 Spike Factory (260, 150) 3 / 2 First
5 Dart Monkey (280, 350) 3 / 2 First
6 Dart Monkey (430, 260) 4 / 2 First

Stopped: Game Over · Submission JSON

Qwen3.5 35B A3B — Round 37 · 4 towers · 1.4M tokens · 17m
# Tower Position Upgrades Target
1 Dart Monkey (280, 350) 2 / 3 First
2 Tack Shooter (150, 320) 3 / 2 First
4 Monkey Village (200, 235) 2 / 1 First
5 Ninja Monkey (585, 145) 3 / 2 First

Stopped: Game Over · Submission JSON

nex-agi/nex-n2-mini — Round 31 · 6 towers · 2.6M tokens · 17m
# Tower Position Upgrades Target
1 Dart Monkey (280, 350) 3 / 0 First
2 Dart Monkey (150, 320) 3 / 0 First
3 Dart Monkey (200, 235) 2 / 3 First
4 Dart Monkey (715, 240) 3 / 2 First
5 Dart Monkey (585, 145) 3 / 2 First
6 Glue Gunner (420, 145) 2 / 1 First

Stopped: Game Over · View run

Qwen3.5 9B — Round 30 · 6 towers · 1.1M tokens · 11m
# Tower Position Upgrades Target
1 Dart Monkey (280, 350) 2 / 3 First
2 Dart Monkey (150, 320) 2 / 3 First
3 Dart Monkey (715, 240) 3 / 2 First
4 Dart Monkey (350, 150) 3 / 2 First
5 Dart Monkey (500, 400) 3 / 2 First
6 Dart Monkey (600, 300) 3 / 0 First

Stopped: Game Over · Submission JSON

Submit Your Results

  1. Run an agent: python scripts/run_agent.py --model <your-model>
  2. A JSON submission and visual run report are generated in results/
  3. Fork the repo, commit both generated paths, and open a PR

Manual setup

uv venv && source .venv/bin/activate
uv pip install -r requirements.txt
python -m playwright install chromium

Create a .env file with your OpenRouter API key:

echo "OPENROUTER_API_KEY=sk-or-your-key-here" > .env

Download the game SWF:

curl -L -o ./game/btd5.swf "https://github.com/SJRNoodles/Flash-Game-Archive/raw/master/bloons-tower-defense-5.swf"

Run the game:

python scripts/run_agent.py --model openai/gpt-5-nano

Run

python scripts/run_agent.py --model openai/gpt-5-nano

# Or, inject your own save file
python scripts/run_agent.py --model openai/gpt-5-nano --saves saves/my-save.json

# Extended thinking (for models that support it, e.g. Gemini)
python scripts/run_agent.py --model google/gemini-3-flash-preview --reasoning high

# Optional for CI: run without a visible Chromium window
python scripts/run_agent.py --model openai/gpt-5-nano --headless

Reasoning effort: Models that support extended thinking (e.g. Gemini) can use --reasoning low|medium|high. Higher effort produces more verbose thinking traces but costs more tokens. Leaderboard submissions must use --reasoning low (the default) to ensure fair comparisons.

Saves are base64-encoded SOL files written to localStorage before the Flash VM starts (via deferred Ruffle loading).

Reusing local state

BloonsBench keeps the reusable pieces in three places:

  • profiles/persistent/default/chromium-profile/ preserves the local Chromium profile between runs.
  • saves/default.json is the portable BTD5/Ruffle save injected into localStorage before the SWF loads.
  • vendor/ruffle-web/<version>/ caches the pinned Ruffle build after the first launch.

The profile and Ruffle cache are ignored by Git; submissions stay portable because the game save and pinned Ruffle version are explicit. Delete the profile to start with a clean browser, or pass --profile to keep a separate one.

Recovery and spend safety

  • Slow reasoning has no total wall-clock deadline. A response can take longer than two minutes as long as the stream does not go silent for 60 seconds.
  • Each model response is capped at 4,096 completion tokens by default. Set OPENROUTER_MAX_COMPLETION_TOKENS to change that bound.
  • An accepted or ambiguously interrupted model request is never submitted again automatically, avoiding accidental double billing. Clearly rejected rate-limit and gateway requests receive only bounded retries.
  • Screenshot connection failures are retried locally, long rounds remain in observation mode without another model call, and unconfirmed GO or freeplay transitions are re-observed instead of invalidating the run.
  • OCR disagreement is treated as a warning unless a destructive action, currently selling a tower, leaves the tower registry genuinely unknowable.

Interactive CLI

Play manually or test the harness:

python scripts/run_mcp.py --cli

While an agent benchmark is running, attach the CLI to that exact browser state:

.venv/bin/python scripts/run_mcp.py --attach

The attached prompt supports observe, click <x> <y>, key <key>, wait <ms>, and status. Coordinates are content-relative within the 960×720 game area. Commands run at the benchmark's next safe observation point and every command, result, and resulting screenshot is retained in its run log. Exported run reports include the replayable command history and recovery screenshots.

Recovery steps can also be replayed as individual shell commands:

.venv/bin/python scripts/run_mcp.py --attach --command "observe"
.venv/bin/python scripts/run_mcp.py --attach --command "click 470 450"
.venv/bin/python scripts/run_mcp.py --attach --command "wait 500"

Disconnecting the CLI does not stop the benchmark. If the benchmark is waiting on a popup or round transition, it continues local observation and services recovery commands without spending another model turn.

Agent tools

Tool Description
observe Screenshot the current game state
place_tower Place a tower at (x, y) on the map
upgrade_tower Upgrade a tower along path 1 or 2
sell_tower Sell a tower for cash back
set_target Set targeting: first / last / close / strong
start_round Start the next round (fast-forward, 7s wait)
status Show placed towers, cash, lives, round
list_towers List all towers with costs and upgrade paths
click Raw click at (x, y) — escape hatch for stuck UI
send_key Press a key (e.g. Escape to cancel placement)
wait Wait N milliseconds

How it works

Ruffle emulates Flash, Playwright drives Chromium, EasyOCR reads the HUD, and the agent talks to OpenRouter for LLM inference.

  1. A local HTTP server (port 8890) serves the Ruffle wrapper + SWF
  2. Playwright launches Chromium, navigates to the game, and auto-clicks through menus to round 1
  3. The agent loop: screenshot → OCR for game state → LLM decides actions → execute tools → repeat
  4. Between rounds, the agent places/upgrades towers; then calls start_round to begin
  5. Our harness remembers tower positions and gives upgrade path info to the LLM to bypass computer usage limitations and avoid desyncs.
  6. Visual checks detect round completion and GAME OVER; the Medium victory panel triggers a verified transition into freeplay
  7. Context distillation kicks in when the conversation gets long, summarizing history to stay within token limits
  8. Completed runs export a compact Markdown report with JPEG checkpoints for round 1, every fifth round, and the final round to results/runs/