MTG Hivemind: Artificial Intelligence Designing Magic the Gathering Cards

栏目: IT技术 · 发布时间: 3年前

MTG Hivemind: Artificial Intelligence designing Magic!

Aug 13, 2019 ·17min read

Introduction

Artificial Intelligence can create some awesome stuff. At this point, this should be no stunning news to you — and given the fact that you’ve just landed here, I can imagine you already have some background in the area, or at least some interest.

Awesome stuff of the day: Computationally generated Magic The Gathering cards!

MTG Hivemind: Artificial Intelligence Designing Magic the Gathering Cards

Sample of hand-picked cards designed by MTGH

These beautifully not-handcrafted cards above were designed by MTG Hivemind, a collection of neural networks and algorithms that learned from scratch, trained with real cards, how to design new ones!

- The artworks tho are admittedly human-made, yet.

It takes only a few seconds for MTGH to design unique cards, a process that would take much longer if executed by a human. Not only that, but it can come up with genuinely distinct card mechanics, as I’d like to highlight using this card right here:

MTG Hivemind: Artificial Intelligence Designing Magic the Gathering Cards

Taste of Blood

When I first saw this card, I was sure that this was pure Magic.

Over the past twenty-five years, Magic The Gathering has changed a lot, new mechanics have been made, old ones have been tweaked, and across many expansions releases, we have been constantly exposed to new gimmicks in the game.

Flyingwas the first mechanic created by the amazing Richard Garfield , Ph. D. in mathematics and creator of Magic The Gathering, in 1993. A simple keyword that made its way to the present times of Magic, being featured among creatures in every single set since its creation. Thirteen years later, Suspend was added into the game, as a way of diving further in the notion of reward over time in the game, and it was originally designed to be an alternative cost for cards, usually being cheaper but taking longer to deploy the card full potential. Later, cards like Epochrasite and Jhoira of the Ghitu explored some different twists featuring this mechanic.

Despite the gap of time, relevance, and depth in those two mechanics, MTG Hivemind managed to put them together in a card, using a noticeable game design twist. Taste of Blood does not feature Suspend as an alternative cost, as most cards would normally do, it actually takes advantage of the way the mechanic has been written to make a spirit that persists in battle, returning to the game a few turns after being destroyed!

As you might have noticed, the card has a human-design flavor into it. It feels like a Magic The Gathering card. The blue archetype color combines well with a water elemental creature, it has flying, and after getting destroyed it takes a few turns to recompose itself and return to the battle! The color cost, the text size, the base power, and the rarity, all aspects work together to compose a card that feels real.

Beautiful.But how does it work?

Objectives

Before diving further into how it actually works, there are a few statements worth mentioning.

Magic The Gathering cards are not like human face pictures.Of course, they look different, but there’s an aspect much more significant than this one: we do not have a billion cards to work with.

There are around fifteen thousand only.

It might sound a lot, but it is not. Magic The Gathering cards are not strongly consistent. Every time players get to see a new set of cards they expect surprises, and surprises are necessarily a break of the pattern. For humans, that is entertainment, there are more things to wrap our minds around. From a machine learning point view, this is painful. Each set features around two hundred and fifty cards, full of new widely different mechanics, displayed among different colors and types.

There are some vanilla cards in Magic, but we also have double-faced cards, flips cards, Planeswalkers, level up cards and weird cards in general. The MTG dataset, in terms of normalization, is chaos. The sample is small and assorted.

MTG Hivemind: Artificial Intelligence Designing Magic the Gathering Cards

Example of cards that are too unique or wild to make a consistent pattern along the entire dataset.

Because of the nature of the data we’re dealing with, the objective of MTG Hivemind is not to create perfect cards , and that would be a tough task to perform. Instead, the purpose is to design unique and exciting cards. Do not expect balanced and consistent results from it. It was not designed to do so.

How it works

Imagine you need to create a complicated piece, for example, an atomic bomb. You would probably have to hire different professionals, from diverse backgrounds, and make them work together towards the final goal. It would be much harder to find someone who knows how to craft the entire product, from mining minerals to making sub-atomic math. Even if you find someone who is capable, it is reasonable that steps would be executed with the quality of generalist, not a specialist.

In order to achieve better performance at a given task, breaking it into smaller parts and developing specific approaches is a smart choice.

