FoxCon Toledo Software Developers Conference 2015

I will be presenting a talk called “SQL Server Notifications in a manufacturing environment” at the annual FoxCon Toledo Software Developers Conference, Feb 7-8, 2015. Unfortunately, there isn’t a website for FoxCon, but Bob Ruple is the organizer. I will post my slides on this website after the conference has started.

Abstract:

Are we there yet? Are we there yet? Queries that poll a database looking for changes can waste tremendous amounts of network bandwidth, CPU, and other precious database server resources. By changing the structure of your SQL client to use query notifications rather than polling, you can reduce computational load on both the client and the server. We’ll review the mechanism of asynchronous queuing in Microsoft SQL Server, and then we’ll examine a case study of how it can be implemented in an automotive assembly plant. Examples of notifications include routine vehicle brake line leak testing and real-time detection of robot failures.

Rolling dice for King of Tokyo

Edit 1/18/2015: I forgot to provide a link to a spreadsheet I made for saved games (King of Tokyo Saved Game –  Excel Template, King of Tokyo Saved Game – PDF format).

Over the winter break, I had some time to play a really great board game, King of Tokyo, with my friends and family.  (Creator’s website, BGG link, Amazon link). King of Tokyo shares a dice mechanic similar to Yahtzee:

At your turn, you get three successive throws after each of which you choose whether to keep or discard each of the six special dice. Your final combination will enable you to win destruction points, hoard energy, restore your health or whack other players into understanding Tokyo is your territory.

There are some questions that came up about the optimal strategies and expected outcomes of the 3-roll, six-dice mechanic. Since Yahtzee is so well known, I borrowed a Monte Carlo analysis from it to analyze King of Tokyo. For example, the chance of rolling a Yahtzee (all five dice the same in a 3-roll turn) is about 0.046 according to Wikipedia.

Anyway, this inspired me to write some Python code to evaluate King of Tokyo.  Note that King of Tokyo uses 6 dice instead of the 5 in Yahtzee, and I arbitrarily assigned damage to be “six” on the dice, energy is “five”, and hearts are “four”. Here are the questions that came up during our King of Tokyo games.

Q1: I’m in Tokyo with 4 HP. What are the chances that my next opponent kills my monster if by only keeping damage dice and rerolling everything else?

This is an excellent question because it determines whether you should leave Tokyo or not. First, here are the possible outcomes:

Damage dealt(d)     P(X>=d)
0                   1.000
1                   0.962
2                   0.798
3                   0.501
4                   0.212
5                   0.052
6                   0.005
Table 1. Outcomes for six dice rolled three times with best results kept.

The attacking monster has a 21.2% chance of dealing at least 4 damage (d is damage dealt, X is a random variable which models the rerolling process), assuming 6 dice are rolled up to 3 times, and only damage dice are kept.

I generated this table using the following Python code:

import numpy as np

def rollSixes(NRerolls=3) :
for i in xrange(0,NRerolls):
    if 6 == randint(1,6) :
        return 1
    return 0

def rollHand(NDice=6,Cutoff=1,NRerolls=3) :
    hand = [ rollSixes(NRerolls) for i in xrange(0,NDice) ]
    return hand.count(1) >= Cutoff

N=100000
NDice=6
NRerolls=3
Cutoff=4

tests2 = [ rollHand(NDice,Cutoff,NRerolls) for i in xrange(0,N) ]

print np.mean(tests2), np.std(tests2)

Table 1 is also has the answers to the following questions:

On average, how much damage is dealt to the monster in Tokyo each turn? (Answer: 3 from the table, but 2.53 is the exact number because E[X]=0.421)

Suppose I to heal at least 2 hearts in the next turn, or else my monster will be eliminated. What are the chances that I can roll at least 2 hearts? (Answer: 79.8%)

Q2. How valuable is the “Extra Head” card?

The “Extra Head” card allows a monster to roll one extra die (so, 7 dice instead of 6). It’s a really expensive and desirable card. Re-running the simulation with NDice=7 gives:

Damage dealt(d)     P(X>=d)
0                   1.000
1                   0.978
2                   0.865
3                   0.627
4                   0.332
5                   0.117
6                   0.025
7                   0.002
Table 2. Seven dice, 3 rerolls, keeping only the best outcomes.

The extra die may feel really useful, but it makes only a relatively small difference in the statistical outcomes. Instead of a 21.2% chance of dealing at least 4 damage, there is a 33.2% chance of dealing at least 4 damage. Not a huge increase, in my opinion.

The expected value of one die is still 0.421 damage (or energy or hearts), but the expected damage from one turn in Tokyo increases from 2.53 to 2.94. That might be enough to persuade some players to yield Tokyo.

Q3. How valuable is the “Giant Brain” card?

“Giant Brain” allows one more reroll each turn (so 4 rerolls instead of 3). Rerunning the simulation with six dice and 4 rerolls:

Damage dealt(d)     P(X>=d)
0                   1.000
1                   0.987
2                   0.907
3                   0.688
4                   0.376
5                   0.129
6                   0.020
Table 3. Six dice, up to 4 rerolls, keeping only the best outcomes.

I feel like “Giant Brain” is a more powerful card than “Extra Head”. The expected value of one die increases from 0.421 damage to 0.518 damage, and the variance of the outcomes also narrows. The improvement in damage (or energy or hearts) is almost the same with each of these cards, but “Giant Brain” is cheaper and not as hotly contested among players.

 Conclusion

King of Tokyo is a fun game. If you like dice games with more skill than Yahtzee (almost pure chance), but you want them to end more quickly than Monopoly (which can go on for many hours with no progress even for perfectly skilled players), King of Tokyo is an excellent choice because the dice mechanic virtually guarantees that the game will be done in under 20 rounds. It’s got most of the fun of a computer dice game like XCOM: Enemy Unknown without needing as much bookkeeping. Congratulations are due to the creators for making a balanced and fun game.