Adaptive AI Checkers — English draughts against a reinforcement-learning opponent that runs entirely on your phone. An optional Django backend trains it further, referees online matches and narrates its moves through a local LLM.
Get the app • Features • Architecture • Screenshots • Quickstart • How the AI Learns • API Contract • Testing
📲 Get the app
CrownFoundry is on Google Play, in closed testing while it gathers feedback.
Nobody has to invite you — joining the testers group is what grants access:
- Join the testers group with the Google account you use on your Android phone. Nothing to fill in.
- Opt in on Google Play, tap Become a tester, and install.
Use the same Google account for both steps, or Play will not recognise you as a tester. The store page only opens once you have opted in — until then it shows "not found", which is how closed testing works rather than a broken link.
Android 5.0 (API 21) or newer. Free, no account, no ads, and nothing to configure — the trained opponent ships inside the app, so it plays at full strength with no connection.
No data leaves your phone unless you point the app at a server yourself. See the privacy policy.
📖 Overview
You play. It loses. It works out why, and the next game is harder.
CrownFoundry is an Android client crafted in Jetpack Compose, carrying a trained Q-network that referees and plays entirely on the device. Every move feeds a replay buffer and adjusts the policy weights, so the opponent learns your tactical habits as you play — with no server involved.
Point it at the Django backend and it gains more: a second referee that validates every move independently, a self-play gym that keeps training the shared policy between games, match history synced across devices, and the analytics behind the Insights tab. None of it is required to play.
When the opponent moves, an integrated local LLM bridge (via Ollama) translates the Q-network's evaluation and board dynamics into live, in-character natural language commentary.
📱 Screenshots
![]() Play Dashboard & Match Setup Difficulty selector, opponent Elo & policy version |
![]() Interactive Draughts Board Legal move hints, turn indicators & custom pieces |
![]() Live AI Reasoning & Evaluation Ollama natural language narrative + Q-values |
![]() Match History & Replays Timeline of games with turn breakdown |
![]() Learning Curve Analytics Win rates, Elo progress & mistake reduction |
![]() Settings & Appearance Rule customization, backend endpoint & themes |
✨ Key Features
- Strict English Draughts Rules Referee: Complete implementation of standard 8x8 checkers rules (compulsory capture, multi-jumps, crowned-mid-jump rule termination) built in pure Python with zero external dependencies.
- Continuous Reinforcement Learning:
- Online Updates: Every AI turn updates replay memory and executes a gradient step.
- Post-Match Credit Assignment: Replays completed matches to backpropagate terminal rewards (+10 Win, -10 Loss, +3 Crown, +2 Capture, -2 Lost Man).
- Self-Play Training: Headless self-play engine (
python manage.py train_selfplay) for offline policy bootstrapping and evaluation.
- True Offline Play: The trained policy is bundled in the APK as a ~110 KB artifact and runs on the device — a full Kotlin port of the rules referee, the feature encoder, the Q-network and the alpha-beta search. Same weights, same depth, same node budget as the server, so the offline opponent is not a weaker one, and a fresh install is playable before it has ever seen a network. Pointed at a server it picks up newer policies as they are trained; if its copy has fallen behind it says "AI engine needs updating" and keeps playing with what it has.
- It Learns Offline Too: Finished offline games run the same Monte-Carlo credit assignment the backend runs, fine-tuning the on-device weights before the next game starts. Those games then sync back to the server, which replays every ply through the real engine, trains on them, and publishes a new policy the device picks up — so a week spent offline still feeds the shared opponent.
- Post-Game Analysis: Opening a finished match scores every ply against the on-device engine — an evaluation curve with the position you are looking at marked on it, a verdict under each move naming what was there instead, and the one move that decided the game. It runs on the phone, so it works with no connection; a device with no engine installed is told so in one line rather than left waiting.
- Puzzles From Your Own Games: The mistakes the analysis finds become practice positions — a real position you reached, with a move you could have played at the time. Revealing the answer is a dead end on purpose: it counts as an attempt and never as a solve.
- PDN Export: Any game shares out as Portable Draughts Notation, the format every other draughts program reads, so a match does not end its life inside this app.
- Pass and Play: Two players, one phone. The board turns to face whoever is to move once their opponent's move has finished animating. It is the one thing here that needs no engine at all, so it works on a device that has never been online — and nothing it produces reaches the trainer, the outbox, the opponent model or the engine's win rate.
- Ask It What You Should Play: The policy on the device is only ever pointed at beating you; pointed the other way it will tell you what it would play in your seat. The hint button asks it and draws the answer on the board — a ring on the piece, a dashed arrow to the square. It searches a ply deeper than the opponent plays at, with the risk bonus off, because a hint is advice rather than a personality. It runs on the device, so it costs nothing and works with no connection.
- See What It Nearly Played: Every AI turn comes back with the shortlist attached — every move it weighed and what it scored each one. "It played 24-19" is a fact; "it played 24-19 over 23-18 by four hundredths" is what tells you the position was close. The ranking is shown with the gap from its pick, because the raw scores only mean anything against each other in that one position.
- Adaptive Opponent Profiling: Dynamically tracks player aggression, king-rush tendencies, and capture rates to customize search depth and exploration.
- Natural Language Move Commentary: Bridges to a local Ollama LLM instance (e.g.
qwen3.5:9borllama3) to explain strategic reasoning behind each chosen move; gracefully falls back to deterministic heuristic narratives if offline. - Bespoke Jetpack Compose UI: Fast, fluid Android interface adapted from ViMusic's design system — custom fluid theming, animated piece hops and jump arcs, coronation effects, and zero boilerplate Material bloat.
- Learning Curve HUD & Analytics: Built-in visual insights tracking win-rate trajectories, mistake repetition rates, average game durations, and Q-network loss convergence.
🏗 Architecture
CrownFoundry/
├── Backend/ # Django 6 + Django REST Framework Referee & ML Engine
│ ├── game/ # Rules referee (engine/), match models, REST views
│ │ └── engine/ # Pure Python rules implementation (zero Django imports)
│ ├── ai/ # Q-network (NumPy), replay buffer, Ollama bridge, self-play
│ │ # + export.py / views.py: the engine artifact the phone downloads
│ ├── analytics/ # ELO calculator, player profiling, learning metrics
│ └── crownfoundry/ # Project settings, routing, WSGI/ASGI
├── Mobile/ # Native Android Client (Kotlin 2.1 + Jetpack Compose 1.7)
│ ├── app/ # UI screens (Play, Game, Matches, Insights, Settings)
│ ├── api/ # Ktor 2.3 HTTP client and serializable DTOs
│ ├── engine/ # The offline brain: rules, encoder, Q-network, search, learner
│ ├── compose-routing/ # Modular screen navigation
│ └── compose-persist/ # Survives activity recreation & config changes
├── tools/ # Validation & testing harness
│ ├── perft.py # Combinatorial move-tree verification against settled draughts counts
│ └── e2e_smoke.py # End-to-end API contract testing over real HTTP
├── APK/ # Pre-built installable Android application package
└── ARCHITECTURE.md # Shared contract & protocol specification
System Interaction Diagram
sequenceDiagram
autonumber
actor Human as Human Player (Black)
participant Client as Android App (Compose + Ktor)
participant Referee as Django Rules Engine
participant RL as Q-Network Policy
participant LLM as Ollama LLM Bridge
Human->>Client: Selects piece & destination square
Client->>Referee: POST /api/match/move/ {"match_id": "...", "player_move": "11-15"}
Referee->>Referee: Validates move against legal tree & updates board state
Referee-->>Client: Returns updated FEN & next turn status
Client->>Referee: POST /api/ai/generate-turn/ {"match_id": "..."}
Referee->>RL: Evaluates candidate moves via Q-Network
RL->>RL: Selects optimal action + computes Q-values
Referee->>LLM: Queries prompt with board state & candidate scores
LLM-->>Referee: Natural language strategic reasoning
Referee-->>Client: Returns chosen move, board state, Q-values & commentary
Human->>Client: Completes match
Client->>Referee: Match finished
Referee->>RL: Triggers post-match credit assignment & replay optimization
Offline Loop
With no connection the app referees itself. Everything the player sees is the same; what changes is who is answering, and that the commentary comes from the heuristic narrator instead of Ollama.
sequenceDiagram
autonumber
actor Human as Human Player (Black)
participant Client as Android App (Compose)
participant Engine as On-Device Engine (:engine)
participant Store as Local Match Store
participant Server as Django Referee
Note over Client,Server: Connection lost — the referee cannot be reached
Human->>Client: Taps Play
Client->>Server: POST /api/match/start/
Server--xClient: unreachable
Client->>Engine: Start a local match instead
Engine-->>Client: Opening position + legal moves
loop every turn
Human->>Client: Plays a move
Client->>Engine: Validate & apply (same rules as the server)
Client->>Engine: Alpha-beta search over the downloaded policy
Engine-->>Client: Move, Q-values, heuristic reasoning
Client->>Store: Append the ply
end
Client->>Engine: Game over — Monte-Carlo pass over the finished game
Engine->>Engine: Fine-tune the on-device weights, remember what not to repeat
Note over Client,Server: Connection returns
Client->>Server: POST /api/ai/engine/sync/ {"matches": [...]}
Server->>Server: Replay every ply through the real engine, import, queue training
Server-->>Client: Accepted / rejected, plus the current engine manifest
Client->>Server: GET /api/ai/engine/manifest/
Server-->>Client: version 29 — newer than the phone's 28
Client->>Server: GET /api/ai/engine/download/
Server-->>Client: CFE1 artifact (~110 KB, checksum-verified)
Client->>Engine: Install — the phone is current again
🚀 Quickstart
You do not need any of this to play. The published app is self-contained — this section is for running the backend and building from source.
Prerequisites
- Backend: Python 3.11+ (with
pipandvenv) - Mobile: Android Studio Ladybug / Koala or Android SDK command-line tools with Java 17+
- LLM (Optional): Ollama running locally with your model of choice (default:
qwen3.5:9b)
1. Start the Backend
cd Backend
# Create and activate virtual environment
python3 -m venv .venv
source .venv/bin/activate
# Install dependencies
pip install -r requirements.txt
# Run migrations and start server
python manage.py migrate
python manage.py runserver 0.0.0.0:8000
Verify backend health:
curl http://127.0.0.1:8000/api/health/
# Returns: {"ok": true, "version": "1.0.0", "ollama": {"available": true, "model": "qwen3.5:9b"}, "policy_version": 22}
2. (Optional) Run Ollama for AI Move Commentary
If you want the AI to narrate its moves using a local LLM:
# Pull and run your preferred model
ollama run qwen3.5:9b
Note: If Ollama is not running, CrownFoundry automatically falls back to heuristic commentary seamlessly.
3. Run or Install the Mobile App
Option A: Install Prebuilt APK
You can install the provided build directly to a connected device or emulator:
adb install APK/CrownFoundry.apk
Option B: Build from Source
cd Mobile
# Build Debug APK
./gradlew :app:assembleDebug
# Install onto connected device / emulator
./gradlew :app:installDebug
Network Configuration: In Android emulator,
http://10.0.2.2:8000automatically routes to your host machine'slocalhost:8000. On a physical phone, navigate to Settings in the app and set the Backend URL to your host machine's LAN IP (e.g.,http://192.168.1.50:8000).
🧠 Reinforcement Learning & AI
CrownFoundry uses an MLP Q-Network written with NumPy for zero-overhead, highly portable deployment without massive binary dependencies:
- Board Representation (Feature Vector):
- 32 dark square encodings (Piece type: Empty, Human Man, Human King, AI Man, AI King).
- Positional dynamics: back-rank safety, center control, piece advancements, king differential.
- Reward Function: $$\text{Reward} = +10(\text{Win}) - 10(\text{Loss}) + 3(\text{Crown}) + 2(\text{Capture}) - 2(\text{Piece Lost})$$
- Continuous Policy Training:
- Online: Replay buffer push + Bellman gradient step on every turn.
- Post-Game: Full-match replay to adjust losing lines and reinforce winning tactics.
- Self-Play Bootstrap:
cd Backend python manage.py train_selfplay --games 500 --evaluate 50
Self-play on the phone
The device does not only learn from the games you sit through. Settings → Offline → Train it against itself runs a practice session on the phone: the opponent plays a run of games against random play, then against a material grabber, then against its own policy, collects every position into a replay buffer, and fits the network once over the whole buffer at a tenth of the artifact's learning rate.
Nothing it learns is installed until it has proved itself. The trained candidate plays a match against the weights it would replace, from randomised openings, and is discarded unless it wins:
| Check | What it catches |
|---|---|
| Head-to-head vs. the previous weights, ≥55% over 20 games | The measurement that has no ceiling — this is what admits an improvement |
| Baseline vs. Random and Greedy, within 18 points of the champion's | A policy that learned to beat its own previous version by exploiting a blind spot they share |
Both have to pass. The baseline alone saturates — the shipped v42 policy already beats both fixed opponents every game from the opening — so a guard built only on it can report a policy getting worse and never one getting better.
Measured on the shipped policy, twelve sessions of 25 games (about ten seconds on a laptop, a minute or so on a phone) accepted two and produced a policy that beat the one it started from 25–13–2 over 40 varied games. Most sessions are rejected, and that is the guard working rather than failing: self-play produces a real improvement some of the time and noise the rest of it.
Publishing a trained policy
A build with no referee (crownfoundry.backendUrl=none, which is what ships on Play) can still
update its opponent, by polling a static manifest instead of a server:
cd Backend
# The database is not committed, so on a fresh clone the exported artifact is the only surviving
# copy of the trained policy. Load it back before training on top of it.
python manage.py migrate
python manage.py import_engine --in ../Mobile/app/src/main/assets/policy.cfe
# Train. Continuing from a stored policy fine-tunes it: a tenth of its own learning rate, and one
# fitting phase over the replay buffer once the games have been played, rather than fitting each
# game as it arrives. See --lr-scale and --fit-steps, and the note below on why.
python manage.py train_selfplay --games 500 --evaluate --eval-games 30 --report
# Export.
python manage.py export_engine --out ../docs/engine/policy.cfe
# Check it is actually better before publishing it. See the warning below - this is the step
# that decides, not `--evaluate`.
cd ../Mobile && ./gradlew :engine:testDebugUnitTest --tests '*ArtifactComparisonTest*' \
--rerun-tasks \
-Pcrownfoundry.champion=app/src/main/assets/policy.cfe \
-Pcrownfoundry.candidate=../docs/engine/policy.cfe
# Publish, if it said PUBLISH.
cd .. && python tools/publish_engine.py docs/engine/policy.cfe
# Refresh what a *fresh install* starts with, before it has ever fetched an update.
cp docs/engine/policy.cfe Mobile/app/src/main/assets/policy.cfe
git add docs/engine Mobile/app/src/main/assets/policy.cfe
git commit -m "engine: publish v43" && git push
Important
--evaluatecan veto a run but it cannot confirm one.should_savecompares scores against a random and a greedy opponent, and it does catch a collapse — a 200-game run at the old defaults took v42 from beating the greedy baseline every game to beating it half the time, and the gate correctly threw it away.What it cannot do is resolve anything finer, or recognise an improvement at all.
ai.training.evaluateplays every game from the opening position, so





