Skip to content

Rebuilding a complete card game and optimising its decks

Implementing a card game's rules to the letter, from the original set through to Vendetta : then evolving legal decks with a genetic algorithm evaluated in simulation.

Client
Personal project : R&D
Period
2025 – present
Sector
Simulation / Rules engine

Architecture, rules engine & simulation

841

cards fully covered

1,919

rule clauses implemented

5

expansions supported, up to Vendetta

The starting problem

Finding the best deck in a card game is a combinatorial problem out of reach: with roughly 180 legal cards and decks of exactly 40, the search space approaches 10⁴⁰ combinations per legend. Testing each deck for one millisecond would take longer than the age of the universe. Enumeration is impossible, you have to evolve.

The approach

Two inseparable building blocks. First a faithful rules engine: without accurate simulation, any optimisation is noise. Then a genetic co-evolution where each legend evolves its deck population, evaluated through simulated matches against the best opposing decks, so the meta evolves along with the decks.

What I built

  • A rules engine covering 1,919 clauses, from base cards to Vendetta mechanics (EMPOWER, FLOW, BURN)
  • A legality validator applying official tournament rules (exactly 40 cards, champion and colour constraints)
  • A genetic algorithm: crossover, mutation and systematic repair back to a legal deck
  • A fitness function based on win rate measured through Monte Carlo simulation
  • Multi-legend co-evolution: each population faces the best decks of the others
  • An automated fidelity audit comparing card text against engine behaviour
  • A coverage report continuously measuring how much of the rules is actually simulated
  • A containerised deployment (database, app, real-time relay, reverse proxy) with multiplayer mode

The results

  • 841 playable cards covered at 100%, with no residual partial coverage
  • 1,919 rule clauses implemented and automatically verified
  • A 10⁴⁰ deck space made explorable through evolution rather than enumeration
  • Gaps between official text and implementation caught by automated audit, not by eye
  • A multi-service architecture deployable in one command, with multiplayer games

Tech stack

  • Next.js
  • TypeScript
  • Genetic algorithm
  • Monte Carlo simulation
  • PostgreSQL
  • Docker
  • Caddy
  • WebSocket

A similar project?

Let's talk about your context and see how I can help.

Contact me