{
  "openapi": "3.1.1",
  "info": {
    "title": "Falling Blocks Placement Solver API",
    "version": "1.0.0",
    "summary": "Find the best spot for a falling four-cell piece on any board, with optional lookahead.",
    "description": "Every endpoint performs the same calculation as the human page and returns inputs, result, units, assumptions, sources, warnings and computedAt. MCP endpoint: /mcp."
  },
  "servers": [
    {
      "url": "https://pixelpierblockfallsolver.usefulweb.app"
    }
  ],
  "paths": {
    "/api/v1/calculate": {
      "post": {
        "operationId": "calculate",
        "summary": "Find the best spot for a falling four-cell piece on any board, with optional lookahead.",
        "description": "Paste a falling-blocks board as rows of “.” and “#”, pick the current piece (I, O, T, S, Z, J or L) and optionally the next one. The solver tries every rotation and column the piece can be dropped into, scores each resulting board by height, holes, transitions and wells, and returns the best placement with the board after it, cleared rows and the runner-up placements. It is the same function that powers the hint and the demo player in Pixelpier’s Blockfall.\n\nMethodology:\n- Pieces use their spawn orientation as rotation 0; rotations 1–3 are quarter turns clockwise inside the piece’s box (4 × 4 for I, 2 × 2 for O, 3 × 3 for the others).\n- Placements: every rotation and column from which the piece can fall straight down from the top of the board. Slides under overhangs and twist moves are not searched.\n- Each placement is scored on the board after it (rows cleared first) with Dellacherie’s features — landing height, eroded piece cells, row and column transitions, holes and well depths — weighted as in El-Ashi (2011), rounded. With a next piece, the score is the average of this placement and the best placement of the next piece after it.\n- “column” is the leftmost column the piece covers and “landingRow” its top row, both counted from 0 at the top-left. Ties go to fewer rotations, then to the left.\n\nA heuristic, not a proof of the optimal move: it looks at most one piece ahead.",
        "tags": [
          "apps"
        ],
        "x-mcp-tool": "pixelpier_blockfall_solver",
        "x-owner-app": "pixelpier",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/PixelpierBlockfallSolverInput"
              },
              "examples": {
                "example1": {
                  "summary": "Long piece into a deep well",
                  "value": {
                    "board": "...........\n...........\n...........\n...........\n...........\n...........\n...........\n...........\n...........\n...........\n...........\n...........\n...........\n...........\n...........\n...........\n.........##\n####.######\n####.######\n####.######\n####.######",
                    "piece": "I",
                    "next": "",
                    "alternatives": 5
                  }
                },
                "example2": {
                  "summary": "T piece with the next piece known",
                  "value": {
                    "board": "......\n......\n......\n......\n#..###\n##.###",
                    "piece": "T",
                    "next": "O",
                    "alternatives": 3
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Calculation result envelope.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/PixelpierBlockfallSolverResult"
                }
              }
            }
          },
          "400": {
            "description": "Malformed JSON body.",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "422": {
            "description": "Invalid input (see errors[]).",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "429": {
            "description": "Rate limit exceeded (see Retry-After).",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          }
        }
      }
    },
    "/api/v1/tool": {
      "get": {
        "operationId": "getToolDefinition",
        "summary": "Inputs, output schema and examples for this tool",
        "responses": {
          "200": {
            "description": "Tool definition.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          }
        }
      }
    }
  },
  "components": {
    "schemas": {
      "Problem": {
        "type": "object",
        "description": "RFC 9457 problem details. 422 responses include per-field `errors`.",
        "required": [
          "type",
          "title",
          "status",
          "detail"
        ],
        "properties": {
          "type": {
            "type": "string"
          },
          "title": {
            "type": "string"
          },
          "status": {
            "type": "integer"
          },
          "detail": {
            "type": "string"
          },
          "code": {
            "type": "string"
          },
          "errors": {
            "type": "array",
            "items": {
              "type": "object",
              "required": [
                "field",
                "message"
              ],
              "properties": {
                "field": {
                  "type": "string"
                },
                "message": {
                  "type": "string"
                }
              }
            }
          }
        }
      },
      "PixelpierBlockfallSolverInput": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "board": {
            "title": "Board (top row first; “.” = empty, “#” = filled)",
            "description": "Width 4–20 cells, height 4–40 rows. Pixelpier’s Blockfall deck is 11 × 21. Any character other than “.” or a space counts as filled.",
            "type": "string",
            "maxLength": 1000,
            "default": "...........\n...........\n...........\n...........\n...........\n...........\n...........\n...........\n...........\n...........\n...........\n...........\n...........\n...........\n...........\n...........\n.........##\n####.######\n####.######\n####.######\n####.######"
          },
          "piece": {
            "title": "Current piece",
            "type": "string",
            "enum": [
              "I",
              "O",
              "T",
              "S",
              "Z",
              "J",
              "L"
            ],
            "default": "I"
          },
          "next": {
            "title": "Next piece (optional lookahead)",
            "type": "string",
            "enum": [
              "",
              "I",
              "O",
              "T",
              "S",
              "Z",
              "J",
              "L"
            ],
            "default": ""
          },
          "alternatives": {
            "title": "Runner-up placements to list",
            "type": "integer",
            "minimum": 0,
            "maximum": 10,
            "default": 5
          }
        },
        "required": []
      },
      "PixelpierBlockfallSolverResult": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "schemaVersion",
          "tool",
          "computedAt",
          "inputs",
          "summary",
          "result",
          "units",
          "assumptions",
          "sources",
          "warnings",
          "presentation",
          "links"
        ],
        "properties": {
          "schemaVersion": {
            "type": "string",
            "const": "1.0"
          },
          "tool": {
            "type": "object",
            "additionalProperties": false,
            "required": [
              "id",
              "name",
              "version"
            ],
            "properties": {
              "id": {
                "type": "string"
              },
              "name": {
                "type": "string"
              },
              "version": {
                "type": "string"
              }
            }
          },
          "computedAt": {
            "type": "string",
            "format": "date-time"
          },
          "inputs": {
            "type": "object",
            "description": "Normalised inputs actually used, including applied defaults."
          },
          "summary": {
            "type": "string"
          },
          "result": {
            "type": "object",
            "additionalProperties": false,
            "required": [
              "width",
              "height",
              "piece",
              "next",
              "placements",
              "best",
              "alternatives",
              "gameOver"
            ],
            "properties": {
              "width": {
                "type": "integer"
              },
              "height": {
                "type": "integer"
              },
              "piece": {
                "type": "string"
              },
              "next": {
                "type": [
                  "string",
                  "null"
                ]
              },
              "placements": {
                "type": "integer"
              },
              "best": {
                "type": [
                  "object",
                  "null"
                ],
                "additionalProperties": false,
                "required": [
                  "rotation",
                  "column",
                  "landingRow",
                  "lines",
                  "score",
                  "cells",
                  "board"
                ],
                "properties": {
                  "rotation": {
                    "type": "integer",
                    "minimum": 0,
                    "maximum": 3
                  },
                  "column": {
                    "type": "integer"
                  },
                  "landingRow": {
                    "type": "integer"
                  },
                  "lines": {
                    "type": "integer"
                  },
                  "score": {
                    "type": "number"
                  },
                  "cells": {
                    "type": "array",
                    "items": {
                      "type": "array",
                      "items": {
                        "type": "integer"
                      }
                    }
                  },
                  "board": {
                    "type": "array",
                    "items": {
                      "type": "string"
                    }
                  }
                }
              },
              "alternatives": {
                "type": "array",
                "items": {
                  "type": "object",
                  "additionalProperties": false,
                  "required": [
                    "rotation",
                    "column",
                    "landingRow",
                    "lines",
                    "score"
                  ],
                  "properties": {
                    "rotation": {
                      "type": "integer"
                    },
                    "column": {
                      "type": "integer"
                    },
                    "landingRow": {
                      "type": "integer"
                    },
                    "lines": {
                      "type": "integer"
                    },
                    "score": {
                      "type": "number"
                    }
                  }
                }
              },
              "gameOver": {
                "type": "boolean"
              }
            }
          },
          "units": {
            "type": "object",
            "additionalProperties": {
              "type": "string"
            }
          },
          "assumptions": {
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "sources": {
            "type": "array",
            "items": {
              "type": "object",
              "additionalProperties": false,
              "required": [
                "title"
              ],
              "properties": {
                "title": {
                  "type": "string"
                },
                "url": {
                  "type": "string"
                },
                "publisher": {
                  "type": "string"
                },
                "retrievedAt": {
                  "type": "string"
                },
                "note": {
                  "type": "string"
                }
              }
            }
          },
          "warnings": {
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "presentation": {
            "type": "array",
            "items": {
              "type": "object"
            },
            "description": "Display blocks used by the human page (same data)."
          },
          "links": {
            "type": "object",
            "additionalProperties": false,
            "required": [
              "human",
              "api",
              "openapi",
              "methodology"
            ],
            "properties": {
              "human": {
                "type": "string",
                "format": "uri"
              },
              "api": {
                "type": "string",
                "format": "uri"
              },
              "openapi": {
                "type": "string",
                "format": "uri"
              },
              "methodology": {
                "type": "string",
                "format": "uri"
              }
            }
          }
        }
      }
    }
  }
}