How to (maybe) win at Riftbound
Training a neural network to play Riftbound against itself, to find out which cards deserve a slot in my deck. Work in progress.
· active
- reinforcement-learning
- simulation
- riftbound
- python
- pytorch
This page follows the project as it goes. I update it after each round of work. Last updated: 6 November 2026.
New since October: the first long training runs, two new sets in the card pool, decks taken from a real tournament, one model per legend, reward shaping, and play KPIs that show how the models play and not only whether they win. Six legend models now clear the strength bar.
I started playing Riftbound in late April 2026, after ten years of League of Legends. I'd wanted to get into a card game for a long time. I played Yu-Gi-Oh! in college and was interested in Magic too, but I always ran into the same wall: the game had existed for twenty years and there were thousands of cards to learn before I could even read the board. Riftbound is young, the card pool is small, the rules fit in one PDF, and everyone is still figuring it out. I was into it right away and wanted to play more.
The problem
The hard part of a card game is choosing the deck. The best players settle that question by playing day and night for several weeks, until the meta settles and they know which forty cards work. I, however, don't have the time nor the skill to know which cards are good and which are better.
What I do have is a laptop, and a laptop can play while I sleep. So instead of grinding the games myself, I built a simulator, trained models to play it against each other, and let them grind. If a model plays a few thousand games with a given legend, I can measure how much each card contributes to winning, and use that to decide what stays in the deck and what goes.
It can even go further when coupled with an engine that reads the game state, and can evaluate how each card individually affects the game.
In practice this turned into four pieces of work: a rules engine, an RL environment, a training loop, and an evaluation. I built them in that order, with the evaluation giving the directions for the next iteration.
1. Teaching a computer the rules
There's no public Riftbound engine (at least when I started working on this), so I wrote one: a Python rules engine that takes two decks and plays a full legal game, listing every legal action at every priority window.
I pulled 1,064 raw card entries (alternate arts and promos included), reduced them to 749 unique cards, and translated every ability into a JSON format the engine can interpret. Since then Vendetta and Radiance came out, and all of their cards are in too (182 and 172 of them), which brings the pool to 1,083 cards. Diana's text, "[Ambush] When you play a spell, buff me +2", becomes:
[
{ "type": "keyword", "keyword": "Ambush" },
{
"type": "triggered",
"trigger": { "event": "on_spell_played", "subject": { "entity": "controller" } },
"effects": [{ "action": "buff", "target": { "entity": "self" }, "value": 2 }]
}
]
In September the card pool needed 73 distinct effect actions, each with its own handler, and after two new sets there are about 160: draw, kill, banish, recycle, stun, grant a keyword, look at the top of the deck, reduce a cost, restrict what the opponent can play this turn, and so on. Then there are the rules themselves. The core rulebook is 65 pages (rules 000 to 729): phases, the chain, combat, showdowns, hidden cards, legend levelling, replacement effects.
I only trusted the engine once I'd gone through the rulebook clause by clause. I kept a checklist of every rule that applies to a 1v1 game and wrote a test for each one. The first run passed 26 tests out of 47, with some initial bugs that teach a lot about the game's specificities :
- Stun clears at the stunned player's next Ending Step, not at the start of their next turn. This can cause some situations where a unit is stunned for nearly two turns.
- A Recall is not a Move (rules 617 and 618). When a unit is sent back to base by a recall, "when this unit moves" abilities don't trigger, the unit doesn't exhaust, and effects that block movement can't stop it. The engine treated every change of location as a move, which fired triggers that should have stayed quiet.
- A token that leaves the board ceases to exist (rule 177.1). It never reaches the trash. The engine was putting dead tokens in the trash like any other unit, which silently inflated every "count cards in your trash" effect.
Today the compliance suite has 82 tests and all 82 pass, alongside card-level and interaction suites. A stress run of 700 full games with random and real decks finishes with zero crashes and zero invariant violations. That last check is the one I care about most: the list of legal actions must never be empty and every game must end with a winner, otherwise the training loop learns from broken games.
The engine keeps growing with the game. Each new set brings new effects, and you have to constantly adapt and add new cards to an ever growing database (thank god we start having rotations next year).
Long training runs turned out to be the best test suite I have. A policy that plays a hundred thousand games tries every action the engine offers, millions of times, in combinations no hand-written test would think of. No Riftbound card allows an infinite loop, so any game that reaches the step cap gets flagged and inspected, and conditions the engine can't interpret now stop the game instead of being guessed. Between October and November about forty commits went into card coverage, and every card that appears in the tournament decks (section 4) now has its own behaviour test.
A few rules also moved closer to the real table. Activated abilities go on the chain like spells, so they can be answered and countered. "You may" effects are a real choice for the player. Units can be played to any battlefield you control (rule 355.2.a), which gives every unit play several destinations. That last one has a cost: random play went from about 2,050 to 1,310 engine steps per second. I'm happy with that trade, since the agents should see every move a real player could make.
2. Making it a game an agent can play
A rules engine isn't an RL environment yet. Riftbound is awkward for reinforcement learning in three ways, and that's where most of the design work went.
The action space has no fixed shape. In the channel phase there's one legal action. In the action phase there can be hundreds, each one a concrete combination of card, payment, target and option. Flattening that into a fixed grid would give something huge and almost entirely empty. So the network scores the list of legal actions directly, and decodes each action as a short path: action type, then which card (a pointer to a token in the encoded state), then which target (another pointer), then any residual variant. The probability of an action is the product of those four conditional probabilities. There's no cap on the number of legal actions, and the network thinks about which card to play through its learned embedding rather than a slot index.
The state is a set, not a grid. Every entity in the game (a card in hand, a unit on a battlefield, a rune, the legend) becomes a token: a card embedding plus a 52-dimensional feature vector with kind, owner, location, might, damage, cost, domain, keywords, facedown flag. A small transformer attends over that set, with a global token for phase, turn, score and battlefield control.
The encoder grows with what I see in the replays. The model used to attack into bigger stacks (0.58 losing attacks per game, where the greedy heuristic made none), because it had to add up Might across unit tokens by itself. Battlefields now carry each side's total Might, and every move or attack carries the balance it would leave there. The chain is encoded too, and cards playable from the trash get their own token. Older checkpoints still load, because the new inputs start at zero, so a model keeps what it learned every time the input grows.
The card embedding went through two versions. The first was a plain lookup table, one row per card. The second, which is the current one, adds a 182-dimensional structural vector built from the parsed abilities (ability types, trigger events, effect actions, target entities, condition operators, log-compressed numbers) and a learned projection of it. The point is that a card drawn twice in the whole training run still shares representation with every other card that does the same thing. The small preset has about 0.6M parameters, sized so a training batch runs on my laptop CPU. The larger presets go up to 12M and assume a GPU (the training runs below use the 3M medium preset). There's also a recurrent variant with a GRU between the encoder and the heads; it's implemented and tested but not trained yet, so I have nothing to say about it.
The opponent's hand is hidden. The observation encoder is strict about this. The network sees the opponent's hand size and deck size, never the contents, the same as a human would. That's fine for the policy, but tree search needs concrete cards to simulate forward, and this is the part of the project that changed the most.
Version one sampled a few concrete worlds, ran a separate search in each, and added up the root visit counts. That's Perfect Information Monte Carlo. It's simple, and it has a known weakness called strategy fusion: each world's search behaves as if it will later find out which world it's in, which a real player never does. The sampled worlds were also permutations of the opponent's actual deck, which gives the search more than a player at the table would have.
Version two, the current one, is single-observer information-set MCTS
(Cowling, Powley and Whitehouse, 2012): one tree over information sets keyed
by the visible action history, a fresh sample of the hidden cards on every
iteration, and selection that only counts actions available in the current
sample. The hidden cards are drawn from the pool the opponent's legend could
legally run given what's public (domain identity, at most three copies minus
the copies already seen, Signature rules), not from their real list. The
full-knowledge belief is still there behind an explicit oracle flag, for
ablations, and every agent label says which belief it used. What's still
approximate is written in the module docstring: statistics are pooled at
opponent nodes, and the belief is uniform over legal cards rather than a
posterior over what the opponent's past actions imply.
3. Training
The main loop is PPO self-play: play a batch of games with the current policy on both seats, +1 to the winner and -1 to the loser, GAE advantages, clipped surrogate update, checkpoint, repeat. For anyone who wants to compare: γ = 0.995, λ = 0.95, clip 0.2, entropy coefficient 0.01, value coefficient 0.5, three epochs, minibatch 64, Adam at 3e-4, a 60-turn cap and a 5,000-step cap per game. Every history entry carries that block plus the draw and cap counts, so a run can be read without opening the code.
On top of that:
- Vectorised rollouts. Sixty-four games run in lockstep, so each step is one batched forward pass instead of sixty-four tiny ones.
- A league. Every N iterations I freeze a snapshot into a pool and play
half of each rollout against it. Opponents are sampled with AlphaStar's
prioritised fictitious self-play weighting,
(1 - p)^2wherepis the live policy's win rate against that snapshot, so training time goes to the opponents it still loses to. The win rate is smoothed with four virtual games at 0.5, because at my scale a single game would otherwise pushpstraight to 0 or 1. - Deck sampling as an explicit argument. Training games can be played on uniformly random legal decks, on the scraped community lists, on perturbed versions of those lists (a few legal swaps away), or a mix. The choice is stamped into every result file. A number measured on random decks and a number measured on real lists aren't the same number, and I want the file to say which one it is.
- An expert-iteration variant. An AlphaZero-style loop where the search is the teacher: run IS-MCTS at each decision, then train the network to match the improved visit counts and the final outcome. It's expensive. On the laptop, a shallow search (2 determinisations, 6 iterations) costs about 0.4 s per decision; a deeper one (8 by 32) about 9.5 s, almost all of it batch-1 network calls at every tree node. Batching the leaf evaluations is the next thing to do there.
Throughput, measured on the laptop CPU with the small preset:
| Configuration | Games/s | ms per decision | Network share of time |
|---|---|---|---|
| Random agents (engine only) | 48 to 64 | 0% | |
| Policy, batch 1 | 0.96 | 15.1 | 85% |
| Policy, batch 64 | 4.8 | 3.1 | 57% |
| Policy, medium preset (3M), batch 64 | 1.5 | 9.2 | 84% |
The network forward pass is 57% to 85% of rollout time, so a GPU is the first lever. Amdahl's law caps the gain at roughly 2x for the small preset and 6x for the medium one, and after that the Python engine is the wall. Multi-process rollouts exist for that second stage. One night of 64-game batches is around 140,000 games at the small preset.
The first long run
In October I moved training to a MacBook with an M3 Pro, which PyTorch can use as a GPU. A PPO update at the medium preset went from 6.7 s on the CPU to 2.9 s on the GPU, while rollouts kept the same speed since they're bound by the Python engine, as the Amdahl estimate above said they would be.
That run was the baseline: standard PPO settings and pure self-play against a league of its own snapshots. It played about 101,000 games, reached the level of the greedy heuristic within the first 6,000, and settled there:
| first ~10k games | 10k to 32k | 32k to 64k | 64k to 101k | |
|---|---|---|---|---|
| vs random | 76% | 82% | 86% | 83% |
| vs greedy | 50% | 51% | 48% | 48% |
| vs untrained network | 69% | 70% | 69% | 70% |
That plateau is the textbook behaviour of pure self-play. Its snapshots all end up about the same strength (even the one from the first ~1,300 games still won 46.4% of 1,568 games against the live model), so the league stops giving any direction, and nothing in it rewards beating a plan it never meets. The second version of the loop is built around that:
- The opponent pool mixes its own snapshots with fixed agents (greedy and random, from both seats), the same idea as AlphaStar's league, where some opponents exist only to be beaten.
- Each update stops early once it has moved the policy far enough (a KL target), and the entropy bonus is tunable, so the policy keeps exploring for longer.
- A run can start from a copy of the greedy heuristic (behaviour cloning) and spend its compute on what comes after greedy instead of on getting there.
- Evaluation uses 100 seeds per opponent every 100 iterations. With 40 games per opponent a win rate is only known to about ±15 points, which is too coarse to see a plateau move.
Reward shaping
A single win or loss at the very end of a game says little about which of the hundred decisions before it were good. So each decision now also gets a small reward for what happened until the same player's next decision, kept small enough that winning always matters more:
- v1: ±0.05 per point scored or conceded, and ±0.02 per point of Might killed or lost. A 5-Might unit is worth about two points, and an even trade is worth nothing.
- v2 adds ±0.02 per card drawn and per rune channeled compared with the opponent, and -0.03 for a spell that resolves without changing anything. A Temporary unit dying doesn't count as a loss, since it dies anyway and sacrificing it is part of LeBlanc's plan.
Each term comes from a habit I noticed in the replays and then counted over thousands of games (more on that below). Credit goes to the decision that caused the outcome: combat damage only resolves once the opponent passes, so a lost fight is charged back to the attack and not to the pass. Points are also capped at the winning total, because a few cards win the game outright by scoring 999.
One model per legend
Each legend in Riftbound has its own plan. Kennen fills his trash for Lightning Rush and Rhasa, Akali moves her units twice in a turn, LeBlanc sacrifices her Temporary units. One network could learn all of them in principle, but at my scale it settles on an average plan.
So the 15 most played legends now get their own model, starting from the generalist (the rest of the field is piloted by the generalist). Each one plays its legend's tournament lists against the other legends' models, and a script rotates through the legends so they all train against opponents that keep improving too. It's also the closest I can get to a real metagame, since each model meets the others as often as that legend is actually played.
To check it was worth it, every legend's games are played twice on the same seed and the same deck, once with the specialist piloting and once with the generalist. Over 200 games per legend, the specialists win 69.9% against 51.7% for the generalist, +18.3 points on average. Kennen, whose plan is the most specific, gains the most (+39 points). LeBlanc and Mordekaiser, which the generalist already played well, gain the least (+5 and +7).
A round-robin between the 15 models (20 games per pairing, each win rate weighted by how much of the field that opponent represents) puts LeBlanc first at 73.5%, then Mordekaiser (68.7%), Master Yi (61.6%), Kai'Sa (60.7%) and Rengar (60.5%). At the bottom are Seraphine, Vex and Orianna, which are also the three models furthest from the bar below. So for now this ranks the models more than the legends, and it will become a statement about the meta as the weaker models catch up.
I also tried a cheap form of search on top: re-scoring the model's top moves one step ahead with its own value estimate. It scored the same as the plain policy (95.5% against random, against 96.0% without), so search will come back once the value network is stronger.
Measuring strength
A checkpoint is played against fixed anchors: a random agent, a deterministic greedy heuristic that knows nothing beyond cost and might (it beats random about 87% of the time on tournament decks), and the same architecture at random initialisation. Every match is mirrored four ways (same seed, both decks, both seats), because the first player wins about 56% of games and the better deck would otherwise leak into every number. Every rate comes with a Wilson 95% interval, and any pool of agents (checkpoints, search versus no search, oracle versus legal-pool belief) can be fitted with Bradley-Terry to get an Elo anchored at random = 0. Training logs the anchor results every N iterations, and the stop condition reads anchor Elo instead of losses: stop when the best Elo hasn't moved by a margin over the last few evaluations, and flag it when the latest Elo drops well below the running best.
Greedy beating random only 87% of the time says more about greedy than about the game: it's a short tempo script that knows nothing about card text. Riftbound rewards good decisions far more than that, and a decent player should almost never lose to someone clicking at random. That's why I set a bar before trusting a model: until it wins at least 90% against greedy and 99.5% against random, over 200 games, its card statistics mostly describe its own mistakes. Those are minimums, and a strong model should clear them comfortably. A script keeps training the legends below the bar, measures them again after each cycle, and lets each one go once it clears.
On 6 November, six of the 15 legend models clear both bars (200 games per opponent, seats alternating, intervals of about ±4 points):
| Legend | vs greedy | vs random | Clears |
|---|---|---|---|
| Mordekaiser | 95.0% | 100.0% | yes |
| Ekko | 95.0% | 99.5% | yes |
| Nasus | 92.0% | 99.5% | yes |
| Rengar | 92.0% | 99.5% | yes |
| LeBlanc | 91.0% | 100.0% | yes |
| Master Yi | 91.0% | 100.0% | yes |
| Kai'Sa | 95.0% | 99.0% | not yet (random) |
| Lillia | 90.0% | 98.0% | not yet (random) |
| Riven | 90.0% | 98.0% | not yet (random) |
| Kennen | 88.5% | 99.5% | not yet (greedy) |
| Evelynn | 86.0% | 99.5% | not yet (greedy) |
| Vex | 86.0% | 97.5% | not yet (both) |
| Seraphine | 81.5% | 97.5% | not yet (both) |
| Akali | 80.5% | 99.5% | not yet (greedy) |
| Orianna | 72.0% | 95.0% | not yet (both) |
The final measurement is separate from the quick checks the training script runs after each cycle. Kennen and Evelynn reached 90.0% and 91.5% in those checks and came in just under on the final one, so they go back into the rotation. Kai'Sa, Lillia and Riven are past the greedy bar and only need the last points against random, which the cycle checks didn't measure until now.
How it plays
A win rate says a model got better, not what it learned. So I added play KPIs. Every generation of a legend's model replays the same games (same seeds, same decks, same seats), and I count showdowns won, spells that changed nothing, spells that flipped a showdown, attacks where all my units die and none of theirs, games lost after leading by 3 points or more, and a few legend-specific combos. Each column below is 100 games per legend for the 15 legends, 1,500 games, averaged across legends, and every column was measured on the current engine so they compare directly:
| first legend models | 2 November | reward shaping v2 | |
|---|---|---|---|
| Win rate vs the generalist | 55.5% | 65.5% | 71.4% |
| Showdowns won | 43.7% | 46.9% | 49.3% |
| Games thrown from a 3-point lead (per 100) | 6.4 | 5.7 | 5.1 |
| Showdown spells that changed nothing | 70.6% | 71.1% | 74.0% |
| Legend ability used when available | 7.1% | 8.4% | 7.9% |
| Kennen: trash size on turn 5 | 7.9 | 9.7 | 10.2 |
| Kennen: Lightning Rush per game | 0.95 | 1.52 | 1.56 |
(The 2 November column uses the checkpoint saved right after that round of training.)
Each generation wins more against the generalist, wins more showdowns and gives away fewer leads, and Kennen's model clearly learned its plan: over 10 cards in the trash by turn 5, and more than half a Lightning Rush per game above the first models. The two behaviours v2 aimed at directly haven't moved yet. Showdown spells are still mostly cast for nothing and legend abilities are rarely used, so they're the target of the next round of shaping.
A training curve also can't tell me whether the model is learning Riftbound or something that happens to work in my simulator. So there's a replay viewer. Any game, random agents or a checkpoint against itself, is recorded as a full state snapshot per action, and a small HTML page lets me scrub through it turn by turn, with card art on hover and the network's value estimate at each step. Watching the model make a decision I disagree with, then working out which of us is right, has been the most useful debugging tool in the whole project. It's also just fun. It now shows each player's legend and champion, what each action targeted, the chain, and what a "look at the top of your deck" saw and kept. Most of the KPIs above started as something odd I saw in a replay, then counted over thousands of games to make sure it wasn't a one-off.
4. The card statistics
All of the above exists to answer one question: does this card deserve a slot in this deck?
Version one answered it with a single number per card: the win rate of games where the card was in the deck. It's the obvious statistic, so I started there. The main issue of this method is that it doesn't say much about the card in itself. The games were keyed by the thirty scraped decklists, so each card's rate was the rate of whichever list it sat in. Draws were counted for both sides, and the first-player edge was in there too.
Version two keeps three rates per (legend, card) pair, each with a Wilson interval, adjusted for seat, with draws out of the denominator:
- Games in deck: how often games are won when the card is in the list.
- Games in hand: how often games are won when the card was actually drawn.
- Improvement when drawn: the difference between the two. The idea is to answer the question "Did this card help ?".
The real answer, though, is a paired experiment. Take a base deck and a variant that differs by exactly one swap. For each of N seeds, play the same seed (same opponent deck, same shuffles until the swapped card matters, same agent RNG, same seat) once with each list, and record the paired difference. Most seeds come out identical under both lists, because the swapped card was never drawn or was drawn when it didn't matter, so their difference is exactly zero and only the seeds where the card changed the outcome count. A ±2-point resolution needs a few hundred paired seeds instead of the roughly 2,400 games per cell an unpaired comparison would need, and the tool prints how many this particular experiment needs from the observed variance.
The first smoke test, with the greedy agent, 60 paired seeds and two candidate swaps, changed the outcome in 2 or 3 seeds out of 60. That's not a result about the cards yet, but more of a measurement of how much play one deck slot actually gets, and it says I need several hundred seeds before it can tell anything.
Decks come from two sources. The real lists first came from the thirty most popular community decks on Piltover Archive. Since the end of October they come from an actual tournament: the Showdown 25k in Sacramento, 723 decks, of which I keep the 99 best placed, with each legend's share matching how often it was played there (Riven 13 lists, Kennen 8, Kai'Sa and Akali 5 each, 37 legends in total). Every one of them goes through the deck builder's rules, which doubles as a check on the card database. I also wrote a deck builder that generates random decks respecting every construction rule: domain identity, exactly 40 cards, at most three copies of a card, a chosen champion matching the legend's tag, twelve in-domain runes, three battlefields. Uniformly random decks tell me whether a card is fine in a vacuum, which isn't the question I'm asking, so the builder can also perturb a real list by a few legal swaps, and that's what ablations run against by default.
Every card table and every ablation result names the agent it was measured with and the opponent distribution it was measured against. A card's value is a property of the card, the player and the meta together, and I want the output to say so rather than let a reader assume otherwise.
No tier list yet. The agent playing the games is the biggest source of uncertainty, and a per-card number is mostly a statement about the agent. That's what the bar is for: once a legend's model clears it, I start trusting what it says about that legend's cards. Six legends are there now, so the first card reports can start with them.
By the numbers
| Engine + training code | ~38,000 lines of Python (~23,800 in September) |
| Unique cards implemented | 1,083 (749 in September) |
| Effect action handlers | about 160 (73 in September) |
| Structural card features | 182 per card, derived from parsed abilities |
| Rule-compliance tests | 82 / 82 passing |
| Engine throughput, random agents | 48 to 64 games/s on the laptop |
| Policy rollout throughput, batch 64 | 4.8 games/s, 3.1 ms per decision |
| Policy network | 0.6M to 12M parameters, transformer over entity tokens |
| First-player win rate, first corpus | 55.9% over 12,744 games |
| Greedy heuristic vs random | about 87% on tournament decks |
| First long run | ~101,000 games, greedy level reached within ~6,000 |
| Legend models | 15, specialists +18.3 points over the generalist |
| Legend models over the bar | 6 of 15 (90% vs greedy, 99.5% vs random) |
| Tournament deck pool | 99 lists, 37 legends, weighted by play rate |
| PPO update, medium preset | 2.9 s on the M3 Pro GPU, 6.7 s on its CPU |
Next
- The first per-legend card reports, for the six legends over the bar, each saying which model it came from.
- Get the other nine legend models over the bar.
- A next round of reward shaping aimed at showdown spells and legend abilities, the two KPIs v2 didn't move.
- Keep adding new cards along with the new effects and abilities.
- Once the models are stronger: the larger preset, the recurrent variant, and the search-based training. For now the training signal matters more than the model size.
- Batched leaf evaluation in the search, which should cut the deep search's cost per decision by about an order of magnitude.
- A belief model that's a posterior over the opponent's actions (why did they pass with runes up?) instead of uniform over legal cards.
- Multi-observer ISMCTS, so statistics stop being pooled at opponent nodes.
- Enforcing
Uniquein the deck builder.