Neural networks work no different. We can’t feed raw card images to a system and expect it to generate complete cards.

For this reason, MTG Hivemind is not a single system, but instead a collection of neural networks with unique aspects each, those have been trained to do quite specific tasks. Some hard-coded algorithms also play a significant role in designing cards features that could not be learned from the sample, we will talk more about that under the Assembler section.

The pipeline for creating a new card from the ground breaks down like this:

MTG Hivemind: Artificial Intelligence Designing Magic the Gathering Cards

Dataset

The first aspect to notice is that all four neural networks (Name Generator, Description Generator, Color Classifier and Type Classifier) are trained with real Magic The Gathering data.

This dataset is initially retrieved from MTGJSON , and then a significant amount of information processing happens. Given the fact that the cards’ description varies a lot, there are several cases where we want to simplify information. Let’s walk through two different examples:

MTG Hivemind: Artificial Intelligence Designing Magic the Gathering Cards

Auramancerand Outnumber are different cards with their own unique text, but there is an interesting fact about those cards: both of them refer to themselves. Meaning that, when Outnumber describes that Outnumber deals damage, it is not talking about any other card in the game, it is actually making a self-reference.

Suppose that there are a hundred of cards with similar descriptions, mentioning their own unique names in the text. We don’t want to treat the occurrence differently, because they are all the same in terms of structure. Each time a new card name is mentioned, it is not a new design element or mechanic, it is just a self-reference. In this case, mapping the card name in its own description to a keyword makes a lot of sense. It brings consistency without a significant amount of information loss .

If the neural network is expected to learn the structure of a Magic The Gathering card description, it is much more effective to feed it with data normalize like this:

[Name] deals damage to target creature equals to the number of creatures you control.

Instead of

Outnumber deals damage to target creature equals to the number of creatures you control.

The model would never know what Outnumber means, but it is possible to expect it to learn how to make self-references very well. Technically, we lose the possibility to generate cards that refer to other specific cards, but that is not common in Magic at all, so the information loss, in this case, is also beneficial.

MTG Hivemind: Artificial Intelligence Designing Magic the Gathering Cards

In other scenarios like boosting a creature power or adding counters, the process is not that simple. You could technically create a neural network that understands well the meaning of those values in the card, but we can’t afford that luxury of consciousness given the limitations we are dealing with.

There are choices when you face scenarios like this, either you:

  • Simplify texts like [+1/+1] and [+2/+1] to be a keyword, like [+n/+n] and give more consistency to the dataset, at the cost of having to fill these gaps with generated information later, and also making it impossible to the neural network to learn interesting patterns around those numbers.
  • Keep the original information in the text, increasing the complexity of the pattern the neural network needs to learn and accepting that the lack of data may cause it to predict weird sentences when dealing with those numbers.

In most cases, the decision made was to simplify information. Results generated this way were much more interesting, even considering that they were vaguer.

MTG Hivemind learned how to create unique cards using keywords, and also how to generate interesting information to fill keyword fields — this is explained under the Assembler section.

MTG Hivemind: Artificial Intelligence Designing Magic the Gathering Cards

Not only dataset was normalized to increase the consistency, but also some of the cards were filtered. As mentioned before, cards such as flip-cards, level-up cards, and Planeswalkers have been removed from the dataset. In these cases, the sample size is not significant and the mechanics are phrased in a way that would add too much entropy to the dataset.

After getting the dataset normalized and ready to be used, generator models and classifiers can be trained and expected to learn their task.

Generators

There are two components of the system that are responsible for generating content: the Name Generator and the Description Generator . These components are Recurrent Neural Network s or RNN for short, a model that have been created to predict sequences, such as a sequence of characters in a phrase or a sequence of values in a stock price.

MTG Hivemind: Artificial Intelligence Designing Magic the Gathering Cards

Representation of a RNN from https://colah.github.io/posts/2015-08-Understanding-LSTMs/

A lot of people have already written about RNNs, how they work and what makes them different from a vanilla neural network, for this reason, I will not dive much further in explanations about the model. I would recommend taking a look at The Unreasonable Effectiveness of Recurrent Neural Networks written with precision by Andrej Karpathy .

After training both RNNs with the processed dataset for only a few minutes, interesting and unique results started to show up!

Progenic Puppeteers
Vampire Charm
Thalia’s Lightning

