MTG Arena
Learning Bot
A Magic: The Gathering bot that learns from every game it plays
Overview
Can a bot get better at Magic every time it plays?
I reached Mythic, the top rank in MTG Arena, playing Magic: The Gathering myself. Then I wanted to see if a program could learn the game the way I did: play, look back at the mistakes, and play differently next time.
The bot plays the real Arena client on a Mac mini. It reads the game from the client’s log and the screen, then clicks and drags cards like a player. Every game is logged, replayed in a simulator I wrote, and turned into the next version.
- 500k+
- simulated games
- 2,678
- real games on Arena since September
- 102
- versions of the bot, from v2.2 to v2.137
Why Magic
One of the hardest games to teach a computer
Computers mastered chess and Go years ago. Magic is still open, for reasons that make it a good test of whether a program can learn.
01
Hidden information
You can’t see your opponent’s hand or the order of your own deck. Every decision is a bet, like in poker.
02
Tens of thousands of cards
Each card can bend the rules, and new sets change what’s good every few months. Memorizing doesn’t work; the bot has to generalize.
03
It’s Turing complete
In 2019, researchers showed you can build a working computer out of Magic cards. Some games can’t be solved by any program, even in principle.
04
Small edges, lots of luck
A good change might add two wins per hundred games. Seeing that through the luck of the draw takes thousands of games, which is why I built a simulator.
How it plays
Read, see, decide, act
1: Read
Parse Arena’s game log for the full state: cards, life totals and every legal action.
2: See
Read the screen to find where each card in hand and on the battlefield is.
3: Decide
Rules and a learned judge score every attack, block and spell.
4: Act
Click and drag with the mouse, then check the log to confirm it worked.
It can play on its own up to 20 hours a day with random breaks, does the daily quests first, and keeps a log of each game: every decision, the board, the life totals turn by turn, and anything that went wrong.
The simulator
A copy of Magic that plays a game in milliseconds
A real game takes about 20 minutes, which is far too slow to test ideas. So I wrote a Magic rules engine in Python. Every card in the bot’s decks is built from its rules text and checked against logged games.
The simulator runs the bot’s actual code, not a copy. I checked it against 5,125 decisions from real games, and it made the same choice every time.
- 249
- cards built from their rules text
- 5,125
- real decisions matched, with no misses
- 3.7 ms
- per simulated game between simple rule-based players
How it learns
Every game teaches the next version
1: Play
The bot plays and logs every decision and how the game turned out.
2: Replay
Close decisions are replayed in the simulator, each option played out 24 times.
3: Learn
A decision-tree judge trains on which choices actually won.
4: Test
Big changes play thousands of paired games against the old version, and ship only if they win.
The judge learned things I never wrote down, like holding a burn spell for a better moment. On its own it added 4.1 points of win rate against the model of Arena’s AI it trained on, and 2.4 against one it never saw.
Honest grading
I grade the bot against an opponent it didn’t practice on. A bot that only beats its own sparring partner hasn’t learned much.
Decks
Learning what to play, not just how
The same loop tunes the decks. The simulator scores each candidate list against a field of popular decks, and the best ones go head to head on Arena in a sequential test that stops as soon as the answer is clear.
+7
Wins per 100 games
The simulator’s estimate for rebuilding the decks from cards I already owned.
59–31
A new deck on Arena
The record of a white lifegain list the simulator picked when its live test ended and it replaced the old deck.
62,750
Possible combos
A combo finder narrowed 13.3 million card pairs from all 5,163 Standard cards down to the ones that could loop.
Results
What 2,678 games showed
Against Arena’s built-in AI, the bot went 169–15. Against other players it sits near 50%, and that turned out to be the matchmaking: Arena pairs you by a hidden rating, so every deck drifts toward even. Raw win rate can’t measure progress, so I compare versions side by side in the same weeks.
The logs also found its biggest weakness. In 59% of its long losses, it had been ahead by five or more life on turn 10.
- 169–15
- against Arena’s built-in AI
- +7.5
- points from one day of fixes found in game logs
- 6 weeks
- from the first game to version 2.137
Takeaways
01
Build the simulator first
Real games take 20 minutes; simulated ones take milliseconds. Ideas got tested in hours instead of weeks.
02
Grade on what you didn’t train on
Gains against the opponent model the bot practiced on were about 70% bigger than against one it never saw. Only the second number counts.
03
The obvious fix can be wrong
The bot let leads slip, so I tried making it attack harder. Played out from the exact positions where it held back, every version of that did 2 to 7 points worse.