Metadata-Version: 2.4
Name: mundi-game-sdk
Version: 0.1.4
Summary: Run Mundi JavaScript games and Gymnasium environments from Python
Requires-Python: >=3.10
Description-Content-Type: text/markdown
Requires-Dist: deno<3,>=2.9.8
Provides-Extra: gym
Requires-Dist: gymnasium<2,>=1; extra == "gym"
Requires-Dist: numpy>=1.21; extra == "gym"

# mundi-game-sdk

Python 3.10+ 可用本地或 HTTP(S) 的目录和 ZIP 运行可信的 Mundi 游戏包。pip 会安装执行 JavaScript 的 Deno。

```sh
python -m pip install mundi-game-sdk
```

```python
from mundi import describe_game, run_match

# 指向单独下载的游戏包
source = "./courtyard.zip"
print(describe_game(source)["capabilities"])
player = {"role": "thrower", "controller": {"kind": "builtin", "ai": "duelist"}}
result = run_match(source, {"players": [player, player], "victoryConfig": {"scoreGoal": 1}})
print(result["end"])
```

安装 Gymnasium 扩展后，可以用本地或 HTTP(S) 游戏目录、ZIP 创建单智能体环境。

```sh
python -m pip install 'mundi-game-sdk[gym]'
```

```python
from mundi import make_gym_env

with make_gym_env("./courtyard.zip", config={"victoryConfig": {"scoreGoal": 1}}) as env:
    observation, info = env.reset(seed=42)
    while True:
        observation, reward, terminated, truncated, info = env.step(env.action_space.sample())
        if terminated or truncated:
            break
```

游戏包声明 `headless` 和 `strategy`。SDK 根据角色和内置电脑安排一个策略席位，根据 `observationSchema` 和 `actionSchema` 构造训练空间。可用 `config["players"]` 指定席位。枚举值映射为从 0 开始的 Gym 动作编号。复杂结构可传入 `observation_space`、`encode_observation`、`action_space`、`decode_action`。默认终局返回最后一次决策观察，按胜负计分，无胜负字段时为 0。可通过 `reward(end, seat)` 自定义终局奖励。

`make_gym_env(game_path)` 返回 `gymnasium.Env`，调用 `reset()` 开局，调用 `step(action)` 推进一步。SDK 在 Gymnasium 中用 `Mundi/Game-v0` 注册游戏包适配器。调用方只需传入实际游戏包的路径。
