Links to the rest of the series:



I'm just going to admit it-- I'm a huge nerd. As a kid I often preferred to read rather than play with the other kids, I was terrible at sports in P.E. and in seventh grade, I joined both the computer club and the LEGO robotics club. On top of that, one of my biggest hobbies is playing Magic: the Gathering. I've been playing since 2008, and I've played in tournaments on 3 continents.

I really like using Magic: the Gathering for ML tasks, because there's a huge dataset (roughly 25,000 unique cards) readily available. Wizards of the Coast (the company that makes Magic: the Gathering) has a very kind fan content policy, which lets me do projects like this.


I'm not the first person to try and use AI to generate Magic:the Gathering cards. RoboRosewater ran on twitter from 2015-2019, and used RNNs. The project was picked up later, and exists here This version uses smarter RNNs.
So why am I trying this out? Simply, I think a language model with transformer-based architecture will generate better cards.


What is Magic: the Gathering?


Since not all of you play Magic, here's a paragraph from Wikipedia.

"A standard game of Magic involves two or more players who are engaged in a battle acting as powerful wizards, known as Planeswalkers. Each player has their own deck of cards, either one previously constructed or made from a limited pool of cards for the event. A player starts the game with a "life total" of twenty and loses the game when their life total is reduced to zero. A player can also lose if they must draw from their deck when no cards are left. In addition, some cards specify other ways to win or lose the game."

Diagram of MtG Gameplay
An example Magic: the Gathering game

Here are some external resources if you want to learn how to play:


Colors


In Magic, there are 5 colors of magic, White, Blue, Black, Red, and Green.
Each of these colors is produced by a different type of land (the resource in this game), and each color represents a different kind of magical power.

5 MtG basic lands
The 5 basic lands in Magic: the Gathering. Art by Alayna Danner

Each color has specific strengths and weakness, as well as ideological values-- In other words, color will be important to our task of generating Magic cards.


Here are some external resources about color in Magic:


The anatomy of a Magic: the Gathering card


In order to generate Magic: the Gathering cards, there's a necessary baseline understanding of how the game works. Here's a graphic from Wizards of the Coast explaining how Magic cards are laid out.

MtG card anatomy
Image courtesy of Wizards of the Coast

What will we have to do?


In order to generate the cards, we'll need to do something like this:

  1. Use a specific type of statistical language model called an n-gram model to generate creature types.
  2. Generate convincing names and rules text for the creatures using one or more language models.
  3. Use a statistical model to generate the numbers on the card (cost, power, toughness, etc.)
  4. Generate art for the cards.
  5. Put it all together.