Skip to content

About

LLM narrative strategy games, including Three Kingdoms, Rome and Nanming

Topics

Resources

Contributing

Stars

38 stars

Watchers

0 watching

Forks

Latest commit

 

History

801 Commits

Folders and files

Repository files navigation

Histrategy (三國志略)

An open-source, AI-powered historical strategy game.

In 207 AD, the Han dynasty crumbles. Warlords vie for control of the realm. You take command — write your own chapter in history. Or re-live the chaos of 44 BC Rome, where Octavian, Antony, and Cleopatra struggle for supremacy.

Python 3.11+ License: MIT Made by Emergence Science


Scenarios

Scenario Year Factions Language
Three Kingdoms 207 AD Cao Cao, Liu Bei, Sun Quan English, 中文
Rome Triumvirate 44 BC Octavian, Antony, Cleopatra, Senate English, 中文
Southern Ming (山河鼎革) 1645 AD Southern Ming, Qing, Peasant Army, Zheng Clan 中文

🏠 《山河鼎革》已停止云端服务 — 自建即可继续游玩(scenario id: nanming)。 云端(emergence.science)不再接受新房间,但源码完全开放:克隆本仓库后本地运行即可体验全部 4 个势力。安装见下方 Quick Start。

Quick Start

Run locally from source

Use Python 3.11 or later with its sqlite3 module. SQLite runs in the Python process, so local play needs neither a database server nor the sqlite3 command-line tool.

git clone https://github.com/emergencescience/histrategy.git
cd histrategy
python3 -m venv .venv
source .venv/bin/activate
python -m pip install -e ./histrategy-engine -e '.[web]'

# Set a provider key to enable LLM-powered gameplay.
export DEEPSEEK_API_KEY="your-key"
export HISTRATEGY_DATA_DIR="$PWD/.histrategy-data"
python -m uvicorn histrategy.server.api:create_app --factory --host 127.0.0.1 --port 8080

Open the local game room UI or the API docs. The server stores rooms in .histrategy-data/histrategy.db with the command above. Without a model key, you can test the local server with deterministic settlement and fallback chronicles.

  • To use an OpenAI-compatible endpoint, set LLM_API_BASE, LLM_API_KEY, and LLM_MODEL in the server environment.
  • To enable Southern Ming for self-hosting, set HISTRATEGY_ALLOW_RETIRED_SCENARIOS=1 before starting the server.
  • To use PostgreSQL, install with '.[web,db]' in place of '.[web]' and set HISTRATEGY_DATABASE_URL to the connection URL.

Run with Docker Compose

export DEEPSEEK_API_KEY="your-key"
docker compose up --build -d

Open the local game room UI. Compose mounts .histrategy-data/ for SQLite and backups.

Programmatic use with the local SDK

After installing the app and engine from source, install the SDK into the same environment:

python -m pip install -e ./histrategy-sdk
from histrategy_sdk import Room

room = Room.create("my-game", faction="cao", scenario="three-kingdoms", lang="en")
result = room.play("Develop agriculture and stockpile grain.")
print(result["narrative"])

Engines

Engine Description LLM Best For
V3 (default) Hybrid: deterministic base + LLM nonlinear layer + guardrails When configured Production play
V2 Deterministic settlement (the base layer of V3) No LLM in settlement Offline, testing, balance tuning
V1 Single LLM call per turn simulating the whole world — Removed 2026-10-03 (hallucinated numbers)

V3 is the default — no environment variable required. Set HISTRATEGY_ENGINE=v2 only to force the deterministic engine (offline/testing).

Architecture

histrategy/              # Full game: FastAPI server, web UI
histrategy-sdk/          # SDK for players: Room, DirectEngine (file-based)
histrategy-agent/        # Agent integration: TurnProcessor, IM adapters
histrategy-engine/       # Core engine: WorldState, TurnController, formulas

The app and Agent use histrategy-engine. The SDK also uses the main app for in-process play.

Key Features

  • Persistent games: Web rooms are stored in the database. The local SDK uses files and can resume with Room.load(name).
  • Multi-scenario: Three Kingdoms and Rome Triumvirate supported. Extensible design.
  • Bilingual: English and Chinese supported at the SDK level. Pass lang="en" or lang="zh".
  • AI NPCs: Opposing warlords make their own decisions based on personality and situation.
  • Agent-native: Designed for Hermes, OpenClaw, and other AI agents to host multiplayer games.

For AI Agents

Install the skill to let your agent host strategy games in any chat:

# OpenClaw
cp histrategy-agent/skills/openclaw/SKILL.md ~/.openclaw/skills/histrategy.md

# Hermes Agent
hermes skills install https://raw.githubusercontent.com/emergencescience/histrategy/main/histrategy-agent/skills/hermes/SKILL.md

Documentation

License

MIT © Emergence Science

About

LLM narrative strategy games, including Three Kingdoms, Rome and Nanming

Topics

Resources

Contributing

Stars

38 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages