コード例 #1
0
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))
コード例 #2
0
 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 = []
コード例 #3
0
def die_6():
    return dice.Die(6)
コード例 #4
0
 def test_bad_sides(self):
     with self.assertRaises(ValueError):
         dice.Die(1)
コード例 #5
0
 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)
コード例 #6
0
ファイル: tester.py プロジェクト: hessier00/second_rise
#                           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()
コード例 #7
0
ファイル: tests.py プロジェクト: mic-meier/passphrase
 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)
コード例 #8
0
ファイル: test_dice.py プロジェクト: natfarleydev/pydice
 def test(self, f):
     d = dice.Die(faces=f)
     d.roll()
     self.assertTrue(d.result in f)
コード例 #9
0
 def test_die(self):
     die = dice.Die()
     self.assertIn(int(die), range(1, 2))
コード例 #10
0
    def test_roll_limit(self):
        die = dice.Die()
        die.rolls = 3

        with self.assertRaises(Exception):
            die.reroll()
コード例 #11
0
 def test_die_value(self):
     die = dice.Die(8)
     self.assertEqual(die.value, 8)
コード例 #12
0
 def test_reroll(self):
     die = dice.Die()
     die.reroll()
     self.assertEqual(die.rolls, 2)
コード例 #13
0
 def test_die(self):
     die = dice.Die()
     self.assertIn(die, range(1, 7))
     self.assertEqual(die.rolls, 1)
コード例 #14
0
 def _seed(self, nums):
     return [dice.Die(num) for num in nums]
コード例 #15
0
 def setUp(self):
     self.dice = [dice.Die(n) for n in range(1, 7)]
コード例 #16
0
 def __init__(self, file_name):
     self.maze = maze.Maze(file_name)
     self.die = dice.Die()
コード例 #17
0
 def test_membership(self):
     test_die = dice.Die(2)
     test_die.value = self.hand1.results[0].value
     self.assertIn(test_die, self.hand1.results)
コード例 #18
0
ファイル: test_dice.py プロジェクト: BradleySmall/dicegame
 def test_roll(self):
     """Test the roll() function of a die."""
     die = dice.Die(6)
     self.assertTrue(die.roll() in range(1, 6 + 1))
コード例 #19
0
ファイル: tests.py プロジェクト: acuyjet/treehouse-tutorials
 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)
コード例 #20
0
 def test_die_value(self):
     die = dice.Die(value=8)
     self.assertEqual(int(die), 8)
コード例 #21
0
ファイル: test_dice.py プロジェクト: BradleySmall/dicegame
 def test_default(self):
     """Test default aspect of a die."""
     die = dice.Die()
     self.assertTrue(die in range(1, 6 + 1))
コード例 #22
0
 def setUp(self):
     self.d6 = dice.Die(6)
     self.d8 = dice.Die(8)
コード例 #23
0
ファイル: test.py プロジェクト: matthewgiem/subclass.py
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()