

Show HN: HearthSim, an AI and game simulator for Hearthstone Heroes of Warcraft - oyachai
https://github.com/oyachai/HearthSim

======
gavanwoolery
In order to balance the game I am working on, I am planning to use a somewhat
similar automated system (although its good to note, you can get a very
interesting statistical analysis by ignoring the AI and just playing random
cards/skills/whatever you are testing against each other). This of course
works best if you are selecting two discrete subsets of one superset and
playing with card variance (random decks, control decks with only one
different card between them, etc).

Off topic: I've played Heathstone enough to appreciate it. It is a good game
(I'd give it maybe 4.5 stars), but not perfect; my critiques:

\- Chance of winning is based largely on luck - the same deck drawn two
different ways can be almost a guaranteed win/fail, even if it is balanced.

\- Card starvation is way too common of a problem. Could not count how many
times I ended up exhausting the deck, even with plenty of cards to counter it.
When you only have one card to play at a time, the game becomes rather dull.

\- Classing leads to a certain lack of permutation and surprise - most decks
have a few basic strategies.

\- Cards outside of the class decks tend to be fairly generic feeling for the
most part. Many cards feel a bit mundane compared to other CCGs.

\- Free to play model hurts the game a bit - I don't mind paying money, but
many aspects of the game feel too grindy (in order to get you to pay money).

~~~
chacham15
The #1 reason I stopped playing the game is because I would do fairly well at
the game, get matched with stronger opponents, and subsequently lose because I
dont even have the full set of Mage cards while my opponent is pulling
legendaries. That kind of a game just isnt fun for me and it happens over and
over.

~~~
KVFinn
You get matched against people who are winning about as much as you are. The
system looks at nothing else. This is the best and really only way to do
matchmaking.

If you were kept separate from the rest of the decks how would that work?

(FWIW, my best deck doesn't is the one that doesn't have any legendaries in it
anyway, and it got as high as rank 2, 4 stars.)

If you were isolated from decks with legendaries and had a seperate ladder, h

~~~
nacs
> If you were isolated from decks with legendaries and had a seperate ladder,
> h

Offtopic but that reminded me of those decade-old Slashdot posts with the
sudden cutoff mid-sentence followed by 'Connection dropped' modem messages.

------
minimaxir
Note that the game only implements about 50 cards of the 382 cards available
in the game:
[https://github.com/oyachai/HearthSim/tree/master/test/com/he...](https://github.com/oyachai/HearthSim/tree/master/test/com/hearthsim/test/card)

BTW, if you haven't tried it yet, Hearthstone is a great CCG with a very fair
progression system and very good polish/balance.

~~~
oyachai
Yep, I'm up to about 100 cards at this time, working on the basic cards first.
Besides the cards, there needs to be more work on the AI modeling...
currently, it won't handle any card with elements of randomness to it. I think
I have an idea on how to treat it (without the AI cheating), so that
implementation is coming up... soon.

~~~
TheMakeA
Are you implementing each card by hand? I was going to make something like
this and was just going to regex match all of the cards (from HearthPwn). It
seemed like there were few enough variations to make something like that
possible.

Curious if you already tried automating it.

~~~
oyachai
A lot of the cards are more or less automatically generated in the sense that
they don't actually extend any functionality of the parent class. Variations
in the special effects ("text" effects) are big enough that for those, I find
implementing them one by one much easier.

------
_halgari
I'm a bit against the code style:
[https://github.com/oyachai/HearthSim/blob/master/src/com/hea...](https://github.com/oyachai/HearthSim/blob/master/src/com/hearthsim/card/spellcard/concrete/ArcaneExplosion.java)

So the card that does the damage has to do the removal check for the minions?
Talk about duplication of code. Wouldn't something like this be better:

engine.dealDamage(1).to(Category.EnemyMinions);

~~~
_halgari
Or better yet, write the entire thing in a logic programming DSL.

~~~
Kiro
DSL as in write your own language? That sounds complex.

------
anonymoushn
Does this implement the many completely undocumented corners of the game
correctly?

Some examples:
[http://www.reddit.com/r/hearthstone/comments/24tvce/unwritte...](http://www.reddit.com/r/hearthstone/comments/24tvce/unwritten_effects/)

Some examples from personal experience: Ongoing effects last until a player
could act, not until the minion causing them leaves the battlefield. So if you
trade your 2/3 harvest golem for your opponent's 6/2 stormwind commander, they
both die, you get a 2/1 damaged golem, and your knife juggler throws a knife
at your opponent's wisp, the wisp will take 1 damage, go down to 2/1, then
lose the buff from stormwind commander (who died a long time ago!) and go down
to 1/1.

If you have a young priestess and a 1/1 imp master, your imp master can kill
itself and your young priestess can target your dead imp master with her buff.
This will not bring the imp master back to life, you just miss out on your
buff for the turn.

~~~
esturk
I was confused for a moment on what you meant, but I believe you were
referring to the 'Stormwind Champion'.

In the future Naxx release, they will implement a queue to keep track of the
timestamp that each creature enters the board. All effect that
triggers/depletes from a 'mass death' will take place in the order of each
card's timestamp, earliest first.

So for the 2nd example, it depends on which creature came into play first. If
Young Priestess, then Imp Master doesn't lose health and you get a 1/1 imp. If
Imp Master first, then Imp is spawned and gets buffed but the master dies.

~~~
anonymoushn
Whoops!

I am not sure if this will fix young priestess thing - the issue is that the
young priestess chooses its target before the imp master uses its ability, but
uses its ability after the imp master does.

------
ntaso
_HearthSim is a generic Hearthstone game simulator and AI, designed to run
large numbers of simulated AI vs AI games in order to test and understand the
values of various game mechanics and cards._

Then I read an article about The Coin on OP's blog:
[http://buddypanda.com/?p=65](http://buddypanda.com/?p=65) and I don't think
that the simulator is that useful. Maybe I'm too dumb to understand this, but
my intuitive idea is that a card like The Coin gives you various advantages
and no disadvantages, since it is an extra card that comes for free and gives
you more flexibility. How come then, that the simulator says that the player
actually wins more games without The Coin?

Hearthstone isn't mainly about random encounters between AI opponents, but to
gain advantage in material over your opponent over the course of the game.
Sometimes, 1hp, 1 card, 1 round is sufficient to decide over victory or
defeat. If the simulator neglects hero abilities (as in The Coin article), my
guess would be that it's not too accurate.

However, I thought that a simulator for Hearthstone would be a great idea. I
think you're onto something here, but I'd like to see a few more use cases
that match my intuition I gained from playing hundreds of games of
Hearthstone.

~~~
epriest
> How come then, that the simulator says that the player actually wins more
> games without The Coin?

This isn't what the results say. The win rate for the player who goes first
("Player 0") rose from 41% to 61% when the player who goes second ("Player 1")
was not given The Coin.

This is summarized in the text:

> The Coin basically makes what used to be a first player advantage into a
> first player disadvantage. Not bad for a single card!

~~~
ciaranm
As far as I'm aware, official stats from Blizzard is that the player going
first is wins a higher % of the time than going second, despite the coin. I'll
try and find the source.

User dtech already found the source for me (: ->
[https://news.ycombinator.com/item?id=8020232](https://news.ycombinator.com/item?id=8020232)

~~~
goldenkey
Not with all decks though apparently. Freeze mage can benefit from the coin
immensely

~~~
ciaranm
I appreciate your point about coin being stronger in some decks than others -
that doesn't change the fact that across _all_ of the games of hearthstone
being played, if you go first you're more likely to win than if you go second.

------
j2kun
Just curious: have you watched any of these games to see what kinds of
mistakes the AI makes for various settings of the parameters in your scoring
functions?

Also, I'd be interested in doing offline learning. For example, if you have
some formal way to record the actions taken in a game, you could ask pro
players to submit their games. Of course, this would require Blizzard to allow
a replay mechanism like it does for starcraft. But it would make the AI design
process much more interesting than exploring game trees (without perfect
information) or greedily picking the best single move.

~~~
oyachai
I have informally looked at what the AI does. Turns out, as far as I can see,
the AI does a pretty good job... with a BIG CAVEAT. The decks that I have used
so far consist solely of minions and one other special card, so there really
isn't any "mistakes" the AI can make. The decks are just so simplistic at this
point. As more interesting cards are implemented, I'm sure there will be
situations where the AI will make interesting mistakes that we can learn from.
It is something I'm really looking forward to exploring.

------
ionforce
You have no idea how excited this project makes me. I have a total nerd boner
for AI and Hearthstone, so... I'm hyperventilating right now.

Hopefully I can grok your work and maybe I can contribute!

~~~
oyachai
I'm a sucker for AI and Hearthstone too :) I'd love any contribution and
collaboration!

------
paulgerhardt
Can someone clarify if this is the same HearthStone AI/Machine Learning
project being presented at DEF CON this year by Elie and Celine Bursztein[1]?

[1]
[https://www.defcon.org/html/defcon-22/dc-22-speakers.html#Bu...](https://www.defcon.org/html/defcon-22/dc-22-speakers.html#Bursztein)

~~~
faizshah
There's another pretty good one that I found a few days ago on github, I don't
think it's the same as the one you're talking about, but it seems to be more
complete than the OP's.

[https://github.com/danielyule/hearthstone-
simulator](https://github.com/danielyule/hearthstone-simulator)

------
dsjoerg
Very cool!

Isn't there some kind of copyright or terms-of-service violation involved in
publishing this?

~~~
mischanix
Seeing as it doesn't reproduce the functionality of the Hearthstone client or
server in its entirety, I think it falls in the same category as fansites such
as Hearthpwn. Blizzard could probably pursue a successful takedown, but I
can't see a good reason to put resources there when there are things like WoW
private servers that pose a legitimate business threat.

------
dnesteruk
Interesting, I've written very much the same thing with the same name. Only
difference is I've written it using C++.

------
z131
Dear god thank you for not writing this in javascript.

~~~
oyachai
Simulation speed is of primary concern here (though javascript isn't too
shabby)! I actually have a C++ version too, but I thought Java might be more
accessible to more people...

~~~
slapresta
How can simulation speed be a concern in a turn-based card game?

~~~
oyachai
HearthSim is designed purely as a AI vs AI game simulation tool. It's not a
"playable" Hearthstone clone. In the examples on my blog, I usually run 40,000
simulated games per data point, and each set of 40,000 games usually takes a
few hours to run on a relatively modern PC.

