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.2.1.tar.gz (15.7 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.2.1-py3-none-any.whl (16.2 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: histrategy_sdk-0.2.1.tar.gz
  • Upload date:
  • Size: 15.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.5

File hashes

Hashes for histrategy_sdk-0.2.1.tar.gz
Algorithm Hash digest
SHA256 177015cecefc43a14eab8910846fd0ae794b11d462310edf544799b641f30473
MD5 adffd12e1a7accc9109c0716b47767f2
BLAKE2b-256 ebf932168d0a3942dd25065b1cfa9227531013433e63f765cc10a1c26ad726ba

See more details on using hashes here.

File details

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

File metadata

  • Download URL: histrategy_sdk-0.2.1-py3-none-any.whl
  • Upload date:
  • Size: 16.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.5

File hashes

Hashes for histrategy_sdk-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 47862d0eaec5e61b96dd47848e2088d77d65ca0ab7eae8f9fe6eaa800d07f655
MD5 2b1bcd7b0ee14faab68d3d3307830fa0
BLAKE2b-256 0d9dc68622cede2349fc81a72beeb0f3553e3209c6cd3c4c5fb50bb569b8709b

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