Skip to main content

Polytopia LLM Benchmark

Project description

Polytopia LLM Benchmark

Fully automated UI benchmark for The Battle of Polytopia (Perfection mode, strict 30 actions).
It captures the screen, OCRs game state, clicks actions, and reads the final score from the game.

Install

pip install polytopia-bench

Requirements:

  • Windows
  • Tesseract OCR installed (set tesseract_cmd in calibration.json if not on PATH)

Calibration (one-time)

Create calibration.json with your UI coordinates and grid settings. Minimal example:

{
  "window_title": "The Battle of Polytopia",
  "tesseract_cmd": "C:/Program Files/Tesseract-OCR/tesseract.exe",
  "regions": {
    "turn": [10, 10, 120, 40],
    "score": [1700, 10, 200, 40],
    "map": [200, 120, 1500, 800],
    "end_screen": [600, 200, 700, 500]
  },
  "tile_grid": {
    "origin": [260, 170],
    "dx": 64,
    "dy": 56,
    "rows": 11,
    "cols": 11
  },
  "buttons": {
    "end_turn": [1780, 960],
    "confirm": [1200, 900],
    "close_popup": [1700, 120],
    "tech_tree": [80, 960]
  },
  "unit_buttons": {
    "warrior": [600, 900]
  },
  "build_buttons": {
    "farm": [600, 900]
  },
  "tech_buttons": {
    "riding": [900, 500]
  },
  "result_rules": {
    "win_score": 1
  }
}

Use examples/calibration_template.json as a starting point.

Run

polybench run --difficulty easy --opponents 1 --games 1 --calibration calibration.json

LLM command (stdin prompt → stdout JSON):

polybench run --difficulty hard --opponents 7 --games 1 --calibration calibration.json --llm-cmd "python examples\\echo_llm.py"

OpenAI-compatible HTTP endpoint:

polybench run --difficulty hard --opponents 7 --games 1 --calibration calibration.json --llm-host http://localhost:8000 --llm-model your-model --llm-api-key YOUR_KEY

Env alternative:

$env:POLYBENCH_LLM_HOST = "http://localhost:8000"
$env:POLYBENCH_LLM_MODEL = "your-model"
$env:POLYBENCH_LLM_API_KEY = "YOUR_KEY"
polybench run --difficulty hard --opponents 7 --games 1 --calibration calibration.json

Python API

import polybench

cfg = polybench.RunConfig(
    difficulty="easy",
    opponents=1,
    games=1,
    calibration_path="calibration.json",
    llm_host="http://localhost:8000",
    llm_model="your-model",
    llm_api_key="YOUR_KEY",
)
polybench.run_benchmark(cfg)

Game API

from polybench import UIAutomationGameAPI

api = UIAutomationGameAPI("calibration.json")
api.reset("easy", 1, 1)
state = api.get_state()
# ...call your LLM and produce an action...
# api.apply_action(action, run_dir="runs/tmp", turn_index=1)

How it works

  • Captures screen → OCRs turn and score → samples a color grid for the map.
  • Builds prompt → LLM returns JSON action.
  • Clicks UI to execute the action.
  • Stops after 30 actions (Perfection limit), then reads the final score and writes summary.

Action schema

Allowed action types:

  • end_turn
  • move
  • attack
  • train
  • build
  • research

For UI automation, unit_id and city_id must be coordinates:

{ "type": "move", "unit_id": { "x": 3, "y": 5 }, "to": { "x": 4, "y": 5 } }

Output

Each run writes:

  • runs/<timestamp>_<difficulty>_<opponents>/game_###/turn_###_prompt.txt
  • runs/<timestamp>_<difficulty>_<opponents>/game_###/turn_###_response.txt
  • runs/<timestamp>_<difficulty>_<opponents>/game_###/turn_###_action.json
  • runs/<timestamp>_<difficulty>_<opponents>/game_###/turn_###_ui_log.txt
  • runs/<timestamp>_<difficulty>_<opponents>/summary.json

Options

polybench run supports:

  • --difficulty easy | normal | hard | crazy
  • --opponents 1 | 7 | 15
  • --games (default 1)
  • --calibration path to calibration.json
  • --llm-cmd external command that reads prompt on stdin and returns JSON on stdout
  • --llm-host HTTP base URL (OpenAI-compatible /v1/chat/completions)
  • --llm-model model name for HTTP LLM
  • --llm-api-key API key for HTTP LLM (or set POLYBENCH_LLM_API_KEY)
  • --k-factor ELO K (default 32)
  • --opponent-elo (default 1000)
  • --start-elo (default 1000)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

polytopia_bench-0.2.0.tar.gz (13.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

polytopia_bench-0.2.0-py3-none-any.whl (15.3 kB view details)

Uploaded Python 3

File details

Details for the file polytopia_bench-0.2.0.tar.gz.

File metadata

  • Download URL: polytopia_bench-0.2.0.tar.gz
  • Upload date:
  • Size: 13.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.0

File hashes

Hashes for polytopia_bench-0.2.0.tar.gz
Algorithm Hash digest
SHA256 bac22cdf80b61ad34c3a6541fa58d17cd2be3719a9a7f8d057bf8cb40fa1eb30
MD5 5109dc7db3604beb84195753966835c3
BLAKE2b-256 d18e979f835a15d9dc049c6715230f029cd20d982e309390fad6f0bbf34882c9

See more details on using hashes here.

File details

Details for the file polytopia_bench-0.2.0-py3-none-any.whl.

File metadata

File hashes

Hashes for polytopia_bench-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 d5cc81db21cf42825998dcd609ee419ce839285d8057e13e1dab3de79fb8ebc9
MD5 d2060b1e3c61c41411c9a5eba2674fe8
BLAKE2b-256 f489b16cbaa114515b6e563adb27d1af1654949474e9058e514148282294d659

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page