

Show HN: Fireplace, a Hearthstone Simulator - scrollaway
https://github.com/jleclanche/fireplace

======
scrollaway
Over the past few months, I've been hard at work on a simulator for the
Hearthstone game by Blizzard.

This turned into a full-blown reimplementation of the game logic pretty fast.

As it turns out, working on this has been the most enlightening and rewarding
experience I've ever had in programming. Hearthstone is a very well designed
game with very few hacks (much unlike other Blizzard games) and extremely
logical rules it has a lot of respect for.

Working on this, more than anything else, has been the most _fun_ I've ever
had working on a project. While it is still incomplete, I'm hoping it is of
interest to someone as I would love to welcome others to the project. I'm
available to answer any questions about it or the Hearthstone's internal
design.

Edit: For those looking for an entry point to what this all looks like, since
this is very much programmer-oriented for now, the docs I wrote on the wiki
([https://github.com/jleclanche/fireplace/wiki](https://github.com/jleclanche/fireplace/wiki))
and the tests
([https://github.com/jleclanche/fireplace/blob/master/tests/te...](https://github.com/jleclanche/fireplace/blob/master/tests/test_main.py))
are the best ones.

~~~
TillE
Is the end goal to implement AIs and try to come up with interesting decks via
something like genetic algorithms? Because that does sound like a fun project.

~~~
scrollaway
There's a lot of end goals! This is something that did cross my mind, yes. I
think Fireplace is more of an enabler for this kind of thing. Writing an AI
that would directly interact with it would be easy and I'm also posting here
so that if anyone has a cool idea for something they want to do with it can
poke me and I'll accomodate!

------
seanalltogether
One immediate idea that comes to mind is the ability to create and share quick
puzzle games for other HS players. You could define parameters like "clear the
board", "find lethal", "minion x must survive", etc... Some players have
already been trying to make them by hobbling together screenshots, but they're
not as effective.

------
147
Could you document the rules of the game somewhere?

Blizzard doesn't make it clear. I was going to embark on a simulator just like
this, except I had a hard time figuring out the weird interactions and edge
cases.

For instance, I just played a game last night where there was an enemy mad
scientist on the board. I play a madder bomber and it kills it, playing a
secret for the mage, which turned out to be mirror entity, proccing that
secret, and the board was left with me and him having a madder bomber.

I wanted to make AI for hearthstone to test and simulate things, but these
weird interactions was preventing me from making a simulator like this.

~~~
rtpg
so one thing is that battlecries trigger before the "summon" effect, and it's
a stack, so you do one effect, resolve those consequences, and then go to the
next effect. In the case of multiple effects being added due to one effect, it
goes by seniority (cards that have been on the board longer trigger first).

There's a decent amount of noted rules on it, but you get some strange things
like Kel'Thuzad ( which was completely borked on release, not sure about it
now). I think the general rule is "the code is the spec"

~~~
scrollaway
Battlecries happening before the summon is a popular opinion but I have strong
reasons to believe it's wrong. However, I wrote above the series of events
that leads to the CARD_PLAYED event to happen after the Mad Scientist is dead,
so Mirror Entity indeed summons the copy after the battlecry has happened.

So basically, battlecries in this case have precendence over secrets so to
say. But the minion is already on the field. This is important because, say
you had a Cult Master that ALSO had a "deal 1 damage" battlecry and you played
it, killing one of your own minions with it: it would see the death, as it is
already on the field.

Regarding Kel Thuzad, we're again talking about ordering issues. What could
have happened is something such as the aura/internal tag it was setting
disappearing a tad too late after its death as during end of turn, if killed
by an END_TURN effect, the aura would trigger before it disappears. But all of
this is extremely internal. If the designers believe it's a bug, then it's a
bug. That's why I'm not touching Warsong Commander yet. :)

------
jc4p
This is awesome dude. I actually found it via your hearthstone-data repo
yesterday since I'm working on a related application (obj-c app to screen-
capture arena and tell me which card I should draft), I'm excited to play
around with this.

~~~
scrollaway
Thanks! Ping me on github if you need anything.

------
dsjoerg
Very cool! Have you looked into the legal issues, for example ToS and
copyright? I wonder if Blizzard would be within their rights to force a
takedown of the code whenever they want.

~~~
scrollaway
I have, to an extent. I've been working with Blizzard games for almost ten
years (I worked on reverse engineering in WoW before), and Blizzard tends to
be very cautious with this sort of projects.

In this case, it would be relatively easy to implement a server on top of
Fireplace which would communicate with a slightly modified Hearthstone client.
This would be a huge no-no for Blizzard and they would try their best to shut
it down, so I'm not doing that.

You'll also note that the game files I am reusing in fireplace are actually in
a separate repo (hearthstone-data submodule) so that I can take it down
separately, should Blizzard request it.

Edit: Part of me also hopes that Team 5, the team behind Hearthstone, is a bit
different. They have been incredibly close to the community, much closer than
Blizzard has with other games, and I'm hoping that if issues arise, we can
work them out peacefully.

~~~
jzelinskie
>In this case, it would be relatively easy to implement a server on top of
Fireplace which would communicate with a slightly modified Hearthstone client.
This would be a huge no-no for Blizzard and they would try their best to shut
it down, so I'm not doing that.

Besides doing something like this, how else would you go about testing this
kind of thing?

~~~
scrollaway
Black box testing, much like the Wine project does. You can see my battery of
tests here:

[https://github.com/jleclanche/fireplace/blob/master/tests/te...](https://github.com/jleclanche/fireplace/blob/master/tests/test_main.py)

Also, the game has excellent debug logs which I could always generate in
Fireplace and compare the two or some such. And if all else fails, I can
always peek at the Hearthstone protocol.

------
aiiane
This is cool. I only wish it didn't require quite so cutting-edge Python
features; a lot of systems are still running a bit behind Python 3.4, even if
they're running Python 3. :)

~~~
scrollaway
Yeah, I understand. This was a project for myself mostly and I needed IntEnums
so I decided to just go with it.

On the other hand, it has zero other dependency than python (with an optional
dependency on pytest for better test output).

