Magic the Gathering is a complex, nerdtastic phenomenon; it's part Lord of the Rings, part chess. In simpler, better times, when I was just a wide-eyed kid with a black deck, the fantasy card game was fairly simple, and mostly casual—not yet the $250 million-a-year industry it is today. In 2015, the game is both big business and a full-blown subculture, home to a huge community of casual players, a competitive pro circuit, and now, its very own artificial intelligence—one that generates thousands of brand new cards by mining the data of the old.
Reed Morgan Milewicz, a programmer and computer science researcher, may be the first person to teach an AI to do Magic, literally. Milewicz wowed a popular online MTG forum—as well as hacker forums like Y Combinator's Hacker News and Reddit—when he posted the results of an experiment to "teach" a weak AI to auto-generate Magic cards. He shared a number of the bizarre "cards" his program had come up with, replete with their properly fantastical names ("Shring the Artist," "Mided Hied Parira's Scepter") and freshly invented abilities ("fuseback"). Players devoured the results.
Milewicz is a Ph.D candidate in the Department of Computer and Information Sciences at the University of Alabama at Birmingham, where he works in the iProgress lab. He'd stumbled upon an article by one of his peers, Andrej Karpathy, who studies machine learning at Stanford. Karpathy was training deep, recurrent neural networks—a kind of statistical machine learning model designed to emulate the neural networks of animal brains—to "read" novels, "learn" their style, and auto-generate texts. Milewicz wanted to try the same with Magic. He set the neural network loose on a data dump that includes every Magic card currently in existence.
To find out more about the project, I braved a stifling wave of nostalgia and a brief sign-in process to the MTG Salvation message board where Milewicz had posted about his creation under the avatar Talcos. It would be the first, and probably last, interview I'd conduct under the moniker "bigbrianthebold."
"I'm a long-time player of Magic," Milewicz told me in one of our exchanges. "I started when I was in first grade and it's been a pastime of mine ever since." So yes, he's a fan. But he's a lot more than that. (For the purposes of understanding this post, I should note here a few of the basic elements of MTG: There are five colors that players can use to form their decks—white, blue, green, red, and black. Players cast "spells" and play "creatures" that belong to different types, like "Merfolk." The aim of the game is to amass an army or cast enough damage-dealing spells to take all of the opponent's life points.)
"I'm interested in reverse engineering rules of complex systems," he said. "Interestingly enough, that's exactly what we're doing with the Magic card generator. The cards are the product of a series of rules; some are the rules of the game itself (e.g. creatures have power and toughness), others are creative rules (like what do white cards do that makes them different from blue cards)?" Those rules, it should be added, are now myriad, and ever-expanding. I recently tried to sit down and revisit the game with my neighbors, and I could scarcely recognize it.
"To be able to generate new Magic cards," Milewicz said, "the recurrent neural net has to reverse engineer all of these rules, and this is something that it can do quite well, even with no prior knowledge about the game, no prior knowledge about English, nothing. All of its knowledge is derived merely from studying the frequencies of sequences of symbols—nothing more. That's a powerful concept, and it's one that I'm exploring in my research."
Here's what he says is one of his favorite new, AI-created cards:
Creature - Dragon
For anyone familiar with Magic—and I've already outed myself here—it will be immediately clear that this is a ridiculous card, in every sense. It's tremendously overpowered, and its abilities aren't quite right (the AI meant to emulate Trample and Mountainwalk, two abilities that creatures in the game actually do commonly have). But other than the misspelling, all the other details are technically sound; it could be a card in the game. It doesn't break any rules.
As Milewicz continued to train the program, it learned more and more about the MTG card universe, and how the game mechanics worked. Its cards started getting more and more "realistic"; that is closer to what you'd expect to see if you opened up a factory-sealed pack of cards. It was learning.
"What we're doing is feeding a neural network text input, one character after another, and training it to predict what characters we will give it next. I say 'C r e a t u r' and it should predict 'e', and if I say 'Draw two' and it should predict 'cards.' This is a deep (multi-layer) LSTM (Long short-term memory) network, which means that it's composed of many small network units that are capable of conditionally storing and forgetting inputs that it receives." Which is how the network is getting "smarter" still. Some of the new cards it creates are barely discernible from real ones, and Milewicz plans on pushing the program further.
"[T]he network can remember what it saw before and its predictions, which means that it can make more robust predictions in the future," he said. "For example, it saw the word 'Merfolk' in the title of the card, and later, when called to predict the color of the card, it can predict blue because Merfolk creatures are usually blue. In doing so, over time, it learns the "rules" that govern Magic cards. Black cards do this, White cards do that. Creature cards do this, Land cards do that."
It works very rapidly, of course, as is befitting of an AI. Right now, according to Gamepedia, there are 13,651 separate Magic cards in the official set. Milewicz could double that count in a couple clicks. "There are, of course, many, many cards which I didn't have room to show everyone (I can generate thousands of cards at a time, and they're all fascinating in their own right)," he wrote me.
So, feeling a weird tension, stretched between a nostalgia for long-gone summer days spent tapping cards on a friend's mana-covered kitchen table and a future where machines auto-generate the content of our most unique games, I asked Milewicz the inevitable question: How long will it be before an AI makes Magic for us?
"It depends on how you look at it," he said. "If by Magic you mean the stats of cards, the arrangements of cards into sets, with all the proper testing and balancing, then that's definitely doable, and in the near future." For its part, Wizards of the Coast—the company that publishes Magic, and is owned by Hasbro—doesn't appear too concerned. "Numerous people has asked me about the AI generating cards [sic]," Magic's head designer Mark Rosewater wrote in a Tumblr post. "I haven't looked at it, but my sources tell me I'm not out of a job just yet." (Interestingly, Milewicz speculates that WotC says it hasn't "looked" at it yet because the famously litigious company doesn't "want to get into any legal trouble by profiting off other people's ideas.")
And given the rate with which WotC churns out the profitable expansion sets, it's hard not to at least consider the possibility machine learning might one day help aid or expedite the process. Creating the game means a lot of labor; a lot of testing, text-writing, and artistry. What if an AI could just cut to the meat?
"But that's not why people play Magic, after all," Milewicz says. "Would they play the game if every card was an otherwise blank piece of paper with numbers scrawled on them? No, games like Magic are popular because they're vehicles for storytelling. The game turns the player into a planeswalker going on adventure, traveling through exotic locales and encountering magical monsters."
It's a common refrain in commentary that examines arenas where AI is abetting the human endeavor; machines can write bare-bones text about earthquakes and sports' scores, sure—but we need human writers to give the practice its soul. For now.
"The question then is whether an AI can give players such unique, compelling experiences," he says. "That's still an open question."