Coder Social home page Coder Social logo

hearthstone-battlegrounds-simulator's Introduction

Hearthstone Battlegrounds Battle Simulator

A simulator for battles in the HS battlegrounds. This program can quickly run over a battle many times, and give statistics on the results

Example output:

Turn 8
* 4/6 Cave Hydra
* 8/2 Kaboom Bot
* 10/4 Kaboom Bot
* 11/6 Nightmare Amalgam
* 2/2 Lightfang Enforcer
* 4/6 Imp Gang Boss
VS
* 2/2 Kaboom Bot
* 2/2 Kaboom Bot
* 6/3 Cobalt Guardian, divine shield
* 2/6 Security Rover
* 4/2 Micro Machine
* 1/5 Junkbot
* 5/6 Psych-o-Tron, taunt, divine shield
--------------------------------
win: 2%, tie: 3%, lose: 94%
mean score: -6.573, median score: -7
percentiles: -14 -11 -9 -8 -8 -7 -6 -5 -4 -3 12
actual outcome: -9, is at the 20-th percentile

This corresponds to the following board state: Example game
taken from the game at https://www.youtube.com/watch?v=TV0HSwbhasQ,

The score at the end is the number of stars of the remanining minions of the first player, or negative the stars of the second player. So a positive score means the first player wins by that many stars, a negative score means that the first player loses. This score corresponds to damage dealt or taken, excluding damage from the character's level. The program reports mean and median of the scores, and the 0%, 10%, .., 100% percentiles

Usage

hsbg run.txt

The input file consists of a series of commands to define the board state, and looks very similar to the output shown above. See examples/run1.txt.

The program can also be used in interactive mode, by starting it without any arguments. Type help to get a list of commands:

-- Defining the board
board      = begin defining player board
vs         = begin defining opposing board
* <minion> = give the next minion
HP <hero>  = tell that a hero power is used
level <n>  = give the level of a player
health <n> = give the health of a player

-- Modifying the board
give <m> <buff> = buff minion(s) m with one or more buffs

-- Running simulations
actual <i> = tell about actual outcome (used in simulation display)
run (<n>)  = run n simulations, report statistics (default: 1000)
optimize   = optimize the minion order to maximize some objective
objective  = set the optimization objective (default: minimize damage taken)

-- Stepping through a single battle
show       = show the board state
reset      = reset battle
step       = do 1 attack step, or start if battle not started yet
trace      = do steps until the battle ends
back       = step backward. can be used to re-roll RNG

-- Other
info <msg> = show a message
help       = show this help message
quit       = quit the simulator

-- Minion format
Minions are specified as
  [attack/health] [golden] <name>, <buff>, <buff>, ..
for example
 * 10/12 Nightmare Amalgam
 * Golden Murloc Tidecaller, poisonous, divine shield, taunt, windfury, +12 attack

-- Minion buffs
 * +<n> attack = buff attack by this much
 * +<n> health = buff health by this much
 * +<a>/+<h>   = buff attack and health
 * taunt, divine shield, poisonous, windfury = the obvious
 * microbots   = deathrattle: summon 3 1/1 Microbots
 * golden microbots = deathrattle: summon 3 2/2 Microbots
 * plants      = deathrattle: summon 2 1/1 Plants
 * <minion>    = magnetize given minion

-- Refering to a minion
You can refer to a minion with an index (1 to 7), a name, a tribe, or all
For example
  give all +1/+1
  give 2 poisonous  # buffs the second minion
  give Mech divine shield, windfury
  give Cave Hydra +10 health
By default this refers to your side, to modify the enemy:
  give enemy all taunt

A better user interface is a work in progress.

Compiling

To compile the code you need a recent version of gcc, python and make. Run make in the root directory to build the executable.

To make the web version you need emscripten, run make web to build it.

FAQ

Q: How do I put in a board state
A: Use a text file, see the examples directory. The plan is to eventually make a parser for the Hearthstone log files.

Q: What about Bob's tavern?
A: Currently only actual battles are simulated, the program doesn't know about buying, selling, leveling etc.

Q: What can I do with this?
A:

  • You can see how lucky you are
  • You can learn to better position your minions (use the optimize command)
  • (future) you can see how well your board is expected to do at a certain turn of the game

Q: Known bugs
A:

  • There might be subtle differences in the order of triggers etc.

hearthstone-battlegrounds-simulator's People

Contributors

twanvl avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

hearthstone-battlegrounds-simulator's Issues

0 attack minions shouldn't attack

Mechano Egg shouldn't be able to attack.
If only 0 attack minions are left, the battle should be counted as a draw.

board:
* Mechano Egg
vs
* Mechano Egg

Chance-to-die printed 100x too small

Input file:

board
level 1
2/1 amalgam
1/1 amalgam, taunt
vs
health 1
2/2 amalgam

Actual output:

--------------------------------
win: 47.9%, tie: 52.1%, lose: 0.0%
mean score: 0.479, median score: 0
percentiles: 0 0 0 0 0 0 1 1 1 1 1 
mean damage dealt: 0.958
their expected health afterwards: 0.042, 0.479% chance to die
--------------------------------

Expected output (with percentage):

--------------------------------
win: 47.9%, tie: 52.1%, lose: 0.0%
mean score: 0.479, median score: 0
percentiles: 0 0 0 0 0 0 1 1 1 1 1 
mean damage dealt: 0.958
their expected health afterwards: 0.042, 47.9% chance to die
--------------------------------

