How did they write the code for Zephrys the Great?

I’m fairly new to coding, learning JavaScript this year, and the idea of trying to figure out how to write code for something like this card baffles me. Is it just a ton of ternary statements that deliver different arrays of cards or something? How did they program this thing to examine my situation, know what I want and give it to me when I want it like this? I don’t think I’ve seen a card in Hearthstone this complicated.

Is anyone here a programmer that can summarize what they did to achieve this?

2 Likes

It was something along the lines of

“if played”
“then, win game”

4 Likes

I’m not sure. I think they have a trained neural network. That would be the simplest approach.

2 Likes

They probably categorized each card as things like Boardclear, Removal, Direct Damge, etc. Then they have another set of code that analyzes the board state to figure out which category is best for you and then picks from that category based on your available mana.

4 Likes

They wrote some very in-depth “if … happens” commands. The amazing part is how many situations they must have been through to create the card. I bet this card took longer to develope than most employees deemed “worth it”.

3 Likes

This is incredibly cool stuff.

It’s actually very time consuming more than anything and as you can see from all those “THE CARD SAID PERFECT DAMNIT!”- posts some players actually believed that Blizzard magically invented the holy grail a.i. that just knows what to do :smiley: It’s just natural that they’d forget to implement 1-2 situations or combinations.

2 Likes

They make a list of parameters to judge the gamestate,much like a chess program.
Boardstate (i asmue stats,taunt,possibly deathrattle,shield,reborn,buffs total stats on each side), health totals.
Then he goes by priority,first lethal. Try all cards and all possible targets and see if there is lethal this turn with the current mana left as highest priority. Lethal from hand next turn unless heal has slightly lower priority. After that look at boardstate. Again try all cards and look which one improves board value (stats +deathrattle maybe) the most (thats why tirion i guess and shadowflame when far behind but few high attack minions). I dont know maybe something like this?

4 Likes

Machine learning, they put Zephris to learn from billions of HS matches happening everyday so the card will slowly gain self-awareness.

If Skynet happened sometimes in the future, we know it started here in Blizzard’s lab with Zephrys.

10 Likes

I dunno, if Skynet is based on Zephris, I don’t think it’d ever got to the point where it was losing to John Connor’s resistance in the first place, and there’d be no need for the whole kill-them-before-he’s-born plan.

2 Likes

I imagine it’s just a long series of if-then statements:

if opponent has six or less health:
    offer Fireball
else if opponent has a lot of minions with four or less health:
    offer Flamestrike
else if opponent has one big minion:
    offer Shadow Word: Death
etc.
etc.
1 Like

Hmmmmm and the buff of cards in june was named ‘‘Rise of the machines’’

Blizzard is trying to take over the world !!! Donais is a cyborg !!!

1 Like

That sounds like a smart way to do it. It’s fun to think about.

Ok just to be serius, im not a programmer but seriously with all the things you see around you in digital technologies and programming you really consider Zephrys to be such an achievement??? LOL.

Coding Zephrys must have been one of the easiest things a 2019 programmer can do…

I dunno man, I have a lot more respect and appreciation for how much thought goes into making things I used to think were simple. You might be surprised to learn how much stuff goes in to making a functional program. I am just starting to learn and am blown away by how challenging it is. Making a snarky genie that gives me the cards I wish I had? That merits some clapping imo.

6 Likes

Well, first off you have to realize that, even though we have pretty colors and shiny card graphics, etc., To the computer it’s just math.

So then you have a few conditions to meet.

Number of minions on board.
Health of opponent.
Mana remaining
Total damage of minions on board.
Total health of caster

This is where it starts to simplify, we are choosing from 3 cards so the computer doesn’t need to do much in terms of deciding what is better.

What card clears board?
What card killa opponent?
What card helps caster survive?

Now it may seem a little special since it works at any Mana, but for lethal we are basically looking at fireball, gorehowl, pyroblast, leeroy.

For board clear we are looking at twisting nether, flamestrike, blizzard, etc (based on Mana)

For healing we are looking at Lay on hands, tirion, etc.

So then the math becomes more like, is opponent hp greater than x? If no then is number of minions on the board greater than y? If no then is caster health less than z?

I mean, it seems really fantastical at first but there just aren’t that many cards for it to need to look at

2 Likes

You forgot the current health of enemy minions on the board. Zephrys will offer different board clears and different removal cards based on how many enemy minions there are and how much health they have. He will offer Flamestrike instead of Twisting Nether if the enemy’s board is full of 4-health minions.

1 Like

This is a fairly straightforward problem for machine learning code.

To solve it, you first break down the state of the game into a vector. Then you search the millions of games you have data on for similar vectors (there are standard algorithms for that). From the set of similar games, you narrow down by prioritizing into buckets like “next card won the game”, “next card cleared the board”, “next card restored health”, etc, then a general “what happened next” bucket. Stack rank from “winning the game” => “what happened next” and you ask for the top 3 cards played (ie if “winning the game” isn’t possible you move to the next bucket and ask for its top cards).

I’ve run several data teams so this is how I would go about doing it. Given computational power today these are all pretty simple tasks and since it’s only restricted to basic cards the problem is easier to solve.

I think this would be a fun problem to work on, but it’s not that hard and likely achievable by 1-2 engineers in the course of a few days.

2 Likes

Apparently more coding work went into Zephrys than any other card.

Thousands of lines of code

Well, that’s probably slightly less impressive than it sounds. My guess is that a lot of the code was automatically generated, via machine learning.