Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- """
- Test out the combinations of the five Grime dice
- http://grime.s3-website-eu-west-1.amazonaws.com/
- http://boingboing.net/2013/03/15/weird-probabilities-of-non-tra.html
- """
- import random
- class Dice:
- def __init__(self,name,sideList):
- self.name = name
- self.sideList = sideList
- def roll(self):
- return random.choice(self.sideList)
- def totalOfSides(self):
- return sum(self.sideList)
- def rollAverage(self,rollIters):
- """ Run through a series of tests to determine average roll value """
- rollTotal = 0;
- for i in range(rollIters):
- rollTotal += self.roll()
- rollAverage = float(rollTotal)/float(rollIters)
- return rollAverage
- def valueAverage(self):
- """ Average the possible values """
- return float(self.totalOfSides()) / len(self.sideList)
- traditional = Dice("traditional",[1,2,3,4,5,6])
- red = Dice("red",[4,4,4,4,4,9])
- yellow = Dice("yellow",[3,3,3,3,8,8])
- blue = Dice("blue",[2,2,2,7,7,7])
- magenta = Dice("magenta",[1,1,6,6,6,6])
- olive = Dice("olive",[0,5,5,5,5,5])
- def rollOff(die1,die2,rollIters):
- """ Roll two dice a number of times and print the results """
- print "ROLLOFF: " + die1.name + " vs. " + die2.name
- die1.wins = 0
- die2.wins = 0
- ties = 0
- for i in range(rollIters):
- die1roll = die1.roll()
- die2roll = die2.roll()
- if die1roll > die2roll:
- die1.wins += 1
- elif die2roll > die1roll:
- die2.wins += 1
- else:
- ## Tie shouldn't be possible with Grime dice
- ties += 1
- print "TIE? " + str(die1.roll) + " " + str(die1.roll)
- if die1.wins > die2.wins:
- winPercentage = die1.wins*100/(die1.wins+die2.wins+ties)
- print die1.name + " wins " + str(winPercentage) + "%"
- print " (" + str(die1.wins) + " to "+ str(die2.wins) + ")"
- else:
- winPercentage = die2.wins*100/(die1.wins+die2.wins+ties)
- print die2.name + " wins " + str(winPercentage) + "%"
- print " (" + str(die2.wins) + " to "+ str(die1.wins) + ")"
- print ""
- #rollOff(red,blue,10000)
- #rollOff(blue,olive,10000)
- #rollOff(olive,red,10000)
- diceList = [red,yellow,blue,magenta,olive]
- for die1 in diceList:
- print "----"
- print
- for die2 in diceList:
- if die1.name != die2.name:
- rollOff(die1,die2,10000)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement