--- license: cc-by-4.0 pretty_name: DraftZero self-play games (Magic The Gathering limited, Foundations) tags: - magic-the-gathering - self-play - mcts - reinforcement-learning - games size_categories: - n<1K --- # DraftZero self-play games Games of **Magic: The Gathering limited** (Foundations, FDN) played by [DraftZero](https://github.com/danieljbrooks/draft-zero)'s agent against itself, with tree search at every decision. Each searched decision is stored as a training example: the position, the search's answer and the game's result. They are what DraftZero's self-play training learns from ([docs/021](https://github.com/danieljbrooks/draft-zero/blob/main/docs/021-self-play-plan.md)). **Status: empty for now.** Games arrive once the self-play loop starts. The layout and format below may still change before the first upload; this card will say when they do. ## What a game is - **The engine:** [XMage](https://github.com/magefree/mage), a full rules implementation of Magic, driven through [MageZero](https://github.com/WillWroble/MageZero). - **The decks:** two decks drawn at random from top players' Foundations Premier Draft decks published by [17lands](https://www.17lands.com/public_datasets) (players with a 60%+ win rate). - **The players:** a policy-value network (first trained to imitate top players' decisions from 17lands replays, then by self-play) searching each decision with Monte Carlo tree search over sampled versions of the hidden cards. Neither side sees the other's hand or decklist. - **The budget:** the number of search simulations per decision is recorded with each game (e.g. `il_bc@100`). - About 169 searched decisions a game; about 100 KB a game, gzipped. ## Format Files are gzipped JSON lines. **One line is one seat's view of one game:** | Field | Meaning | |---|---| | `pair` | the deck pair's index in its run | | `swap` | whether the seats were swapped (each deck pair is played twice, once each way) | | `seat` | `A` or `B` | | `bot` | the player and its search budget, e.g. `il_bc@100` | | `result` | the game's result for this seat: `1` win, `-1` loss, `null` no winner (e.g. the 50-turn cap) | | `records` | the seat's searched decisions, in order (below) | **Each entry of `records` is one decision:** | Field | Meaning | |---|---| | `features` | the position as MageZero encodes it, from this seat's point of view (the opponent's hand hidden): sorted ids of discrete features (cards in zones with their status, life totals, turn and step, ...). Ids are XMage feature hashes (`xmage_feature_hash`, version 1) | | `type` | the decision: `PRIORITY` (cast, play or pass), `CHOOSE_USE` (yes or no, e.g. "attack with this creature?"), `CHOOSE_TARGET` (a target, or which attacker to block) | | `turn` | the game's turn number | | `legal` | the legal options, as indices into DraftZero's action vocabulary ([`assets/vocab/FDN_SPG.tsv`](https://github.com/danieljbrooks/draft-zero/blob/main/assets/vocab/FDN_SPG.tsv)); for `CHOOSE_USE`, `0` is no and `1` is yes | | `visits` | how many search simulations went to each legal option (same order as `legal`): the policy target | | `q` | the search's value of the position for this seat, from -1 (lost) to 1 (won) | | `heuristic` | MageZero's hand-written evaluation of the position for this seat | Planned additions, before or with the first games: the network's prior and each option's mean value, the option actually played, the network version, and a replay log (seeds and choices, so any future encoder can rebuild the positions). ## Reading it ```python import gzip, json from huggingface_hub import hf_hub_download, list_repo_files repo = "danbrooks/draftzero-selfplay-games" files = [f for f in list_repo_files(repo, repo_type="dataset") if f.endswith(".jsonl.gz")] path = hf_hub_download(repo, files[0], repo_type="dataset") for line in gzip.open(path, "rt"): game = json.loads(line) for d in game["records"]: best = d["legal"][max(range(len(d["visits"])), key=d["visits"].__getitem__)] ``` DraftZero's `tools/imitation_scale/selfplay_tables.py` turns these files into training tables. ## License and credits - **This dataset:** [CC BY 4.0](https://creativecommons.org/licenses/by/4.0/). - **[17lands](https://www.17lands.com/)**: every deck comes from its public datasets, licensed CC BY 4.0. Thank you to 17lands and the players who share their data. - **[XMage](https://github.com/magefree/mage)**, the rules engine every game runs in, and **[MageZero](https://github.com/WillWroble/MageZero)** by Will Wroble, the framework DraftZero builds on. - The code that produces the games is MIT-licensed: [danieljbrooks/draft-zero](https://github.com/danieljbrooks/draft-zero). - Magic: The Gathering is a trademark of Wizards of the Coast. This dataset is unofficial and not affiliated with or endorsed by Wizards of the Coast.