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.0.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.0-py3-none-any.whl (17.2 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: histrategy_sdk-0.3.0.tar.gz
  • Upload date:
  • Size: 16.9 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.3.0.tar.gz
Algorithm Hash digest
SHA256 fe9387a638752ee4522e1e599ab273079fd00c16eb17e2a123c52a4a0d7a9861
MD5 88f5e86c1f35a801e505d3b5c87462b7
BLAKE2b-256 092cb6c819c625b10d4ed8a354cf31453b5a1e0c993e0955d945c29b4179600d

See more details on using hashes here.

File details

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

File metadata

  • Download URL: histrategy_sdk-0.3.0-py3-none-any.whl
  • Upload date:
  • Size: 17.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.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 25585056d14dc14e00e40e22ab64531685ce9f7ede318b648eafa69d40af2f48
MD5 878023399f93a9134c60b105d0ab159a
BLAKE2b-256 e4ace9ab68b91b6e48b77ea6bccefa67a695962e5d3649f8fa994be1dc795291

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