Skip to main content

Python SDK for 三國志略 (Histrategy) — AI-powered Three Kingdoms strategy game. Fully file-based, no network required.

Project description

histrategy-sdk

Python SDK for 三國志略 (Histrategy) — AI-powered Three Kingdoms strategy game.

Fully file-based. No network, no server, no in-memory state. Every turn reads from and writes to ~/.histrategy/rooms/<name>/ on disk. Designed for AI agents (OpenClaw, Hermes, Codex) that reset context daily.

pip install histrategy-sdk

Quick Start

from histrategy_sdk import Room

# Create a new game
room = Room.create("my-campaign", faction="shu")

# Play a turn — reads state from disk, executes, writes back
result = room.play("联吴抗曹,攻打襄阳")
print(result["narrative"])

# Agent context resets overnight? No problem:
room2 = Room.load("my-campaign")
result2 = room2.play("休养生息,发展内政")
print(f"Year {result2['year']}, {result2['season']}, Turn {result2['turn']}")
print(f"⚔️{result2['faction_status']['strength']} 🍚{result2['faction_status']['food']}")

File Layout

~/.histrategy/rooms/
  my-campaign/
    world_state.json    # Full game state (engine.to_dict())
    turns.jsonl          # Append-only turn history
    metadata.json        # Room metadata
  multiplayer/shu/
    world_state.json
    turns.jsonl
    metadata.json
  multiplayer/cao/
    ...
  multiplayer/wu/
    ...

API

Room

Method Description
Room.create(name, faction) Create new room + save initial state
Room.load(name) Load room from disk
room.play(decision) Execute turn → auto-save to disk
room.plan() Get advisor suggestions
room.intro() Get intro scene
room.status() Get current faction resources
room.get_turn_history() Read all past turns from disk

DirectEngine

Low-level in-process engine (used internally by Room):

Method Description
DirectEngine(faction) Create new engine
engine.execute(decision) Process turn
engine.to_dict() Serialize state
DirectEngine.from_dict(data) Restore from saved state

TurnResult

Field Type Description
narrative str AI-generated historical chronicle
aftermath str Resource changes summary
state_changes dict Numerical state deltas
new_suggestions list[str] Next-turn strategy suggestions
events_occurred list[str] Character events
npc_actions list[str] NPC faction actions
game_over dict | None Victory/defeat
faction_status FactionStatus Resources and territories
token_usage TokenUsage LLM tokens consumed

Multiplayer

One room per faction. The world_state.json contains ALL factions, so any player can load the state and execute their turn:

# Three players, three rooms, shared game world
shu = Room.create("three-kingdoms/shu", faction="shu")
cao = Room.create("three-kingdoms/cao", faction="cao")
wu  = Room.create("three-kingdoms/wu",  faction="wu")

# Player 1 (Shu)
r = shu.play("联吴抗曹")
# → saves to three-kingdoms/shu/world_state.json

# Player 2 (Cao) — loads the world state that includes Shu's move
# (Note: each room has its own world_state.json copy;
#  for true shared state, all rooms should point to the same file
#  or the orchestrator should sync after each turn)
r = cao.play("南征刘备")

License

MIT — Emergence Science

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

histrategy_sdk-0.3.1.tar.gz (16.9 kB view details)

Uploaded Source

Built Distribution

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

histrategy_sdk-0.3.1-py3-none-any.whl (17.2 kB view details)

Uploaded Python 3

File details

Details for the file histrategy_sdk-0.3.1.tar.gz.

File metadata

  • Download URL: histrategy_sdk-0.3.1.tar.gz
  • Upload date:
  • Size: 16.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.11 {"installer":{"name":"uv","version":"0.11.11","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Debian GNU/Linux","version":"13","id":"trixie","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for histrategy_sdk-0.3.1.tar.gz
Algorithm Hash digest
SHA256 2209f4ed5f0156356c3117c79201a3d43f10042ed49784e5f697320a84ff4d11
MD5 c240cdb5983945a41550f9a355b4d6c2
BLAKE2b-256 bf0b31c133e3d14fe6c1fd8634626ad90f855f30035e2d50620d2491e6db98cf

See more details on using hashes here.

File details

Details for the file histrategy_sdk-0.3.1-py3-none-any.whl.

File metadata

  • Download URL: histrategy_sdk-0.3.1-py3-none-any.whl
  • Upload date:
  • Size: 17.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.11 {"installer":{"name":"uv","version":"0.11.11","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Debian GNU/Linux","version":"13","id":"trixie","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for histrategy_sdk-0.3.1-py3-none-any.whl
Algorithm Hash digest
SHA256 d9f549894efeae057e3b5c24c4002bc6dd28eb352f1de9b4b1ac8aa14a0be83b
MD5 8da038ad0446b448ac21cf292e9775fa
BLAKE2b-256 bb3661e23de8b1c86810da1489a86f801b7ba8aa855f53654e38a9271c89fb12

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