Wednesday, September 10, 2014

Calculating Probabilities for Miniatures Games

So some discussion with BookkeeperJason, has inspired me to expand a little on my methods choices of those methods when I do these calculations.  Now Mathhammer has a long history of exploration from people with people being able to list things like expected models lost to various attacks pretty easily.  These calculations are easy due to the nature of the damage processes in 40K where you take one die and roll to hit, then take that die and roll to wound, and then the opponent takes that die and makes a save.  So it is straightforward to determine the chances of each of those progressing then multipling them together to find the probability of the starting attack killing a model.  Since each attack die an independent track you just added up the results for each one to get the number of models you expect to kill.  You can also trivially calculate the chances of N attacks with p kill probability generating a specific numbers of kills using the Binomial Distrubution.

Now some games turn out to be more difficult to calculate.  Space Hulk, X-Wing, and Dwarf Kings Quest all use a contested dice mechanic where both sides roll dice and the results are compared throught some mechanic to determine the result.  You can generate calculate the probability of each side having some die result but how the dice are compared really makes a difference in how to proceed.  In the basic X-wing (without Track Locks, Focus, and Evade and ignoring criticals), you can calculate the probability of of getting so many hits and so many evades and just match them up determine the results.  For example if you have 4 attack dice and 4 defense dice you can only end up with 1 hit when the attack dice yield one more success than the defense dice which means, 4/3,3/2,2/1,1/0.  The final probability will be the sum of those individual events which are the product of each sides chances of getting that specific result.

Now Space Hulk and Dwarf Kings Quest make this more complicated since you are actually comparing the numbers on the dice as opposed to comparing the dice to some other metric and then comparing.  This makes the calculations very challenging.  For example if some one in DKQ has 3 attack dice then the chances of them rolling 6,5,4 are the same as 3,2,1 but the chances of those results generating hits depend on the exact roll of the defender.  You have to compare the two sets of dice to determine the result that it corresponds to and then added the probability of the attackers roll times the probability of the defenders roll to that results probability tally.  When I started my Math Hulk series, I did this in excel and found that as I got to the more and more complicated events it got very hard to keep track of everything once both sides where rolling multiple dice and one side could reroll or force a reroll and such.

For my X-Wing and DWQ studies I tried to do things a little different.  I built a computer program that similated the dice rolls for both side, then automatically ran through the results process and then kept track of how often each possible final result occurred then divide those numbers by the total times the process was simulated.  This coding is sort of overkill for small problems involving 1 or 2 dice where all the possibilities can be hand determined on a spreadsheet but works great as the dice increase since it moves the time consuming comparisons and counting to the computer which is what those are good for.  It is easy to add special rules since you just go in and program the change at the point it happens in the game, and everything still works.

Now there is no reason to feed in just simulated dice.  You can program a computer to generate a list of all the possible dice results and then feed those into the same comparison and counter to get exact results.  With some presorting and counting before the comparison you can get very fast results here for a reasonable number of dice that you might use in this way.  You are not likely to have many times where you are rolling 20 dice then seeing which ones beat armor and then ordering them to compare to someelses 20 dice. This is a great way to check your random generator results but I think might run into more problems with rerolls and such as it add splits into what was before a well ordered comparison of two lists.

So that is how I am doing things if people have any questions.

2 comments:

  1. I have enjoyed the challenge, I think you are currently ahead in the efficiency race, but the gap will close... Now for the important things, getting out a game or two and rolling dice for real.

    ReplyDelete
    Replies
    1. I got in a game of blood bowl last night so that is something for me.

      Delete