Advertisement
stephenjbell

Grime Dice Test

Mar 17th, 2013
177
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.44 KB | None | 0 0
  1. """
  2. Test out the combinations of the five Grime dice
  3. http://grime.s3-website-eu-west-1.amazonaws.com/
  4. http://boingboing.net/2013/03/15/weird-probabilities-of-non-tra.html
  5. """
  6.  
  7. import random
  8.  
  9. class Dice:
  10.     def __init__(self,name,sideList):
  11.         self.name = name
  12.         self.sideList = sideList
  13.    
  14.     def roll(self):
  15.         return random.choice(self.sideList)
  16.    
  17.     def totalOfSides(self):
  18.         return sum(self.sideList)
  19.    
  20.     def rollAverage(self,rollIters):
  21.         """ Run through a series of tests to determine average roll value """
  22.         rollTotal = 0;
  23.         for i in range(rollIters):
  24.             rollTotal += self.roll()
  25.         rollAverage = float(rollTotal)/float(rollIters)
  26.         return rollAverage
  27.    
  28.     def valueAverage(self):
  29.         """ Average the possible values """
  30.         return float(self.totalOfSides()) / len(self.sideList)
  31.    
  32.        
  33. traditional = Dice("traditional",[1,2,3,4,5,6])
  34. red = Dice("red",[4,4,4,4,4,9])
  35. yellow = Dice("yellow",[3,3,3,3,8,8])
  36. blue = Dice("blue",[2,2,2,7,7,7])
  37. magenta = Dice("magenta",[1,1,6,6,6,6])
  38. olive = Dice("olive",[0,5,5,5,5,5])
  39.  
  40.  
  41.  
  42. def rollOff(die1,die2,rollIters):
  43.     """ Roll two dice a number of times and print the results """
  44.     print "ROLLOFF: " + die1.name + " vs. " + die2.name
  45.     die1.wins = 0
  46.     die2.wins = 0
  47.     ties = 0
  48.     for i in range(rollIters):
  49.         die1roll = die1.roll()
  50.         die2roll = die2.roll()
  51.        
  52.         if die1roll > die2roll:
  53.             die1.wins += 1
  54.         elif die2roll > die1roll:
  55.             die2.wins += 1
  56.         else:
  57.             ## Tie shouldn't be possible with Grime dice
  58.             ties += 1
  59.             print "TIE? " + str(die1.roll) + " " + str(die1.roll)
  60.     if die1.wins > die2.wins:
  61.         winPercentage = die1.wins*100/(die1.wins+die2.wins+ties)
  62.         print die1.name + " wins " + str(winPercentage) + "%"
  63.         print "  (" + str(die1.wins) + " to "+ str(die2.wins) + ")"
  64.     else:
  65.         winPercentage = die2.wins*100/(die1.wins+die2.wins+ties)
  66.         print die2.name + " wins " + str(winPercentage) + "%"
  67.         print "  (" + str(die2.wins) + " to "+ str(die1.wins) + ")"
  68.     print ""
  69.  
  70. #rollOff(red,blue,10000)
  71. #rollOff(blue,olive,10000)
  72. #rollOff(olive,red,10000)
  73.  
  74. diceList = [red,yellow,blue,magenta,olive]
  75.  
  76. for die1 in diceList:
  77.     print "----"
  78.     print
  79.    
  80.     for die2 in diceList:
  81.         if die1.name != die2.name:
  82.             rollOff(die1,die2,10000)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement