llm-snake-arena

🐍 LLM Snake Arena

A visual snake battle game where two LLMs compete against each other β€” each snake powered by a model (from the same provider or different providers!)

## [🐍 ▢️ TRY IT LIVE! βš”οΈ](https://sujee.github.io/llm-snake-arena/snake.html) **Watch two AI snakes battle in your browser β€” no install needed!**

History

LLM Snake Arena originated as a demo created by Sujee Maniyam for the Nebius Token Factory Cookbook. This is an independent version.

The original version can be accessed

Features

Providers and Models

Gameplay

Visualizations

Game Configuration

Other features

How to Play

  1. Open snake.html in your web browser
  2. Pick a provider preset (Nebius, OpenAI, Anthropic, Together AI, Ollama Cloud/Local, Custom) and enter your API URL (pre-filled for presets) and API Key (Ollama Local needs no key β€” leave it blank)
  3. Leave Use same provider for both players checked, or uncheck it to configure Provider 2 separately
  4. Click Load Models to fetch available models
  5. Select different models for Player 1 (Red) and Player 2 (Blue) via the searchable dropdowns
  6. (Optional) Adjust Options β€” Visibility Radius, Collision Avoidance, Provide Hints, Debug Mode, Model Reasoning
  7. Click Start to begin the battle

Controls in the Matchup card: Start, Pause ⏸️, Restart πŸ”„, and a Loop toggle. The Extra section has ⚑ Run Benchmarks, πŸ“ˆ Show Results, and model sorting (Sort by Name / Sort by Benchmark).

Tech Stack

Game Rules

Customization

From the UI (no code changes)

These settings have controls in the Options panel and apply to subsequent moves β€” no restart needed:

Code-only (edit js/game.js)

These have no UI control β€” change them in the source:

const GRID_SIZE = 30;                 // Board dimensions (30Γ—30). Try 20 for faster games, 40 for more space
const NUM_FRUITS = 3;                 // Fruits on the board at once
const LLM_TIMEOUT_MS = 45000;         // Per-request LLM timeout (45s)
const API_RETRY_DELAY_MS = 2000;      // Base retry delay (also seeds timeout backoff)
const GAME_MAX_TOKENS = null;         // null = omit max_tokens (let the model finish; reasoning models need >1k)
const fruitGuidanceEnabled = true;    // Include FRUITS list in prompt (keep on β€” off isn't viable gameplay)
const MAX_LOG_ENTRIES = 100;          // Cap on game-log <p> entries (oldest trimmed)

Snake starting positions are controlled in initializeGame; prompt construction lives in getBoardState.

Note: There is no fixed β€œturn delay” β€” snakes move at the natural speed of their model’s responses. If you want to add artificial pacing, you would add a delay inside moveSnakeWithLLM before it recurses.

API Compatibility

Works with any OpenAI-compatible API that supports:

Plus native Anthropic (Anthropic preset β†’ https://api.anthropic.com/): GET /v1/models + POST /v1/messages with x-api-key auth, called directly from the browser.

Tested with Nebius Token Factory but should work with others (OpenAI, compatible proxies, Ollama, LM Studio). Models are filtered by output modality: any model that produces text output is included (so vision-capable text LLMs like moonshotai/Kimi-K2.6 are selectable), while pure image/audio generation models are excluded.

Troubleshooting

Local Run

If opening a file in a browser gives you access errors, run a tiny web server like this:

python -m http.server 8000

Go to: http://localhost:8000/snake.html

Debugging with an Agent

Have an .env file with API keys needed for providers you are testing.

NEBIUS_API_KEY=xxxx
OPENAI_API_KEY=yyyy
ANTHROPIC_API_KEY=zzz
...

And a sample prompt for an agent

Trace a model loading call for provider OpenAI. Use the API key from the .env file
Debug why provider/model is running out of tokens

β€œFailed to load models” error:

Snakes don’t seem smart:

Game too slow/fast:

One snake barely moves:

Enjoy watching AI snake battles! πŸβš”οΈπŸ