A hybrid AI/ML Catan solver for Colonist.io.
Watan++ combines:
- logic-heavy Catan simulation and evaluation
- LLM-based multi-agent analysis for high-context strategic decisions
- computer vision (YOLOv8 segmentation) to parse board screenshots
- browser-side packet sniffing and extraction utilities for Colonist.io
At a high level, the workflow is:
- Capture game state from Colonist.io (browser sniffer, DOM/WS hooks).
- Represent the game in a compact HDCS (High-Density Catan State) JSON format.
- Simulate settlement drafts and evaluate candidate lines.
- Use fast heuristics plus optional LLM analysis to score and rank settle options.
- Optionally parse screenshots with the CV pipeline to generate structured board JSON.
- Python (primary)
- JavaScript (browser sniffer)
- OpenAI API (default model config: gpt-5-mini)
- Anthropic API
- Google Gemini API
- Ultralytics YOLOv8 segmentation
- PyTorch (via ultralytics)
- OpenCV + NumPy + Pillow
- Pydantic v2 for HDCS schemas and invariants
- requests, httpx, websockets
- python-dotenv
- pytest
- script-style test runners in src/tests
- src/
- ai/: provider abstraction and sync/async AI query layer
- base_computes/: core game state, simulation, settle evaluation, robber prediction
- settle_process/: orchestrators for init analysis and settle recommendations
- tests/: script runners and validation tests for core pipelines
- colonist_sniffer.js: in-browser Colonist.io extractor (exposes window.colonistSniffer)
- catan_vision/
- training and inference pipeline for board detection/parsing
- dataset/ in YOLO format
- processing/ for geometric parsing and projection
- outputs/ for JSON and debug visualizations
- manual_processing/
- terminal visualization and board rendering helpers
- info/
- planning docs and HDCS schema/context notes
The project uses a compact, positional JSON schema for game state with strict index conventions:
- resources: [Wood, Brick, Wool, Grain, Ore] => [0..4]
- dev cards: [Knight, VP, Road Building, Year of Plenty, Monopoly]
- map modeled as a tile/node/edge dual-graph for Catan topology
See these docs for full details:
- info/WPP+Planning.md
- info/context.md
From repository root:
python -m venv .venv
# Linux/macOS
source .venv/bin/activate
# Windows PowerShell
# .venv\Scripts\Activate.ps1
pip install -r requirements.txtYou can use environment variables directly, or place them in a root .env file.
Required variables by provider:
- OPENAI_API_KEY
- ANTHROPIC_API_KEY
- GOOGLE_API_KEY
Example .env:
OPENAI_API_KEY=...
ANTHROPIC_API_KEY=...
GOOGLE_API_KEY=...python test_ai.pyThe most practical entrypoint is the settle bot test runner.
python src/tests/test_settle_bot.py src/sample5.jsonUseful options:
python src/tests/test_settle_bot.py src/sample5.json --provider openai --model gpt-5-mini
python src/tests/test_settle_bot.py src/sample5.json --ai-cutoff 3
python src/tests/test_settle_bot.py src/sample5.json --debugWhat it does:
- simulates settlement placeouts
- scores top-N placeouts with AI analysis
- scores remaining placeouts with fast algorithmic evaluator
- returns ranked settle+road options
python src/tests/test_init_analysis.py src/sample5.json --provider openai --model gpt-5-miniBefore training, update catan_vision/data.yaml path to your local dataset directory.
python -m catan_vision.train_catanpython -m catan_vision.main --image /path/to/board.pngExpected outputs:
- catan_vision/output_json/catan_map.json
- catan_vision/output_visualizations/*
File: src/colonist_sniffer.js
Typical usage:
- Open Colonist.io game in browser.
- Paste the full script into DevTools Console.
- Run helper commands from window.colonistSniffer, for example:
colonistSniffer.scan()
colonistSniffer.getState()
colonistSniffer.getWSMessages()
colonistSniffer.printState()The sniffer includes multiple extraction strategies:
- WebSocket interception
- Socket/Global state discovery
- DOM probing
- debug helpers for protocol exploration
Pytest is available, but this repository also uses script-driven test runners.
Typical commands:
pytest -q
python src/tests/test_settle_sim.py src/sample5.json
python src/tests/test_robber_pipeline.py src/sample5.json
python src/tests/test_starting_hands.py src/sample5.jsonNote: some tests/scripts rely on optional API keys or local visualization dependencies.
Implemented strongly:
- HDCS game-state modeling and validation
- settle simulation/evaluation stack
- AI provider abstraction with async orchestration
- CV-based board parsing workflow
- Colonist browser extraction tooling
Documented/planned in design notes:
- local Flask update_state service for continuous Bayesian state updates
- broader multi-agent game-time orchestration around full turns
- Missing API key errors:
- ensure provider-specific env vars are set or present in root .env
- Vision model not found:
- train first or place best.pt at catan_vision/runs/catan_yolo8m/weights/best.pt
- Empty or poor vision outputs:
- verify catan_vision/data.yaml path and class alignment with catan_vision/config.py
- Sniffer captures no messages:
- reload game tab and re-inject script early, then trigger game actions and inspect colonistSniffer.getWSMessages()
This repository includes an embedded copy of a computer-use preview example under src/gemini-test/computer-use-preview with its own LICENSE and docs.