Skip to content

Commit

Permalink
dice: remove dead code for addition argument to DicePouch
Browse files Browse the repository at this point in the history
The equation evaluator has been taking care of this since 2013, when the
`addition` argument was hard-coded to `0` in a dice-rolling rewrite. See
commit 5a8ecf4 for some of the history.

A decade later, in 2023, we have no use for this argument. The code to
handle it is unreachable, which affects the plugin's coverage score.
Best solution is to just remove the dead code.
  • Loading branch information
dgw committed Oct 26, 2023
1 parent 543b423 commit c35c246
Showing 1 changed file with 8 additions and 18 deletions.
26 changes: 8 additions & 18 deletions sopel/modules/dice.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,15 @@


class DicePouch:
def __init__(self, num_of_die, type_of_die, addition):
def __init__(self, num_of_die, type_of_die):
"""Initialize dice pouch and roll the dice.
Args:
num_of_die: number of dice in the pouch.
type_of_die: how many faces the dice have.
addition: how much is added to the result of the dice.
"""
self.num = num_of_die
self.type = type_of_die
self.addition = addition

self.dice = {}
self.dropped = {}
Expand Down Expand Up @@ -70,7 +68,7 @@ def drop_lowest(self, n):
del self.dice[i]

def get_simple_string(self):
"""Return the values of the dice like (2+2+2[+1+1])+1."""
"""Return the values of the dice like (2+2+2[+1+1])."""
dice = self.dice.items()
faces = ("+".join([str(face)] * times) for face, times in dice)
dice_str = "+".join(faces)
Expand All @@ -81,14 +79,10 @@ def get_simple_string(self):
dfaces = ("+".join([str(face)] * times) for face, times in dropped)
dropped_str = "[+%s]" % ("+".join(dfaces),)

plus_str = ""
if self.addition:
plus_str = "{:+d}".format(self.addition)

return "(%s%s)%s" % (dice_str, dropped_str, plus_str)
return "(%s%s)" % (dice_str, dropped_str)

def get_compressed_string(self):
"""Return the values of the dice like (3x2[+2x1])+1."""
"""Return the values of the dice like (3x2[+2x1])."""
dice = self.dice.items()
faces = ("%dx%d" % (times, face) for face, times in dice)
dice_str = "+".join(faces)
Expand All @@ -99,15 +93,11 @@ def get_compressed_string(self):
dfaces = ("%dx%d" % (times, face) for face, times in dropped)
dropped_str = "[+%s]" % ("+".join(dfaces),)

plus_str = ""
if self.addition:
plus_str = "{:+d}".format(self.addition)

return "(%s%s)%s" % (dice_str, dropped_str, plus_str)
return "(%s%s)" % (dice_str, dropped_str)

def get_sum(self):
"""Get the sum of non-dropped dice and the addition."""
result = self.addition
"""Get the sum of non-dropped dice."""
result = 0
for face, times in self.dice.items():
result += face * times
return result
Expand Down Expand Up @@ -155,7 +145,7 @@ def _roll_dice(bot, dice_expression):
bot.reply('I only have 1000 dice. =(')
return None # Signal there was a problem

dice = DicePouch(dice_num, dice_type, 0)
dice = DicePouch(dice_num, dice_type)

if result.group('drop_lowest'):
drop = int(result.group('drop_lowest'))
Expand Down

0 comments on commit c35c246

Please sign in to comment.