{
  "_comment": "PGS (PlayCraft Gameplay Schema) 参考骨架 - 三消核心玩法。Agent 以此为起点编写或 fork 玩法规则。",
  "version": "1.0",
  "gameplayType": "match3",
  "entities": {
    "board": {
      "type": "grid",
      "cols": 8,
      "rows": 8,
      "description": "游戏棋盘，8×8 格子"
    },
    "tile": {
      "type": "cell-item",
      "colorCount": 6,
      "description": "棋盘格子上的消除元素，共 6 种颜色/类型"
    },
    "score": {
      "type": "counter",
      "initial": 0,
      "description": "当前得分"
    },
    "moves": {
      "type": "counter",
      "initial": 30,
      "description": "剩余步数（由 config 覆盖）"
    }
  },
  "rules": {
    "swap": {
      "description": "玩家交换相邻两个格子（上下左右），若交换后产生 ≥3 连，则有效；否则回退",
      "swapDirection": "orthogonal",
      "revertIfNoMatch": true
    },
    "match": {
      "description": "消除连续 ≥3 个同类型格子（水平或垂直）",
      "minCount": 3,
      "directions": ["horizontal", "vertical"],
      "scorePerTile": 50,
      "bonusThresholds": [
        { "count": 4, "bonus": 100, "description": "消除 4 个获得额外 100 分" },
        { "count": 5, "bonus": 300, "specialTile": "bomb", "description": "消除 5 个生成炸弹特殊块" }
      ]
    },
    "gravity": {
      "description": "消除后，上方格子向下坠落填充空位",
      "direction": "down"
    },
    "refill": {
      "description": "坠落后，顶部补充新的随机格子",
      "from": "top",
      "distribution": "uniform"
    },
    "cascade": {
      "description": "每次补充后重新检查是否有新的匹配，连续消除（连消）",
      "enabled": true
    }
  },
  "algorithm": {
    "description": "主循环：swap → match → cascade → win/lose 检测",
    "steps": [
      "1. 玩家选择两个相邻格子 swap",
      "2. 检测 swap 后是否产生 match（≥3 连）",
      "3. 若无 match，回退 swap；steps 不消耗",
      "4. 若有 match，消除匹配格子，计分，steps - 1",
      "5. 触发 gravity（上方格子下坠）",
      "6. 顶部 refill 新格子",
      "7. 检测新格子是否产生 cascade match，若有则回到步骤 4",
      "8. cascade 结束后检测胜败条件"
    ]
  },
  "winCondition": {
    "type": "score_goal",
    "description": "在 moves 耗尽前达到目标分数（由 config 中 level.goalScore 定义）"
  },
  "loseCondition": {
    "type": "moves_exhausted",
    "description": "moves 归零且未达到胜利条件"
  },
  "testCases": [
    {
      "id": "tc_basic_match",
      "description": "基础三消：水平三连消除",
      "initialState": {
        "board": "3×1 横排三个相同颜色的格子（例如 Red Red Red）",
        "moves": 5
      },
      "action": { "type": "swap", "from": [3, 0], "to": [4, 0] },
      "expectedState": {
        "matchedCount": 3,
        "scoreGained": 150,
        "movesLeft": 4,
        "boardRefilled": true
      }
    },
    {
      "id": "tc_invalid_swap",
      "description": "无效交换：交换后无三连，步数不扣",
      "initialState": {
        "board": "交换后不形成三连的两个格子",
        "moves": 5
      },
      "action": { "type": "swap", "from": [0, 0], "to": [1, 0] },
      "expectedState": {
        "matchedCount": 0,
        "scoreGained": 0,
        "movesLeft": 5,
        "swapReverted": true
      }
    },
    {
      "id": "tc_cascade",
      "description": "连消：消除后新格子产生新匹配",
      "initialState": {
        "board": "消除一组后，下落的格子正好形成新的三连",
        "moves": 3
      },
      "action": { "type": "swap", "from": [2, 7], "to": [3, 7] },
      "expectedState": {
        "cascadeCount": { "min": 2 },
        "scoreGained": { "min": 300 },
        "movesLeft": 2
      }
    },
    {
      "id": "tc_win",
      "description": "胜利：达到目标分数",
      "initialState": {
        "score": 950,
        "goalScore": 1000,
        "moves": 2
      },
      "action": { "type": "swap", "from": [0, 0], "to": [1, 0] },
      "expectedState": {
        "win": true,
        "score": { "min": 1000 }
      }
    },
    {
      "id": "tc_lose",
      "description": "失败：步数耗尽未达目标",
      "initialState": {
        "score": 500,
        "goalScore": 1000,
        "moves": 1
      },
      "action": { "type": "swap", "from": [0, 0], "to": [1, 0] },
      "expectedState": {
        "movesLeft": 0,
        "win": false,
        "gameOver": true
      }
    }
  ]
}
