Skip to content

Commit

Permalink
shortened code
Browse files Browse the repository at this point in the history
  • Loading branch information
ShawnDriscoll committed Oct 26, 2017
1 parent d36eb45 commit eec9f65
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 78 deletions.
43 changes: 4 additions & 39 deletions diceroll.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
diceroll_log.info('roll() v' + __version__ + ' started, and running...')

number_of_dice = ['zero', 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine', 'ten']
simple_dice = ['D2', 'D3', 'D4', 'D6', 'D8', 'D9', 'D10', 'D12', 'D20', 'D30']

def _dierolls(dtype, dcount):
'''
Expand Down Expand Up @@ -222,9 +223,9 @@ def roll(dice):
dice_type = dice_type.rstrip()
else:
dice_type = dice[ichar1: len(dice)]

if dice_type == 'D6':
rolled = _dierolls(6, num_dice) + dice_mod
if dice_type in simple_dice:
rolled = _dierolls(int(dice_type[1:len(dice_type)]), num_dice) + dice_mod
diceroll_log.info('%s = %d%s+%d = %d' % (dice, num_dice, dice_type, dice_mod, rolled))
return rolled
elif dice_type == 'D66' and num_dice == 1 and dice_mod == 0:
Expand All @@ -239,42 +240,6 @@ def roll(dice):
rolled = roll_1 + roll_2 + dice_mod
diceroll_log.info('%s = %d%s+%d = %d and %d + %d = %d' % (dice, num_dice, dice_type, dice_mod, roll_1, roll_2, dice_mod, rolled))
return rolled
elif dice_type == 'D10':
rolled = _dierolls(10, num_dice) + dice_mod
diceroll_log.info('%s = %d%s+%d = %d' % (dice, num_dice, dice_type, dice_mod, rolled))
return rolled
elif dice_type == 'D20':
rolled = _dierolls(20, num_dice) + dice_mod
diceroll_log.info('%s = %d%s+%d = %d' % (dice, num_dice, dice_type, dice_mod, rolled))
return rolled
elif dice_type == 'D30':
rolled = _dierolls(30, num_dice) + dice_mod
diceroll_log.info('%s = %d%s+%d = %d' % (dice, num_dice, dice_type, dice_mod, rolled))
return rolled
elif dice_type == 'D12':
rolled = _dierolls(12, num_dice) + dice_mod
diceroll_log.info('%s = %d%s+%d = %d' % (dice, num_dice, dice_type, dice_mod, rolled))
return rolled
elif dice_type == 'D8':
rolled = _dierolls(8, num_dice) + dice_mod
diceroll_log.info('%s = %d%s+%d = %d' % (dice, num_dice, dice_type, dice_mod, rolled))
return rolled
elif dice_type == 'D4':
rolled = _dierolls(4, num_dice) + dice_mod
diceroll_log.info('%s = %d%s+%d = %d' % (dice, num_dice, dice_type, dice_mod, rolled))
return rolled
elif dice_type == 'D9':
rolled = _dierolls(9, num_dice) + dice_mod
diceroll_log.info('%s = %d%s+%d = %d' % (dice, num_dice, dice_type, dice_mod, rolled))
return rolled
elif dice_type == 'D3':
rolled = _dierolls(3, num_dice) + dice_mod
diceroll_log.info('%s = %d%s+%d = %d' % (dice, num_dice, dice_type, dice_mod, rolled))
return rolled
elif dice_type == 'D2':
rolled = _dierolls(2, num_dice) + dice_mod
diceroll_log.info('%s = %d%s+%d = %d' % (dice, num_dice, dice_type, dice_mod, rolled))
return rolled
elif dice_type == 'DD':
rolled = (_dierolls(6, num_dice) + dice_mod) * 10
diceroll_log.info('%s = (%d%s+%d) * 10 = %d' % (dice, num_dice, dice_type, dice_mod, rolled))
Expand Down
Binary file modified diceroll_2.4.0b.zip
Binary file not shown.
43 changes: 4 additions & 39 deletions docs/source/diceroll.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
diceroll_log.info('roll() v' + __version__ + ' started, and running...')

number_of_dice = ['zero', 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine', 'ten']
simple_dice = ['D2', 'D3', 'D4', 'D6', 'D8', 'D9', 'D10', 'D12', 'D20', 'D30']

def _dierolls(dtype, dcount):
'''
Expand Down Expand Up @@ -222,9 +223,9 @@ def roll(dice):
dice_type = dice_type.rstrip()
else:
dice_type = dice[ichar1: len(dice)]

if dice_type == 'D6':
rolled = _dierolls(6, num_dice) + dice_mod
if dice_type in simple_dice:
rolled = _dierolls(int(dice_type[1:len(dice_type)]), num_dice) + dice_mod
diceroll_log.info('%s = %d%s+%d = %d' % (dice, num_dice, dice_type, dice_mod, rolled))
return rolled
elif dice_type == 'D66' and num_dice == 1 and dice_mod == 0:
Expand All @@ -239,42 +240,6 @@ def roll(dice):
rolled = roll_1 + roll_2 + dice_mod
diceroll_log.info('%s = %d%s+%d = %d and %d + %d = %d' % (dice, num_dice, dice_type, dice_mod, roll_1, roll_2, dice_mod, rolled))
return rolled
elif dice_type == 'D10':
rolled = _dierolls(10, num_dice) + dice_mod
diceroll_log.info('%s = %d%s+%d = %d' % (dice, num_dice, dice_type, dice_mod, rolled))
return rolled
elif dice_type == 'D20':
rolled = _dierolls(20, num_dice) + dice_mod
diceroll_log.info('%s = %d%s+%d = %d' % (dice, num_dice, dice_type, dice_mod, rolled))
return rolled
elif dice_type == 'D30':
rolled = _dierolls(30, num_dice) + dice_mod
diceroll_log.info('%s = %d%s+%d = %d' % (dice, num_dice, dice_type, dice_mod, rolled))
return rolled
elif dice_type == 'D12':
rolled = _dierolls(12, num_dice) + dice_mod
diceroll_log.info('%s = %d%s+%d = %d' % (dice, num_dice, dice_type, dice_mod, rolled))
return rolled
elif dice_type == 'D8':
rolled = _dierolls(8, num_dice) + dice_mod
diceroll_log.info('%s = %d%s+%d = %d' % (dice, num_dice, dice_type, dice_mod, rolled))
return rolled
elif dice_type == 'D4':
rolled = _dierolls(4, num_dice) + dice_mod
diceroll_log.info('%s = %d%s+%d = %d' % (dice, num_dice, dice_type, dice_mod, rolled))
return rolled
elif dice_type == 'D9':
rolled = _dierolls(9, num_dice) + dice_mod
diceroll_log.info('%s = %d%s+%d = %d' % (dice, num_dice, dice_type, dice_mod, rolled))
return rolled
elif dice_type == 'D3':
rolled = _dierolls(3, num_dice) + dice_mod
diceroll_log.info('%s = %d%s+%d = %d' % (dice, num_dice, dice_type, dice_mod, rolled))
return rolled
elif dice_type == 'D2':
rolled = _dierolls(2, num_dice) + dice_mod
diceroll_log.info('%s = %d%s+%d = %d' % (dice, num_dice, dice_type, dice_mod, rolled))
return rolled
elif dice_type == 'DD':
rolled = (_dierolls(6, num_dice) + dice_mod) * 10
diceroll_log.info('%s = (%d%s+%d) * 10 = %d' % (dice, num_dice, dice_type, dice_mod, rolled))
Expand Down

0 comments on commit eec9f65

Please sign in to comment.