This is a sample of names that were generated using the RNN trained with real card names. As you can see, Name Generator learned how to create solid Magic The Gathering card names.

{t}: [name] deals 1 damage to target attacking or blocking creature.

This text was created by the Description Generator. It was trained using real text from the dataset, and as shown above, it looks like a consistent card and it also uses [name] as a keyword to make self-reference.

Permanents without converted mana cost 3 or less and cast that spell without paying its mana cost. Equip [mana].

Unfortunately, this second description is not as clean as the last one. It uses native terminology, but it does not make any sense at all. As you might have expected, a significant amount of times, the model generates descriptions that look confusing when trying to create genuine new content.

Using artificial intelligence to generate new content is always a bit tricky, it is hard to find the right audacity level for the model; if you force too much diverse content, descriptions start to look rubbish, and if you worry too much about generating sober results, the new content starts to look unexciting.

Classifiers

So far we’ve seen how names and descriptions are created, but this is not an entire card yet, a card also needs color and type. That’s where classifiers come in. Color Classifier and Type Classifier are responsible for matching a card with a color and a type label, solely based on its description.

These neural networks are expected to learn specific patterns, for example: being able to recognize that a card with trample will probably be a creature, and not an instant or sorcery. Tasks similar to this one can be executed and learned with little effort, and no massive structure is required for that. In fact, those classifiers are a highly conventional model of neural networks.

MTG Hivemind: Artificial Intelligence Designing Magic the Gathering Cards

Representation of a neural network https://medium.com/xanaduai/making-a-neural-network-quantum-34069e284bcf

An awesome explanation about how classification problems can be approached by using neural networks can be seen in But what *is* a Neural Network? made by 3Blue1Brown . Worth watching.

Here is the interesting part: both classifiers are trained with real Magic cards, and tested with cards it has not seen before, to make sure it is classifying new cards correctly. If the model succeeds in matching the correct color and type label to cards it has never seen, that also means we can give it a description made by the Description Generator and expect it to match what would be an accurate color and type.

The image below shows classifications that the Color Classifier have matched to an existent card, and colors it has suggested to a card that do not exist, and was created by the Description Generator.

MTG Hivemind: Artificial Intelligence Designing Magic the Gathering Cards

Numbers assigned by the Color Classifier to show how much it thinks the color label fits the description.

As you can see, it does a great job at assigning a color label to descriptions. The same is true for types. To be more specific, those models reached a significant accuracy when classifying cards they have never seen before, Color Classifier gets the color correctly 87% of the time when labeling a card, and Type Classifier gets the type right 95% of the time.

MTG Hivemind: Artificial Intelligence Designing Magic the Gathering Cards

Color Classifier accuracy displayed over time. The line represents the accuracy when classifying cards it has never seen before, scoring around 87% after the train is complete.

MTG Hivemind: Artificial Intelligence Designing Magic the Gathering Cards

Type Classifier accuracy displayed over time. The line represents the accuracy when classifying cards it has never seen before, scoring around 95% after the train is complete.

At this moment, it is possible to generate unique names and card descriptions, and also match those with coherent colors and type label. The card is almost done, but there are some small gaps left:

  • Mana Cost
  • Power and Toughness
  • Rarity
  • Subtype
  • Artwork

Assembler

The Assembler fills information gaps and generates aspects of that card that were not covered by the neural network components. It is responsible for aspects that could not be approached by using regular neural networks solutions. Either because they were too arbitrary to be learned in terms of recognizable patterns, because they were too simple and solving that with neural networks would be overkill, or because they had paradoxical requirements.

Let’s walk through each case individually:

Mana Cost is not trivial to figure outexclusively based on a generic card description. This task is complicated even for me, and I have around 100 billion neurons. Given this task, making relations between groups of words and a cost is more complex than it seems. To make the point more clear, let’s look at an example:

Flying.
When [name] enters the battlefield, you gain 3 life for each artifact you control.

How much do you think this card would cost to cast?

To start with, we know that the creature has flying. The problem is, that means nothing. Cards with zero mana cost, such as Ornithopter have flying, and Emrakul also does, but it costs fifteen instead.

Then, you gain life for each artifact you control. That also does not tell enough, even if you understand a lot about Magic it still hard to tell the impact of the ability.

The exhibited card is Filigree Angel , which costs a total of eight mana to cast.

