def main(): print('This program rolls a pair of dice repeatedly %d times'\ % NUM_ROLLS) total_rolls = 0 for num in range(1000): die1 = dice.Die() die2 = dice.Die() die1.roll die2.roll sum = int(die1) + int(die2) if sum == 2 or sum == 3 or sum == 12: total_rolls += 1 print('Total number of rolls that equal 2, 3, or 12 within the %d rolls: %d'\ % (NUM_ROLLS, total_rolls))
def __init__(self, entries, generator=None, name=None): self._entries = entries self._sort() self._minimum = self._entries[0].minimum self._maximum = self._entries[-1].maximum if generator is None: self._generator = dice.Die(self._maximum - self._minimum + 1) else: self._generator = generator if name is None: self._name = 'Unnamed Table' else: self._name = name self._result = None self._history = []
def die_6(): return dice.Die(6)
def test_bad_sides(self): with self.assertRaises(ValueError): dice.Die(1)
def test_membership(self): test_die = dice.Die(2) # give this test die the value of what was in hand1 test_die.value = self.hand1.results[0].value self.assertIn(test_die, self.hand1.results)
# dice.D10(), # dice.D10(), # dice.D10()]) # meter = dice.Diedometer(test.dice) # print(' meter: {}'.format(meter.meter)) # print(' incrementing...') # while not meter.finished: # meter.increment() # while meter.result > 35: # meter.drop_die() # # print(' meter: {}: {} (dropped: {}'.format(meter.meter, # # meter.result, # # meter.dropped_dice)) # print(' done...') test = dice.Die(6) print('Testing dice stats for a single die...') print(' Stats for a single d6...') print(' stats dictionary: {}'.format(test.stats.stats_dict)) print(' possible combinations: {}'.format(test.stats.combo_count)) print(' average result: {}'.format(test.stats.average)) print(' stats table:\n{}\n'.format(test.stats.csv())) test = dice.D10() print(' Stats for a single d10...') print(' stats dictionary: {}'.format(test.stats.stats_dict)) print(' possible combinations: {}'.format(test.stats.combo_count)) print(' average result: {}'.format(test.stats.average)) print(' stats table:\n{}\n'.format(test.stats.csv())) test = dice.Percentile()
def test_dice_is_instance_of_Die_class(self): d20 = dice.Die(20) d6 = dice.D6() self.assertIsInstance(d20, dice.Die) self.assertIsInstance(d6, dice.D6)
def test(self, f): d = dice.Die(faces=f) d.roll() self.assertTrue(d.result in f)
def test_die(self): die = dice.Die() self.assertIn(int(die), range(1, 2))
def test_roll_limit(self): die = dice.Die() die.rolls = 3 with self.assertRaises(Exception): die.reroll()
def test_die_value(self): die = dice.Die(8) self.assertEqual(die.value, 8)
def test_reroll(self): die = dice.Die() die.reroll() self.assertEqual(die.rolls, 2)
def test_die(self): die = dice.Die() self.assertIn(die, range(1, 7)) self.assertEqual(die.rolls, 1)
def _seed(self, nums): return [dice.Die(num) for num in nums]
def setUp(self): self.dice = [dice.Die(n) for n in range(1, 7)]
def __init__(self, file_name): self.maze = maze.Maze(file_name) self.die = dice.Die()
def test_membership(self): test_die = dice.Die(2) test_die.value = self.hand1.results[0].value self.assertIn(test_die, self.hand1.results)
def test_roll(self): """Test the roll() function of a die.""" die = dice.Die(6) self.assertTrue(die.roll() in range(1, 6 + 1))
def test_membership(self): # Test to see if a die is within a given hand test_die = dice.Die(2) test_die.value = self.hand1.results[0].value self.assertIn(test_die, self.hand1.results)
def test_die_value(self): die = dice.Die(value=8) self.assertEqual(int(die), 8)
def test_default(self): """Test default aspect of a die.""" die = dice.Die() self.assertTrue(die in range(1, 6 + 1))
def setUp(self): self.d6 = dice.Die(6) self.d8 = dice.Die(8)
from hands import YatzyHand from hands import Hand import dice die = dice.Die(sides=5) print(die.value) D6 = dice.D6() print(D6.value) hand = Hand(size=5, die_class=dice.D6) print(type(hand)) print(hand) yh = YatzyHand()