{
  "_comment": "PGS (PlayCraft Gameplay Schema) 参考骨架 - 方块放置消行玩法。Agent 以此为起点编写或 fork 玩法规则。",
  "version": "1.0",
  "gameplayType": "block_puzzle",
  "entities": {
    "board": {
      "type": "grid",
      "cols": 10,
      "rows": 10,
      "description": "游戏棋盘，默认 10×10 格子"
    },
    "piece": {
      "type": "polyomino",
      "description": "可放置的方块形状，由多个格子组成的多联骨牌",
      "examples": [
        { "name": "L", "cells": [[0,0],[1,0],[1,1]] },
        { "name": "line3", "cells": [[0,0],[1,0],[2,0]] },
        { "name": "square2x2", "cells": [[0,0],[1,0],[0,1],[1,1]] },
        { "name": "single", "cells": [[0,0]] }
      ]
    },
    "pieceQueue": {
      "type": "slot-array",
      "slotCount": 3,
      "description": "当前 3 个候选方块槽位，3 个都用完后补充新的"
    },
    "score": {
      "type": "counter",
      "initial": 0,
      "description": "当前得分"
    }
  },
  "rules": {
    "place_piece": {
      "description": "将候选方块放置到棋盘指定位置（以方块左上角为锚点）。放置时所有格子必须在棋盘内且未被占用",
      "collisionCheck": true,
      "boundaryCheck": true
    },
    "clear_full_lines": {
      "description": "放置后立即检查所有行与列，若某行或某列全部被占用则消除并得分",
      "clearRows": true,
      "clearCols": true,
      "scorePerLine": 100,
      "multiLineBonusMultiplier": 1.5
    },
    "generate_pieces": {
      "description": "3 个槽位的方块全部用完后，同时生成 3 个新的随机方块",
      "batchSize": 3,
      "distribution": "uniform_shapes"
    }
  },
  "algorithm": {
    "description": "主循环：选择方块 → 放置 → 消行 → 检测失败 → 补充方块",
    "steps": [
      "1. 玩家从 3 个候选槽位中拖拽选择一个方块",
      "2. 拖拽到目标位置，实时高亮可放置区域（canPlacePiece 检测）",
      "3. 放下方块（place_piece），从槽位移除该方块",
      "4. 检测所有行和列是否完整（clearLines），一次性消除所有完整行/列并计分",
      "5. 若 3 个槽位全部为空，生成 3 个新的随机方块（generatePieces）",
      "6. 检测失败条件：若剩余 3 个方块都无法放入棋盘，游戏结束"
    ]
  },
  "winCondition": {
    "type": "endless",
    "description": "无尽模式，无胜利条件，追求最高得分"
  },
  "loseCondition": {
    "type": "no_valid_placement",
    "description": "当前 3 个候选方块都无法放入棋盘任意位置时，游戏结束"
  },
  "testCases": [
    {
      "id": "tc_place_single_cell",
      "description": "放置单格方块到空棋盘",
      "initialState": {
        "board": "10×10 全空棋盘",
        "pieceQueue": [{ "id": 0, "cells": [[0,0]], "color": 1 }, null, null],
        "score": 0
      },
      "action": { "type": "place", "pieceIndex": 0, "position": { "col": 5, "row": 5 } },
      "expectedState": {
        "board": "棋盘 [5][5] 被占用，其余空",
        "pieceQueue": [null, null, null],
        "score": 0,
        "clearedRows": [],
        "clearedCols": []
      }
    },
    {
      "id": "tc_clear_row",
      "description": "放置一个 1×1 方块完成整行消除",
      "initialState": {
        "board": "棋盘第 9 行有 9 个格子被占满（只差 col=9 空着）",
        "pieceQueue": [{ "id": 0, "cells": [[0,0]], "color": 2 }, null, null],
        "score": 0
      },
      "action": { "type": "place", "pieceIndex": 0, "position": { "col": 9, "row": 9 } },
      "expectedState": {
        "clearedRows": [9],
        "clearedCols": [],
        "score": 100,
        "gameOver": false
      }
    },
    {
      "id": "tc_clear_row_and_col",
      "description": "同一个放置动作同时消除一行和一列",
      "initialState": {
        "board": "第 5 行第 0-9 列全满（第 5 行完整），第 3 列第 0-9 行全满（第 3 列完整），在 [3][5] 处放置则同时消除",
        "pieceQueue": [{ "id": 0, "cells": [[0,0]], "color": 3 }, null, null],
        "score": 0
      },
      "action": { "type": "place", "pieceIndex": 0, "position": { "col": 3, "row": 5 } },
      "expectedState": {
        "clearedRows": [5],
        "clearedCols": [3],
        "score": { "min": 200 },
        "gameOver": false
      }
    },
    {
      "id": "tc_invalid_placement_overlap",
      "description": "非法放置：目标位置与已有方块重叠",
      "initialState": {
        "board": "棋盘 [2][2] 已被占用",
        "pieceQueue": [{ "id": 0, "cells": [[0,0],[1,0]], "color": 1 }, null, null],
        "score": 50
      },
      "action": { "type": "place", "pieceIndex": 0, "position": { "col": 2, "row": 2 } },
      "expectedState": {
        "placementRejected": true,
        "score": 50,
        "boardUnchanged": true
      }
    },
    {
      "id": "tc_generate_new_pieces",
      "description": "3 个槽位全部用完后，自动生成 3 个新方块",
      "initialState": {
        "board": "10×10 基本空棋盘",
        "pieceQueue": [{ "id": 0, "cells": [[0,0]], "color": 1 }, null, null],
        "score": 200
      },
      "action": { "type": "place", "pieceIndex": 0, "position": { "col": 0, "row": 0 } },
      "expectedState": {
        "pieceQueueLength": 3,
        "allSlotsRefilled": true,
        "score": 200
      }
    },
    {
      "id": "tc_game_over",
      "description": "游戏结束：所有候选方块都无法放入棋盘",
      "initialState": {
        "board": "棋盘几乎填满，仅剩零散不连续的单格空位，无法容纳任何 L 形或线形方块",
        "pieceQueue": [
          { "id": 0, "cells": [[0,0],[1,0],[2,0]], "color": 1 },
          { "id": 1, "cells": [[0,0],[0,1],[1,1]], "color": 2 },
          { "id": 2, "cells": [[0,0],[1,0],[0,1],[1,1]], "color": 3 }
        ],
        "score": 5000
      },
      "action": { "type": "check_game_over" },
      "expectedState": {
        "gameOver": true,
        "noValidPlacements": true
      }
    }
  ]
}