MTG Hivemind: Artificial Intelligence Designing Magic the Gathering Cards

Emrakul on the left, Filigree Angel on the middle and Ornithopter on the right.

Looking at the cards above you may have thought

Well, what about other card features, such as power and toughness? Couldn’t they tell more about the card converted mana cost?

This is indeed a great suggestion, the problem is that we cannot be sure if mana cost is based on power and toughness, or if power levels are based on the card mana cost.

The converted mana cost problem turned out to be much harder than I imagined during the development process.

Different approaches using neural networks did poorly, the results, in general, felt pretty random and the accuracy was low. While color and type classification reached spectacular accuracy within a few seconds of training, cost classification could not score better than random.

In scenarios like this one, my approach was to try a more creative solution. For the mana cost, the resolution was to compare the generated card description to each other existent card in Magic The Gathering database and get the cost from the closest one, adding a bit of noise to make sure it felt organic enough. Remembering that the objective is not to generate balanced cards, but rather interesting ones, this method proved to be surprisingly good!

MTG Hivemind: Artificial Intelligence Designing Magic the Gathering Cards

Cards with a believable converted mana cost generated by MTGH.

At this point power and toughness are no longer a problem, it is fairly easy to give a heuristic value that fits naturally to the card, not necessarily balanced, but at least it should look like a real Magic card.

This now leads us to a very similar problem: Subtypes . Similarly to the converted mana cost problem, it is hard to tell a card Subtype based solely on its description.

For this particular problem, a list of colors and words that often come along with each Subtype was created. For example, searching for Goblin would return results like red, haste and creature.

After doing so, generated card features are compared, such as name, description, and color to see the number of aspects that match to each element on the list. It then picks the most or one of the most fitting Subtype.

For example, if a white card with flying is generated, it will probably be classified as an Angel instead of Goblin. This is because it would score much better in similarity with the first subtype.

MTG Hivemind: Artificial Intelligence Designing Magic the Gathering Cards

List of suggested subtypes for the generated card Ruin, before it was assigned to Insect.

The last information gap that Assembler is responsible for filling in is mana fields and rarity.

Rarityis quite simple to figure out, just like in real Magic The Gathering cards they are based on the card’s description length. Mana fields are then filled based on card converted mana cost and color.

MTG Hivemind: Artificial Intelligence Designing Magic the Gathering Cards

Cards designed by MTGH that had their text filled with generated mana costs.

MTG Hivemind complete pipeline is almost done. But there is a significant part left behind: the artwork!

The Art Gatherer

Mechanically speaking, the card artwork does not make much of difference, and it is not even the focus of MTG Hivemind to find a pleasing image and display on the card. Yet, art is an important aspect of the card when we consider how much a card feels real. Exclusively for this reason, MTG Hivemind searches a matching artwork for the created cards.

This process could also be achieved by using neural networks that can create artworks, but this would be extremely complicated. Generating unique card text from the database is already hard, so you can probably imagine that creating images from the original database would not be trivial at all. For several reasons, the idea of using another neural network to create the art for the card is impracticable.

The most cost-efficient way of doing so is searching for pieces made by real artists.

MTG Hivemind: Artificial Intelligence Designing Magic the Gathering Cards

https://www.artstation.com/

The process is rather simple, it basically searches the ArtStation database for posts that contain specific keywords, like the color or the card type. Then, the image is retrieved and the name of the original artist is printed on the card.

MTG Hivemind: Artificial Intelligence Designing Magic the Gathering Cards

Ascened Shaperia, a full card generated by MTG Hivemind

Done. That is how the entire pipeline for creating new card works. Thousands of cards can now be created within a click.

Let’s take a look at some results and discuss improvements , issues , and code .

Results and Code

So far, most of the shown cards were acceptable. This is not true for all of the pieces created by MTG Hivemind, as it surely can create significantly bad stuff. Most of the cards actually have one or more problems, and in some cases, they can be an absolute waste.

The image below shows a sample of bad cards generated.

MTG Hivemind: Artificial Intelligence Designing Magic the Gathering Cards

Sample of garbage cards.

As you can see, these cards are garbage. Most of the text does not make much sense, colors are weird and the overall setting does not fit well.

