Skip to content
Active
Data Science
Web Apps
Oct 2026

MTG Deck Lab

Builds Magic: The Gathering Commander decks as an optimisation problem: a mixed-integer program picks 99 cards for a commander, bracket and budget, then a Monte Carlo simulator goldfishes the result ten thousand times.

Private repo
99
Cards per deck
8, nested
Budget tiers
10,000
Simulated games
656
Test functions
MTG Deck Lab project visual

The constraint

Commander deckbuilding is a constrained search: 99 singleton cards, a colour identity, a power bracket the table agreed on, and a budget. People do it by intuition and spreadsheets, and the result is rarely checked before it is played.

The approach

Model the deck as a mixed-integer linear program with constraints for colour identity, bracket and budget. Combos flagged by the Commander Spellbook estimator are forbidden outright, so a deck cannot drift above its bracket. All eight budget tiers are solved together so each cheaper deck is nested inside the next.

Process
  1. 1
    Constraints, not heuristics

    Wrote the rules of a legal, on-bracket deck as constraints, so the solver cannot return one that breaks them.

  2. 2
    Nest the budgets

    Solved every budget tier together so upgrading a deck is adding cards, not rebuilding it.

  3. 3
    Simulate before trusting

    Goldfished every deck ten thousand times to check it actually curves out the way the model claims.

Outcomes

  • Eight nested budget tiers from one solve
  • Bracket-breaking combos excluded as hard constraints
  • A 10,000-game goldfish simulation for every deck
  • Forty decks each for two commanders
Details

Built a Commander deck optimiser as a mixed-integer program with nested budget tiers and bracket constraints, verified by a 10,000-game Monte Carlo simulation.