June 2019
Beginner to intermediate
770 pages
19h 24m
English
The following is an example of a Blackjack Hand description that might be suitable for emulating play strategies:
class Hand: def __init__(self, dealer_card: Card) -> None: self.dealer_card: Card = dealer_card self.cards: List[Card] = [] def hard_total(self) -> int: return sum(c.hard for c in self.cards) def soft_total(self) -> int: return sum(c.soft for c in self.cards) def __repr__(self) -> str: return f"{self.__class__.__name__} {self.dealer_card} {self.cards}"
In this example, we have a self.dealer_card instance variable based on a parameter of the __init__() method. The self.cards instance variable, however, is not based on any parameter. This kind of initialization creates an empty collection. Note that the ...
Read now
Unlock full access