{
  "openapi": "3.1.1",
  "info": {
    "title": "Go Score Counter (SGF) API",
    "version": "1.0.0",
    "summary": "Counts a finished Go game from its SGF: area or territory scoring, dead stones, komi and the result.",
    "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://playcardsgoscore.usefulweb.app"
    }
  ],
  "paths": {
    "/api/v1/calculate": {
      "post": {
        "operationId": "calculate",
        "summary": "Counts a finished Go game from its SGF: area or territory scoring, dead stones, komi and the result.",
        "description": "Paste a finished Go game as SGF (any board size up to 19×19) and the counter replays it, removes the dead stones and scores it: area scoring (stones on the board plus surrounded empty points, as in Chinese and AGA rules) or territory scoring (surrounded points plus captured stones, as in Japanese and Korean rules), with komi for White. Dead stones come from the territory marks most Go programs write into the SGF at the end of a game, from your own list, or from a rough computer estimate. You get the result in SGF form (B+3.5), the count for both sides, a picture of the final board with territory and dead stones, and the SGF with the counted territory. The Playcards Go table scores with the same engine.\n\nMethodology:\n- The main line of the SGF is replayed from the setup stones: captures are applied and counted per colour; an occupied point or a suicide is an error (ko is not checked, so games from rule sets with other ko rules can still be counted).\n- Dead stones are removed. Every empty area (including the points of the removed stones) that touches stones of only one colour is that colour’s territory; areas that touch both colours are neutral (dame).\n- Area scoring: live stones + territory. Territory scoring: territory + stones captured during play + dead stones removed at the end. White adds komi. Seki is not detected separately: empty points inside a seki touch both colours and stay neutral, as most rule sets count them.\n- Territory marks (TB/TW) in an SGF are how many Go programs store the agreed end of a game: a stone standing on a point marked as the other colour’s territory is taken as dead. The computer estimate plays a few hundred quick random games from the final position and calls a stone dead when the other colour owns its point at the end of most of them — useful for clear cases, unreliable in close fights.",
        "tags": [
          "apps"
        ],
        "x-mcp-tool": "playcards_go_score",
        "x-owner-app": "playcards",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/PlaycardsGoScoreInput"
              },
              "examples": {
                "example1": {
                  "summary": "Finished 9×9 game with territory marks (area scoring)",
                  "value": {
                    "sgf": "(;GM[1]FF[4]SZ[9]KM[7.5]RU[Chinese]PB[Black]PW[White]RE[B+1.5]\nAB[ea][eb][ec][ed][ee][ef][eg][eh][ei][hh]\nAW[fa][fb][fc][fd][fe][ff][fg][fh][fi][bb]\nTB[aa][ab][ac][ad][ae][af][ag][ah][ai][ba][bb][bc][bd][be][bf][bg][bh][bi][ca][cb][cc][cd][ce][cf][cg][ch][ci][da][db][dc][dd][de][df][dg][dh][di]\nTW[ga][gb][gc][gd][ge][gf][gg][gh][gi][ha][hb][hc][hd][he][hf][hg][hh][hi][ia][ib][ic][id][ie][if][ig][ih][ii])"
                  }
                },
                "example2": {
                  "summary": "The same game counted with territory scoring",
                  "value": {
                    "sgf": "(;GM[1]FF[4]SZ[9]KM[7.5]RU[Chinese]PB[Black]PW[White]RE[B+1.5]\nAB[ea][eb][ec][ed][ee][ef][eg][eh][ei][hh]\nAW[fa][fb][fc][fd][fe][ff][fg][fh][fi][bb]\nTB[aa][ab][ac][ad][ae][af][ag][ah][ai][ba][bb][bc][bd][be][bf][bg][bh][bi][ca][cb][cc][cd][ce][cf][cg][ch][ci][da][db][dc][dd][de][df][dg][dh][di]\nTW[ga][gb][gc][gd][ge][gf][gg][gh][gi][ha][hb][hc][hd][he][hf][hg][hh][hi][ia][ib][ic][id][ie][if][ig][ih][ii])",
                    "rules": "territory"
                  }
                },
                "example3": {
                  "summary": "Dead stones listed by hand",
                  "value": {
                    "sgf": "(;GM[1]FF[4]SZ[9]KM[7.5]RU[Chinese]PB[Black]PW[White]RE[B+1.5]\nAB[ea][eb][ec][ed][ee][ef][eg][eh][ei][hh]\nAW[fa][fb][fc][fd][fe][ff][fg][fh][fi][bb])",
                    "deadFrom": "list",
                    "deadStones": "B8 H2"
                  }
                },
                "example4": {
                  "summary": "Beginner game with captures, Japanese rules, territory marks",
                  "value": {
                    "sgf": "(;GM[1]FF[4]CA[UTF-8]SZ[9]KM[6.5]RU[Japanese]PB[Anna]PW[Ben];B[dc];W[gf];B[eg];W[de];B[ff];W[ch];B[gg];W[dh];B[bh];W[bf];B[he];W[ac]\n;B[ee];W[cd];B[gc];W[ed];B[bb];W[fc];B[da];W[eb];B[cg];W[cc];B[dd];W[db]\n;B[dg];W[bg];B[eh];W[id];B[ib];W[gd];B[cf];W[hd];B[ce];W[be];B[fe];W[hb]\n;B[bd];W[bc];B[fd];W[ic];B[ad];W[cb];B[hc];W[hf];B[if];W[ig];B[ie];W[ge]\n;B[gb];W[ga];B[ha];W[fa];B[he];W[ie];B[ih];W[hg];B[fb];W[hb];B[ae];W[ea]\n;B[af];W[gh];B[ec];W[ag];B[ba];W[ca];B[af];W[ii];B[ci];W[ah];B[fh];W[gc]\n;B[ad];W[bd];B[hi];W[aa];B[fi];W[ab];B[bb];W[ef];B[di];W[fb];B[ed];W[bi]\n;B[dh];W[fg];B[ff];W[dc];B[gi];W[gg];B[ch];W[ed];B[ee];W[ia];B[hh];W[ba]\n;B[fd];W[ai];B[df];W[fe];B[dd];W[ef];B[de];W[ff];B[];W[]TB[ei][ii]TW[da][ha][bb][gb][ib][ec][hc][ad][fd][ae][he][af][if])"
                  }
                },
                "example5": {
                  "summary": "The same game with the dead stones estimated by the computer",
                  "value": {
                    "sgf": "(;GM[1]FF[4]CA[UTF-8]SZ[9]KM[6.5]RU[Japanese]PB[Anna]PW[Ben];B[dc];W[gf];B[eg];W[de];B[ff];W[ch];B[gg];W[dh];B[bh];W[bf];B[he];W[ac]\n;B[ee];W[cd];B[gc];W[ed];B[bb];W[fc];B[da];W[eb];B[cg];W[cc];B[dd];W[db]\n;B[dg];W[bg];B[eh];W[id];B[ib];W[gd];B[cf];W[hd];B[ce];W[be];B[fe];W[hb]\n;B[bd];W[bc];B[fd];W[ic];B[ad];W[cb];B[hc];W[hf];B[if];W[ig];B[ie];W[ge]\n;B[gb];W[ga];B[ha];W[fa];B[he];W[ie];B[ih];W[hg];B[fb];W[hb];B[ae];W[ea]\n;B[af];W[gh];B[ec];W[ag];B[ba];W[ca];B[af];W[ii];B[ci];W[ah];B[fh];W[gc]\n;B[ad];W[bd];B[hi];W[aa];B[fi];W[ab];B[bb];W[ef];B[di];W[fb];B[ed];W[bi]\n;B[dh];W[fg];B[ff];W[dc];B[gi];W[gg];B[ch];W[ed];B[ee];W[ia];B[hh];W[ba]\n;B[fd];W[ai];B[df];W[fe];B[dd];W[ef];B[de];W[ff];B[];W[]TB[ei][ii]TW[da][ha][bb][gb][ib][ec][hc][ad][fd][ae][he][af][if])",
                    "deadFrom": "estimate"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Calculation result envelope.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/PlaycardsGoScoreResult"
                }
              }
            }
          },
          "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"
                }
              }
            }
          }
        }
      },
      "PlaycardsGoScoreInput": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "sgf": {
            "title": "SGF game",
            "description": "A Go game in SGF: (;GM[1]SZ[9]KM[7.5];B[ee];W[gc]…). Only the main line is read. Setup stones (AB/AW) count as part of the position.",
            "type": "string",
            "maxLength": 300000,
            "default": "(;GM[1]FF[4]SZ[9]KM[7.5]RU[Chinese]PB[Black]PW[White]RE[B+1.5]\nAB[ea][eb][ec][ed][ee][ef][eg][eh][ei][hh]\nAW[fa][fb][fc][fd][fe][ff][fg][fh][fi][bb]\nTB[aa][ab][ac][ad][ae][af][ag][ah][ai][ba][bb][bc][bd][be][bf][bg][bh][bi][ca][cb][cc][cd][ce][cf][cg][ch][ci][da][db][dc][dd][de][df][dg][dh][di]\nTW[ga][gb][gc][gd][ge][gf][gg][gh][gi][ha][hb][hc][hd][he][hf][hg][hh][hi][ia][ib][ic][id][ie][if][ig][ih][ii])"
          },
          "deadFrom": {
            "title": "Dead stones",
            "type": "string",
            "enum": [
              "marks",
              "list",
              "estimate"
            ],
            "default": "marks"
          },
          "deadStones": {
            "title": "Dead stones (optional)",
            "description": "Points like D4 (A1 = bottom left, no letter I) or SGF pairs like dd. One stone marks its whole chain as dead.",
            "type": "string",
            "maxLength": 2000,
            "default": ""
          },
          "rules": {
            "title": "Scoring",
            "type": "string",
            "enum": [
              "sgf",
              "area",
              "territory"
            ],
            "default": "sgf"
          },
          "komi": {
            "title": "Komi (optional)",
            "description": "Points for White. Empty: the KM property, else 7.5 (area) or 6.5 (territory).",
            "type": "string",
            "maxLength": 6,
            "default": ""
          }
        },
        "required": []
      },
      "PlaycardsGoScoreResult": {
        "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": [
              "size",
              "moves",
              "rules",
              "komi",
              "black",
              "white",
              "winner",
              "margin",
              "result",
              "resultInSgf",
              "deadStones",
              "dame",
              "sgf"
            ],
            "properties": {
              "size": {
                "type": "integer"
              },
              "moves": {
                "type": "integer",
                "description": "Moves in the main line (passes included)."
              },
              "rules": {
                "type": "string",
                "enum": [
                  "area",
                  "territory"
                ]
              },
              "komi": {
                "type": "number"
              },
              "black": {
                "type": "object",
                "additionalProperties": false,
                "required": [
                  "stones",
                  "territory",
                  "prisoners",
                  "dead",
                  "komi",
                  "total"
                ],
                "properties": {
                  "stones": {
                    "type": "integer",
                    "description": "Live stones on the board (area scoring counts them)."
                  },
                  "territory": {
                    "type": "integer",
                    "description": "Empty points (and points of dead stones) surrounded only by this colour."
                  },
                  "prisoners": {
                    "type": "integer",
                    "description": "Stones this colour captured during play (territory scoring counts them)."
                  },
                  "dead": {
                    "type": "integer",
                    "description": "Opposing stones removed as dead at the end (territory scoring counts them as prisoners)."
                  },
                  "komi": {
                    "type": "number"
                  },
                  "total": {
                    "type": "number"
                  }
                }
              },
              "white": {
                "type": "object",
                "additionalProperties": false,
                "required": [
                  "stones",
                  "territory",
                  "prisoners",
                  "dead",
                  "komi",
                  "total"
                ],
                "properties": {
                  "stones": {
                    "type": "integer",
                    "description": "Live stones on the board (area scoring counts them)."
                  },
                  "territory": {
                    "type": "integer",
                    "description": "Empty points (and points of dead stones) surrounded only by this colour."
                  },
                  "prisoners": {
                    "type": "integer",
                    "description": "Stones this colour captured during play (territory scoring counts them)."
                  },
                  "dead": {
                    "type": "integer",
                    "description": "Opposing stones removed as dead at the end (territory scoring counts them as prisoners)."
                  },
                  "komi": {
                    "type": "number"
                  },
                  "total": {
                    "type": "number"
                  }
                }
              },
              "winner": {
                "type": [
                  "string",
                  "null"
                ],
                "enum": [
                  "black",
                  "white",
                  null
                ]
              },
              "margin": {
                "type": "number"
              },
              "result": {
                "type": "string",
                "description": "SGF result: B+3.5, W+0.5 or 0 for a tie (jigo)."
              },
              "resultInSgf": {
                "type": [
                  "string",
                  "null"
                ],
                "description": "The RE property of the file, if any."
              },
              "deadStones": {
                "type": "array",
                "items": {
                  "type": "string"
                },
                "description": "Dead stones as points (A1 = bottom left)."
              },
              "dame": {
                "type": "integer",
                "description": "Neutral empty points (touching both colours)."
              },
              "sgf": {
                "type": "string",
                "description": "The game with RE set and the counted territory (incl. dead stones) as TB/TW marks."
              }
            }
          },
          "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"
              }
            }
          }
        }
      }
    }
  }
}