{
  "openapi": "3.1.1",
  "info": {
    "title": "Board Game Solver API",
    "version": "1.0.0",
    "summary": "Solves Four in a Row and Kalah positions exactly: win, loss or draw and the value of every move.",
    "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://playcardsboardsolver.usefulweb.app"
    }
  ],
  "paths": {
    "/api/v1/calculate": {
      "post": {
        "operationId": "calculate",
        "summary": "Solves Four in a Row and Kalah positions exactly: win, loss or draw and the value of every move.",
        "description": "Enter a Four in a Row position as the moves played so far (column digits 1–7, e.g. 4453) or as a 6-line grid, and the solver searches it to the end of the game: does the player to move win, lose or draw with perfect play, how fast, and what is every column worth. Positions with many empty cells take too long to solve exactly — the solver then stops at the node limit and says so instead of guessing. The Playcards computer player uses the same solver near the end of a game. Kalah endgames work the same way: enter both rows of pits with their stores and who is to move, and the solver plays every line to the end and gives the final store difference for each pit.\n\nMethodology:\n- Exact game-tree search (negamax with alpha-beta pruning, centre columns first, a transposition table of upper bounds and an immediate-win check) from the given position to the end of the game; no heuristics decide the answer.\n- Score convention used by published Four in a Row test sets: 0 for a draw; for a win (43 − stones on the board before the winning stone) ÷ 2, rounded down — that is 22 minus the number of stones the winner has dropped. A loss is the negative. Column scores are the scores after dropping in that column, from the point of view of the player who drops.\n- The search stops at the node limit. Early positions (more than about 20 empty cells) usually need far more nodes than the limit allows; the answer is then “not solved” rather than an estimate. The empty board is a first-player win (Allis 1988, Allen 1988), which this tool cannot verify within its limit.\n- Kalah (6 pits, any number of seeds): exhaustive minimax over every line of play to the end of the game with a table of positions already solved; the value is the final store difference for the player to move with best play by both sides (an extra turn keeps the same player on move). The default rules capture only when the opposite pit holds seeds; the line “empty capture: on” switches to the house rule that also captures the last seed alone.",
        "tags": [
          "apps"
        ],
        "x-mcp-tool": "playcards_board_solver",
        "x-owner-app": "playcards",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/PlaycardsBoardSolverInput"
              },
              "examples": {
                "example1": {
                  "summary": "A win in one move (14 stones)",
                  "value": {
                    "game": "fourinrow",
                    "position": "44444433333322"
                  }
                },
                "example2": {
                  "summary": "Middle game after 23 moves",
                  "value": {
                    "game": "fourinrow",
                    "position": "52753311433677442422121"
                  }
                },
                "example3": {
                  "summary": "Late position from a published test set",
                  "value": {
                    "game": "fourinrow",
                    "position": "2252576253462244111563365343671351441"
                  }
                },
                "example4": {
                  "summary": "Grid input: X threatens on two columns",
                  "value": {
                    "game": "fourinrow",
                    "position": ".......\n.......\n.......\n.......\n...O...\n.XXX.O."
                  }
                },
                "example5": {
                  "summary": "Kalah endgame: an extra turn wins it",
                  "value": {
                    "game": "kalah",
                    "position": "south: 0 0 0 2 1 1 | 20\nnorth: 1 0 2 0 0 1 | 20\nto move: south"
                  }
                },
                "example6": {
                  "summary": "Kalah endgame with the empty-capture house rule",
                  "value": {
                    "game": "kalah",
                    "position": "south: 1 0 0 0 3 0 | 22\nnorth: 0 2 0 1 0 2 | 17\nto move: north\nempty capture: on"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Calculation result envelope.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/PlaycardsBoardSolverResult"
                }
              }
            }
          },
          "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"
                }
              }
            }
          }
        }
      },
      "PlaycardsBoardSolverInput": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "game": {
            "title": "Game",
            "type": "string",
            "enum": [
              "fourinrow",
              "kalah"
            ],
            "default": "fourinrow"
          },
          "position": {
            "title": "Position",
            "description": "Four in a Row: moves as column digits 1–7 from the first move on, or 6 lines of 7 cells (X = first player, O = second, . = empty), top row first. Kalah: “south: 0 0 0 2 1 1 | 20”, “north: …” (pits from each player’s left, store after |) and “to move: south”.",
            "type": "string",
            "maxLength": 400,
            "default": "52753311433677442422121"
          },
          "maxNodes": {
            "title": "Search limit (positions)",
            "description": "The solver stops after this many positions and reports “not solved”.",
            "type": "integer",
            "minimum": 10000,
            "maximum": 5000000,
            "default": 2000000
          }
        },
        "required": []
      },
      "PlaycardsBoardSolverResult": {
        "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": [
              "game",
              "sideToMove",
              "stones",
              "solved",
              "outcome",
              "score",
              "winnerStoneCount",
              "bestMoves",
              "columns",
              "nodes"
            ],
            "properties": {
              "game": {
                "type": "string"
              },
              "sideToMove": {
                "type": "string",
                "enum": [
                  "first",
                  "second",
                  "none"
                ]
              },
              "stones": {
                "type": "integer"
              },
              "solved": {
                "type": "boolean"
              },
              "outcome": {
                "type": [
                  "string",
                  "null"
                ],
                "enum": [
                  "win",
                  "loss",
                  "draw",
                  null
                ],
                "description": "For the side to move, with perfect play by both sides."
              },
              "score": {
                "type": [
                  "integer",
                  "null"
                ],
                "description": "Positive: the side to move wins; 22 minus the stones the winner has on the board when the line is completed (higher = faster). 0 = draw."
              },
              "winnerStoneCount": {
                "type": [
                  "integer",
                  "null"
                ],
                "description": "How many stones the winner has dropped in total when the four is completed."
              },
              "bestMoves": {
                "type": "array",
                "items": {
                  "type": "integer"
                }
              },
              "columns": {
                "type": "array",
                "items": {
                  "type": "object",
                  "additionalProperties": false,
                  "required": [
                    "column",
                    "score",
                    "outcome"
                  ],
                  "properties": {
                    "column": {
                      "type": "integer"
                    },
                    "score": {
                      "type": [
                        "integer",
                        "null"
                      ]
                    },
                    "outcome": {
                      "type": [
                        "string",
                        "null"
                      ]
                    }
                  }
                }
              },
              "nodes": {
                "type": "integer"
              }
            }
          },
          "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"
              }
            }
          }
        }
      }
    }
  }
}