Alternatively, expected output as a probability:

--------------------------------
win: 47.9%, tie: 52.1%, lose: 0.0%
mean score: 0.479, median score: 0
percentiles: 0 0 0 0 0 0 1 1 1 1 1 
mean damage dealt: 0.958
their expected health afterwards: 0.042, 0.479 chance to die
--------------------------------

"damage dealt" calculation is wrong

This input:

Board
level 1
health 30
* Amalgam
Vs
level 2
health 30
* Amalgam
* Amalgam

Produces:

--------------------------------
win: 0%, tie: 0%, lose: 100%
mean score: -1, median score: -1
percentiles: -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 
mean damage taken: 3
expected health afterwards: 27, 0% chance to die
mean damage dealt: 2
expected enemy health afterwards: 28, 0% chance they die
--------------------------------

I would expect:

--------------------------------
win: 0%, tie: 0%, lose: 100%
mean score: -1, median score: -1
percentiles: -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 
mean damage taken: 3
expected health afterwards: 27, 0% chance to die
mean damage dealt: 0
expected enemy health afterwards: 30, 0% chance they die
--------------------------------

As a reverse, consider:

Board
level 1
health 30
* Amalgam
* Amalgam
Vs
level 2
health 30
* Amalgam

This produces:

--------------------------------
win: 100%, tie: 0%, lose: 0%
mean score: 1, median score: 1
percentiles: 1 1 1 1 1 1 1 1 1 1 1 
mean damage taken: 0
expected health afterwards: 30, 0% chance to die
mean damage dealt: 0
expected enemy health afterwards: 30, 0% chance they die
--------------------------------

I would expect:

--------------------------------
win: 100%, tie: 0%, lose: 0%
mean score: 1, median score: 1
percentiles: 1 1 1 1 1 1 1 1 1 1 1 
mean damage taken: 0
expected health afterwards: 30, 0% chance to die
mean damage dealt: 2
expected enemy health afterwards: 28, 0% chance they die
--------------------------------

I guess that the "damage dealt" calculation is incorrectly using your opponent's final board instead of your own.

great work!

I have same the same idea with U
,before I start to coding ,I search it on github , and find this project ,it'is amazing!
If you can get the current game stat from hearthstone game ,it should be more useful ! Current game stat can get from log file in hearthstone directory

Microbots not always triggering

Input:

board
1/1 amalgam
vs
1/1 amalgam, microbots

Click "Simulate" in web interface.

Actual output:

--------------------------------
win: 0.0%, tie: 50.9%, lose: 49.1%
mean score: -1.473, median score: 0
percentiles: -3 -3 -3 -3 -3 0 0 0 0 0 0 
mean damage taken: 1.473
mean damage dealt: 0.000
--------------------------------

Expected output:

--------------------------------
win: 0.0%, tie: 0.0%, lose: 100.0%
mean score: -3.000, median score: -3
percentiles: -3 -3 -3 -3 -3 -3 -3 -3 -3 -3 -3 
mean damage taken: 3.000
mean damage dealt: 0.000
--------------------------------

make issue

Got this response to running make. Not sure if this is an issue on my end... So happy someone made this tool!

git submodule init
process_begin: CreateProcess(NULL, git submodule init, ...) failed.
make (e=2): The system cannot find the file specified.
Makefile:35: recipe for target 'hsdata/CardDefs.xml' failed
mingw32-make: *** [hsdata/CardDefs.xml] Error 2

Microbots deathrattle not printing with "show"

Input:

board
1/1 amalgam
vs
1/1 amalgam, microbots

show

Click "Simulate" in web interface.

Actual output:

* 1/1 Amalgam
vs
* 1/1 Amalgam

Expected output:

* 1/1 Amalgam
vs
* 1/1 Amalgam, microbots

No Voidlord deathrattle

Looks like Voidlord doesn't currently spawn Voidwalkers on death.

In case it's of interest, this is the battle I was simulating when I found the bug:

Board
* 9/12 Siegebreaker
* 8/13 Voidlord
* 11/14 golden Imp Gang Boss
* 12/17 Voidlord
* 21/16 golden Mal'Ganis
* Soul Juggler
* golden Soul Juggler
Vs
* 60/60 Wrath Weaver
* 55/55 golden Floating Watcher
* 12/14 Imp Gang Boss
* 11/13 Imp Gang Boss
* 17/21 golden Voidwalker
* Crystalweaver
* Soul Juggler

This is from https://youtu.be/6OKQDT_sO4U?t=1195 - I was surprised that the simulator gave a 0.0% winning chance, since Kripp won the actual battle. Trace showed no Voidwalkers spawned, and I confirmed that minion_events.cpp has no code to spawn them.

Th work of a genius

Thank you very much. I learned a lot from it.

I can think of one important improvement: Add the oppertunity to create a "random" deck for your opponent. I did put random between quotes because it should of course not actually be truly random. I could imagine that you could specify a level and it would produce a typical setup for a decent player on that level. So on level 1end 2 the typical opponent would have 1 or 2
playable cards. On level 3 and 4 there would be 3-5 cards (propably some improved). On level 5 they would have 7 good cards that work well together. On level 6 they would typically have a very good setup. For example loads of poisoness murlocs with divine shield.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.