explaingit

pham-tuan-binh/tribes-rl

Analysis updated 2026-05-18

11CAudience · researcherComplexity · 4/5LicenseSetup · hard

TLDR

A from-scratch C rebuild of the game Polytopia, built to train AI agents to play it and to let people watch or challenge them in a browser.

Mindmap

A visual breakdown will appear here once this repo is fully enriched.

Code map

Detail Auto

An interactive map of this repo's files and how they connect — its source is parsed live in your browser. Click Visualize to build it.

filefunction / class

What do people build with it?

USE CASE 1

Train a reinforcement learning agent to play a Polytopia-style strategy game from scratch.

USE CASE 2

Run large-scale self-play training using the PufferLib environment for speed.

USE CASE 3

Watch or play against already-trained AI agents directly in a web browser.

USE CASE 4

Study how a game engine can be verified for correctness against a reference implementation.

What is it built with?

CPufferLibWebAssemblyJavaScriptPython

How does it compare?

pham-tuan-binh/tribes-rlfreertos/freertos-cellular-interface-reference-quectel-bg96sgkdev/ptrace_may_dream
Stars111111
LanguageCCC
Last pushed2026-05-28
MaintenanceMaintained
Setup difficultyhardhardhard
Complexity4/54/55/5
Audienceresearcherdeveloperresearcher

Figures from each repo's GitHub metadata at analysis time.

How do you get it running?

Difficulty · hard Time to first run · 1h+

Training requires PufferLib and a capable GPU, the web build needs Emscripten to compile to WebAssembly.

MIT license: use, modify, and share freely, including commercially, as long as you keep the copyright notice.

In plain English

tribes-rl is an open-source rebuild of the strategy game The Battle of Polytopia, written in C, and built specifically to train reinforcement learning agents to play it. The game rules are ported from an existing academic Java project called Tribes, and the author checked that the new C version matches it move for move using recorded reference games. The project centers on one game engine that serves two purposes. First, it runs as a fast, headless training environment using a library called PufferLib, letting many copies of the game run in parallel so an AI agent can learn by playing itself repeatedly. Second, the exact same engine is compiled to WebAssembly so it can run inside a browser, powering a website where visitors can watch trained agents play each other or play against them directly, with no server needed. The game itself is simplified on purpose: only the conquest win condition is used, maps are a fixed size with two to four players, fog of war is on, and matches end in a draw after 200 turns if nobody wins outright. The AI's decisions are broken into small steps, like picking a tile then choosing an action such as move, attack, build, or research, and the system only ever offers the agent choices that are actually legal at that moment. Training rewards are tuned to encourage winning quickly and discourage stalling or wasting resources, and performance numbers show that on a high-end graphics card, a large training run can finish in a couple of hours. The engine's correctness is checked automatically against the original Java version using stored test cases. The website itself needs no special framework, just plain JavaScript, and one trained model file works for every player count. Character sprites for the game are produced through a separate image generation pipeline included in the project. The whole project is released under the MIT license, and the game rules were ported from the Tribes project rather than copied wholesale, though the author credits it as essential to this project's existence.

Copy-paste prompts

Prompt 1
Explain how the action space and turn phases work in tribes-rl's C game engine.
Prompt 2
Help me set up PufferLib and train an agent using tribes-rl's polytopia environment.
Prompt 3
Walk me through building the WASM version of tribes-rl so I can run the website locally.
Prompt 4
Show me how the golden-trace testing against the Java Tribes project works.

Frequently asked questions

What is tribes-rl?

A from-scratch C rebuild of the game Polytopia, built to train AI agents to play it and to let people watch or challenge them in a browser.

What language is tribes-rl written in?

Mainly C. The stack also includes C, PufferLib, WebAssembly.

What license does tribes-rl use?

MIT license: use, modify, and share freely, including commercially, as long as you keep the copyright notice.

How hard is tribes-rl to set up?

Setup difficulty is rated hard, with roughly 1h+ to a first successful run.

Who is tribes-rl for?

Mainly researcher.

Open on GitHub → Explain another repo

This repo across BitVibe Labs

Verify against the repo before relying on details.