{
  "_comment": "PGS (PlayCraft Gameplay Schema) 参考骨架 - 左右选择跑酷玩法。Agent 以此为起点编写或 fork 玩法规则。",
  "version": "1.0",
  "gameplayType": "left_right_parkour",
  "entities": {
    "runner": {
      "type": "player-character",
      "description": "跑酷角色，自动向前移动",
      "fields": {
        "position": "number，当前门板索引（已通过的门板数量）",
        "score": "number，当前累计得分",
        "lives": "number，当前剩余生命值（初始为 config.initialLives）",
        "speed": "number，当前速度倍率（影响动画速度，初始为 config.initialSpeed）",
        "items": "string[]，已收集的道具列表"
      }
    },
    "gate": {
      "type": "choice-node",
      "description": "门板选择节点，包含左右两个选项",
      "fields": {
        "id": "number，门板索引",
        "position": "number，在关卡中的位置",
        "left_option": {
          "label": "string，左门显示文字（如 '+100分'）",
          "effect": {
            "score": "number，得分变化（正/负）",
            "lives": "number，生命值变化（正/负）",
            "speed": "number，速度倍率变化（如 +0.1 表示提速）",
            "item": "string | null，获得的道具（null=无）"
          }
        },
        "right_option": {
          "label": "string，右门显示文字（如 '-1命'）",
          "effect": {
            "score": "number，得分变化",
            "lives": "number，生命值变化",
            "speed": "number，速度倍率变化",
            "item": "string | null，获得的道具"
          }
        }
      }
    },
    "currentGateIndex": {
      "type": "counter",
      "initial": 0,
      "description": "当前待通过的门板索引"
    },
    "gameState": {
      "type": "enum",
      "values": ["running", "game_over", "win"],
      "initial": "running",
      "description": "游戏总状态"
    }
  },
  "rules": {
    "choose_left": {
      "description": "玩家选择左门，应用 left_option.effect",
      "precondition": "gameState === 'running'",
      "effect": [
        "runner.score += gate.left_option.effect.score",
        "runner.lives += gate.left_option.effect.lives",
        "runner.speed += gate.left_option.effect.speed",
        "若 gate.left_option.effect.item !== null，将道具加入 runner.items"
      ]
    },
    "choose_right": {
      "description": "玩家选择右门，应用 right_option.effect",
      "precondition": "gameState === 'running'",
      "effect": [
        "runner.score += gate.right_option.effect.score",
        "runner.lives += gate.right_option.effect.lives",
        "runner.speed += gate.right_option.effect.speed",
        "若 gate.right_option.effect.item !== null，将道具加入 runner.items"
      ]
    },
    "advance": {
      "description": "通过当前门板后，前进到下一个门板",
      "effect": "currentGateIndex += 1；runner.position = currentGateIndex"
    },
    "check_lives": {
      "description": "每次应用效果后检测生命值",
      "condition": "runner.lives <= 0",
      "result": "gameState = 'game_over'"
    },
    "check_finish": {
      "description": "检测是否已通过所有门板",
      "condition": "currentGateIndex >= gates.length",
      "result": "gameState = 'win'"
    }
  },
  "algorithm": {
    "description": "主循环：跑向门板 → 玩家选择 → 应用效果 → 检测结束",
    "steps": [
      "1. 初始化关卡：加载 gates 配置，设置 runner 初始属性",
      "2. 显示当前门板 gates[currentGateIndex] 的左右选项",
      "3. 玩家点击左门或右门",
      "4. 调用 applyGateChoice(state, currentGateIndex, direction) 应用效果",
      "5. 检测 runner.lives <= 0 → gameState = 'game_over'",
      "6. 若未结束，调用 advanceToNextGate(state)：currentGateIndex + 1",
      "7. 检测 currentGateIndex >= gates.length → gameState = 'win'",
      "8. 若游戏继续，回到步骤 2 显示下一个门板",
      "9. 游戏结束时调用 calculateFinalScore(state) 计算最终分数（加成奖励）"
    ]
  },
  "winCondition": {
    "type": "reach_finish",
    "description": "通过所有门板且 runner.lives > 0（currentGateIndex >= gates.length && lives > 0）"
  },
  "loseCondition": {
    "type": "lives_depleted",
    "description": "runner.lives <= 0"
  },
  "testCases": [
    {
      "id": "tc_choose_left_win",
      "description": "全选左门通关：所有门板选左，均为正效果，成功到达终点",
      "initialState": {
        "runner": { "position": 0, "score": 0, "lives": 3, "speed": 1.0, "items": [] },
        "gates": [
          { "id": 0, "left_option": { "label": "+100分", "effect": { "score": 100, "lives": 0, "speed": 0, "item": null } }, "right_option": { "label": "-1命", "effect": { "score": 0, "lives": -1, "speed": 0, "item": null } } },
          { "id": 1, "left_option": { "label": "+200分", "effect": { "score": 200, "lives": 0, "speed": 0, "item": null } }, "right_option": { "label": "-2命", "effect": { "score": 0, "lives": -2, "speed": 0, "item": null } } }
        ],
        "currentGateIndex": 0,
        "gameState": "running"
      },
      "actions": [
        { "type": "choose", "direction": "left" },
        { "type": "choose", "direction": "left" }
      ],
      "expectedState": {
        "runner": { "score": 300, "lives": 3 },
        "currentGateIndex": 2,
        "gameState": "win"
      }
    },
    {
      "id": "tc_choose_right_lose",
      "description": "选右门失败：选择扣命门板导致生命归零，游戏结束",
      "initialState": {
        "runner": { "position": 0, "score": 0, "lives": 1, "speed": 1.0, "items": [] },
        "gates": [
          { "id": 0, "left_option": { "label": "+50分", "effect": { "score": 50, "lives": 0, "speed": 0, "item": null } }, "right_option": { "label": "陷阱！-3命", "effect": { "score": 0, "lives": -3, "speed": 0, "item": null } } }
        ],
        "currentGateIndex": 0,
        "gameState": "running"
      },
      "actions": [
        { "type": "choose", "direction": "right" }
      ],
      "expectedState": {
        "runner": { "score": 0, "lives": -2 },
        "gameState": "game_over"
      }
    },
    {
      "id": "tc_accumulate_score",
      "description": "累计得分：多个门板混合选择，验证分数正确累加",
      "initialState": {
        "runner": { "position": 0, "score": 0, "lives": 3, "speed": 1.0, "items": [] },
        "gates": [
          { "id": 0, "left_option": { "label": "+100分", "effect": { "score": 100, "lives": 0, "speed": 0, "item": null } }, "right_option": { "label": "+50分 +速度", "effect": { "score": 50, "lives": 0, "speed": 0.2, "item": null } } },
          { "id": 1, "left_option": { "label": "+150分 -1命", "effect": { "score": 150, "lives": -1, "speed": 0, "item": null } }, "right_option": { "label": "+80分", "effect": { "score": 80, "lives": 0, "speed": 0, "item": null } } },
          { "id": 2, "left_option": { "label": "道具", "effect": { "score": 0, "lives": 0, "speed": 0, "item": "shield" } }, "right_option": { "label": "+200分", "effect": { "score": 200, "lives": 0, "speed": 0, "item": null } } }
        ],
        "currentGateIndex": 0,
        "gameState": "running"
      },
      "actions": [
        { "type": "choose", "direction": "left" },
        { "type": "choose", "direction": "left" },
        { "type": "choose", "direction": "right" }
      ],
      "expectedState": {
        "runner": { "score": 450, "lives": 2, "speed": 1.0, "items": [] },
        "currentGateIndex": 3,
        "gameState": "win",
        "note": "score=100+150+200=450, lives=3-1=2, 第3关选右得200分"
      }
    },
    {
      "id": "tc_speed_and_item",
      "description": "速度与道具效果：选择含速度加成和道具的门板，验证属性正确更新",
      "initialState": {
        "runner": { "position": 0, "score": 0, "lives": 3, "speed": 1.0, "items": [] },
        "gates": [
          { "id": 0, "left_option": { "label": "磁铁道具+速度", "effect": { "score": 0, "lives": 0, "speed": 0.5, "item": "magnet" } }, "right_option": { "label": "+100分", "effect": { "score": 100, "lives": 0, "speed": 0, "item": null } } }
        ],
        "currentGateIndex": 0,
        "gameState": "running"
      },
      "actions": [
        { "type": "choose", "direction": "left" }
      ],
      "expectedState": {
        "runner": { "speed": 1.5, "items": ["magnet"] },
        "gameState": "win"
      }
    }
  ]
}
