# Follow a game's tree

> Get every game of one line in one request, the root game, its remakes, their expansions and its spin-offs, with the editions and names of each, and use it to tell what someone owns.

Games come in lines. Carcassonne has its expansions and a junior version;
Twilight Imperium was made again three times, and each making has
expansions of its own. A **game tree** is one such line: every game of it,
what each is to the others, and the editions and names each goes by.

Use it when one game is not the right unit: to show a collection grouped
by line, to offer "you own the base game, here are its expansions", or to
decide whether a title someone typed is a game you already have under
another name.

## The tree of a game

```sh
curl "https://api.theboardgamedb.com/v1/games/twilight-imperium-fourth-edition/tree"
```

Any game of the line gives the same tree. The answer, shortened:

```json
{
  "data": {
    "id": "0b6d2a0e-…",
    "root": { "id": "…", "slug": "twilight-imperium", "name": "Twilight Imperium", "yearPublished": 1997 },
    "size": 5,
    "truncated": false,
    "nodes": [
      { "game": { "name": "Twilight Imperium" }, "role": "root", "parent": null, "line": true, "depth": 0, "editions": [], "names": [] },
      { "game": { "name": "Twilight Imperium: Fourth Edition" }, "role": "remake", "parent": "…", "line": true, "depth": 1,
        "editions": [{ "id": "…", "name": null, "language": "fr", "year": 2018 }],
        "names": [{ "name": "Twilight Imperium: Fourth Edition", "language": "en" }] },
      { "game": { "name": "Twilight Imperium: Prophecy of Kings" }, "role": "expansion", "parent": "…", "line": true, "depth": 2, "editions": [], "names": [] }
    ],
    "edges": [
      { "from": "…", "to": "…", "kind": "reimplements", "outside": null },
      { "from": "…", "to": "…", "kind": "expansion_of", "outside": null }
    ]
  }
}
```

Each entry of `nodes` is a game of the tree; `game` is a full game summary,
the same as in search results. `role` says what it is in the line:

| `role`      | What it is                                                                         |
| ----------- | ---------------------------------------------------------------------------------- |
| `root`      | The game the line starts from.                                                     |
| `remake`    | Its parent made again: a new edition that is a game of its own.                    |
| `expansion` | It needs its parent to be played.                                                  |
| `spin_off`  | A game of its own built on its parent (a junior version, a dice game, a sequel).   |
| `sibling`   | Another game of the line that plays on its own, tied to it by a shared expansion.  |

`parent` is the id of the game it hangs from, so the nodes draw as a tree
without reading `edges`; `depth` counts the steps down from the root.

`line` tells the main line from its branches: it is `true` for the root,
its remakes and the expansions of each, and `false` for a spin-off and
everything that hangs from it. To list "Catan and its expansions" without
Catan Junior, keep the nodes whose `line` is `true`.

## How the root is chosen

The root is a game of the tree that plays on its own, redoes no other
game of the tree and is built on none. When several qualify, it is the
oldest; a game whose year is not known comes after those that have one,
then the game with the most links wins. So the root of Twilight Imperium
is the 1997 game, not its best-known edition, and it may change when an
older game of the line is added to the catalog. The tree's `id` does not
change with it.

## Editions and names are not nodes

A French printing, a tenth-anniversary box, a new cover: these are
editions of one game, listed in that game's `editions`. A remake is a node
because its rules changed enough to be another game. The names a game goes
by in every language are in `names`, main names first.

That split is what makes the tree useful for matching. To decide whether
"Die Siedler von Catan" is a game you already hold, look for it in the
`names` of the nodes rather than comparing titles yourself.

## Links to other trees

`edges` holds every link, one per pair of games whichever of the two it
was stated on. Three kinds tie the games of the tree together
(`expansion_of`, `reimplements`, `based_on`). Two more lead out of it:
`contains`, from a box to a game that comes in it, and `integrates_with`,
between two games that can be combined. A big box of three unrelated
games does not make them one line, so the game at the other end is not a
node: it is given in the edge's `outside`.

## A game on its own

Most games are tied to no other. Their tree is one node, `size` is 1 and
`id` is `null`; the game's own `tree` field is `null` too, so you know
before asking:

```sh
curl "https://api.theboardgamedb.com/v1/games/hive"
```

A game in a line carries `tree` with the tree's `id` and `size`.

## Keeping a tree

`GET /trees/{id}` answers the same body by the tree's id. The id is
stable. When two trees turn out to be one line, the older id stays and
the other answers that tree: compare the `id` you get with the one you
asked for and keep the new one. An id whose tree no longer exists answers
404 `tree_not_found`.

Trees follow the catalog: a new expansion joins its base game's tree
within minutes of being listed. An answer holds 200 games at most, the
nearest to the root first, and says so with `truncated`.