Cards like this were expected, they actually represent the downside of decisions made while developing MTG Hivemind. They are unbalanced, the text went complete nonsense because of the liberty it was given to create unique descriptions, and the art is not taken into a curatorship process.

MTG Hivemind does create a lot of bad and ordinary pieces, but so do humans, right? Most of the cards you can find on the internet, or even real Magic The Gathering cards are sometimes poorly designed, displaying awkward artworks and weird texts. It is reasonable to think that the algorithm would also create some bad ones. But the important aspect is, if a filter was considered in the process of selecting exceptional cards, it could generate a pool of significantly high average quality. The design process of discarding what did not work and keeping impressive results is natural, and of course, it is also necessary when looking to a sample of cards designed by MTG Hivemind.

There is a gradient of quality in generated cards, and it is worth taking a look at pieces that at first look like unique ones, but end up being ridiculous or simply confusing.

MTG Hivemind: Artificial Intelligence Designing Magic the Gathering Cards

Sample of cards that look interesting, but they are not.

Most of them fit this category, and if you don’t think too much about it, they look like real cards. Visually their aspects seem to fit, but the text does not make much sense, or there is a lack of context or synergy.

And once in every thirty cards, it is possible to find some gems .

MTG Hivemind: Artificial Intelligence Designing Magic the Gathering Cards

A sample of truly interesting and wild cards designed by MTG Hivemind.

MTG Hivemind learned to design amazing cards, and if you want to see more cards generated by it, you can check the MTGH twitter account and take a look at a new card every single day.

Commentaries

A lot of things went wrong during the development of MTG Hivemind, and I surely learned a lot about neural networks. There are two main issues with the card generation system right now; lack of coherence and hard generated information .

It was known that classifying cards converted mana cost and Subtype would be problematic and that using neural networks would not help me that much with this specific challenge. Not being able to solve this with machine learning left me unarmed, and the solution I found was a bit clunky. It works, but there is a lot of improvement to be made in the way a card converted mana cost and Subtype is generated, probably estimating those aspects using a bit more of information, instead of only using description, would be a great choice.

Another significant problem with MTGH is that, because it is too segmented, different parts of the card are created separately, and this might end up weakening the consistency. For example, the title generator does not take into account the characteristics from the card description, so it is possible to create a card that is a human and has the devoid ability — which would never happen when designing a consistent card.

MTG Hivemind: Artificial Intelligence Designing Magic the Gathering Cards

A non-consistent Skeleton card generated by MTG Hivemind on the left, and a real Skeleton card on the right.

Improvements

Having a core aspect to design the card around would be a huge improvement to the system. Right now, the biggest issue is the lack of coherence in the card generator system, but this is not due to the segmentation in the MTGH, but rather due to an unclear point of reference. Information is generated by having another one as the base, but sometimes the base reference is description, sometimes it is the Subtype or even the card name. If every single aspect were created given the card description or another core aspect, maybe the branches derived from the core would be much more consistent.

Data normalization could also be worked a bit more, since some of the fields were normalized, such as name, power, and toughness, while others such as token types and counter types were not, feeling a bit arbitrary.

Code

The entire project and code are available to download on Colab . Feel free to explore, experiment and give feedback about the project.

Thanks for reading!


以上就是本文的全部内容,希望本文的内容对大家的学习或者工作能带来一定的帮助,也希望大家多多支持 码农网

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

三位一体

三位一体

[美]迈克尔·马隆 / 黄亚昌 / 浙江人民出版社 / 2015-4 / 98.90

[内容简介] ●本书讲述了罗伯特•诺伊斯、戈登•摩尔和安德鲁•格鲁夫如何缔造了世界上最重要公司的故事。公司的“外交家”诺伊斯被视为圣父、“思想家”摩尔被视为圣灵、“行动家”格鲁夫被视为圣子,这个三位一体的组合创下了企业管理中的奇迹,开创了一个价值万亿美元的产业,将一家初创企业打造成为千亿美元量级的巨型公司。 ●本书作者迈克尔•马隆在接触空前数量的企业档案的基础上,揭示了英特尔公司无处不......一起来看看 《三位一体》 这本书的介绍吧!

Markdown 在线编辑器
Markdown 在线编辑器

Markdown 在线编辑器

正则表达式在线测试
正则表达式在线测试

正则表达式在线测试

HSV CMYK 转换工具
HSV CMYK 转换工具

HSV CMYK互换工具