Card Similarities in Clash Royal

learned representation in the style of w2v

Evan Pu
5 min readJul 22, 2019

Given 2 objects, A and B, what makes them similar? There can be many answers, but one of the most elegant answer is based on substitution :

A and B are similar, if in most use cases of A, you can substitute it with B, and you wouldn’t notice much of a difference.

The idea of substitution has popped up multiple times, the ones I’m aware of are the liskov-substitution-principle, and of course, distributional-semantics. But instead of research literature, we’re just gonna do it with Clash Royal cards instead. It’s going to be a lot more relaxing and accessible.

Clash Royal

Clash Royal is a tower-offence game mixed with pokemon: From a total possibility of roughly 100 cards, you select 8 cards to form a deck; Then, during a game, you summon the card onto the arena, which march mindlessly toward the enemy’s towers and begin to attack them. Today, the tower offence aspect is not important, but the pokemon aspect is important. Just like in pokemon, you want a deck of 8 cards that form a strong line-up, able to account for diverse circumstances while retaining an overall theme.

It’s honestly a pretty cool game, I call it “Dota on the toilet”, and sometimes I take a very long time on the . . nvm.

Card Substitution as a Guessing Game

What does it mean for card A and card B to be similar in Clash Royal? Well, given a partial deck of 7 cards, if you can compliment it equally well with either card A or card B, they must be similar in nature, fulfilling a similar role: Maybe they’re both tanky, maybe they’re both fast win-conditions, or ranged supports. The point is instead of deciding these roles, we’re simply going to learn them with a ton of dAtA and mAcHiNeLeArNiNg.

To realise the concept of substitution, we’re going to turn it into a little game. First, I am going to pick a competitive clash royal deck; Then, I will reveal to you 7 out of 8 cards; You are then to guess the secrete identity of the 8th card based on the 7 cards already revealed to you. If you played the game long enough (or seen enough decks, in the case of MaChInELeArNiNg), you can form a pretty good guess on what the 8th card is. However, you will still need to guess, and chances are you would have a few candidates that equally made sense as the 8th card. Thus, these few candidates can be interchanged, and under this definition, they are most similar in terms of roles and functions.

For you MaChInE lEaRnInG n3rds, the net work architecture is as follows:

Given 7 cards, pass them through a transformer network and maxpool them together. Then, given a new card, first embed the new card into a latent representation, and have the prediction network predict whether this new card exists as the secrete 8th card. Return the learned embedding vector after training.

Applications of Card Similarity

Now onto the application. The most useful application is fixing the current issue with draft challenges. There is a mode in Clash Royal know as draft challenge, where you are given 4 pairs of cards, in which you must select 4 cards for yourself, and the remaining 4 is given to your opponents. It is a very fun mode that require you to think fast on the spot to form a strong line-up. The main complaint of this mode is that the pairs of cards often exceedingly different the choices become very laughable: Should I choose knight, a ground troop over a lava-hound, a flying win-condition?

With a learned card similarity, we can resolve this issue by aligning similar cards together into sensible pairs. Here is an example I’m pretty proud of:

fixing draft challenging by using learned similarities and re-arranging the pairs

Failed Attempts

There are actually quite a few failed attempts at learning the card similarities. Trying to predict the remaining cards from a single card, trying to build a generative model for valid decks both failed at learning the right embedding representations. The issue can be summarised as the princess-barrel problem: There is a popular deck archetype in Clash Royal known as the “bait deck”, which the card “princess” and the card “(goblin)-barrel” are almost always used in conjunction. As a result, princess and barrel ended up being very similar, except that they are very different cards. A similar problem exist in traditional w2v embedding, which is the “mr david” problem, where the word “david” is most similar to the word “mr” instead of “bob” and other male names due to “mr david” exist as a pair excessively in the corpus. By posing the problem as a 7 to 1 card guessing problem, I circumvented this drawback because now you really cannot substitute a princess of a barrel anymore. As you can see, in the final learned embedding, princess is next to wizard and baby dragon instead of next to goblin barrel.

Despite being kind of failed at generating the right card embedding, the generative model for decks can produce semi-reasonable decks:

[RGhost, E Wiz, Valk, Fireball, The Log, Tornado, Wizard, Hog Rider]

[Tornado, Arrows, Baby Dragon, Executioner, Knight, Hog, Valk, Ice Spirit]

Overall it is fairly good at learning card complimentary such as pairing tornado with executioner and baby dragon, but it is poor at an overall “theme” such as “bait” or “beatdown”. This is to be expected as high level concepts have traditionally been difficult for pattern-learning approaches.

All the code is [here], take a look and leave a star if you want :D. It is research quality code (aka undocumented), you are warned.

Conclusion

In conclusion, w2v and distributional semantics is a powerful concept based on substitution. And it manifests itself very strongly within Clash Royal. I’ve also done a similar project with Dota 2 heroes, and it would be applicable in other line-up based games such as Pokemon, Magic, HearthStone . . .

If you reached this far, High Five !

I’ve been thinking . . . that it maybe a good idea that you should follow my twitter : https://twitter.com/evanthebouncy where I will announce future blog posts like this one. My twitter game is so weak only 21 followers LOL.

--

--

Evan Pu

Research Scientist (Autodesk). PhD (MIT 2019). I work on Program Synthesis in the context of Human-Machine Communications