Three Things Alike
Duplication removal FTW. Also: Resist fascism, and take care of one another!
There are three _next_action methods used when a frame is complete. For example:
class Box:
def _record_spare_bonus(self, pins):
self._scores.append(pins)
self._mark_3 = self._mark(pins)
self._next_action = self._spare_complete
return False
def _spare_complete(self, pins):
return False
There are these other two:
class Box:
def _open_frame_complete(self, _pins):
return False
def _strike_complete(self, pins):
return False
We only use them in one way:
class Box:
def __init__(self, previous_box = None):
self.previous_box = previous_box if previous_box else ZeroBox()
self._scores = []
self._next_action = self._record_first_roll
self._mark_1 = ' '
self._mark_2 = ' '
self._mark_3 = ' '
self._complete = (self._strike_complete, self._spare_complete, self._open_frame_complete)
def score(self):
na = self._next_action
if na in self._complete:
return sum(self._scores)
else:
return None
We can combine all those into one:
class Box:
def score(self):
if self._next_action == self._frame_complete:
return sum(self._scores)
else:
return None
Rename one of them to _frame_complete, remove the other two, and there you go. Commit: combine three …complete methods into one.
That is all. Resist fascism, write your congress people, support your trans and other not quite like you fellow humans, and take care of one another.