June 2019
Beginner to intermediate
770 pages
19h 24m
English
The following is a subclass of Hand, where total is a simple attribute that's computed eagerly as each card is added:
class Hand_Eager(Hand): def __init__( self, dealer_card: BlackJackCard, *cards: BlackJackCard ) -> None: self.dealer_card = dealer_card self.total = 0 self._delta_soft = 0 self._hard_total = 0 self._cards: List[BlackJackCard] = list() for c in cards: # Mypy cannot discern the type of the setter. # https://github.com/python/mypy/issues/4167 self.card = c # type: ignore @property def card(self) -> List[BlackJackCard]: return self._cards @card.setter def card(self, aCard: BlackJackCard) -> None: self._cards.append(aCard) self._delta_soft = max(aCard.soft - aCard.hard, self._delta_soft) self._hard_total ...
Read now
Unlock full access