class Dealer(Player): def __init__( self ): # Constructor to initalize the dealer info and ensure that Player class' (the base class) constructor is invoked as necessary super().__init__("Dealer", self) # Invokes the Player class' constructor self.deck = CardDeck() # Creates a new CardDeck object self.natural_blackjack_dflag = 0 def shuffle_deck( self): # The dealer uses the Cardeck Object to shuffle the deck self.deck.shuffle() # Shuffles the deck def signal_hit( self, player ): # Used to request a card after which, the dealer picks up a card from the top of the pile and gives it to the person who requested the card player.deal_to(self.deck.draw() ) # The dealer draws the topmost card from the deck def play_round(self): # Simulates the dealer playing a round of blackjack if self.card_sum < 17: # The dealer hits as long his card sum is less than 17 self.deal_to(self.deck.draw( )) # The dealer hits (draws a car from the top of the deck) self.play_round( ) # Recursively calls play round till the dealer's card sum is more than 16 after which, the dealer stands
class Dealer(Player): def __init__(self): super().__init__("Dealer", None) self.deck = CardDeck() def shuffle_deck(self): """ >>> import random; random.seed(1) >>> dealer = Dealer() >>> dealer.shuffle_deck() >>> str(dealer.deck)[0:20] '10 8 10 6 8 9 3 10 2' """ self.deck.shuffle() def signal_hit(self, player): """ A method called by players when they want to hit Player objects should pass their `self` references to this method Should deal one card to the player that signalled a hit These doctests will not run properly if the `deal_to` method in the `Player` class is not properly implemented >>> import random; random.seed(1) >>> dealer = Dealer() >>> dealer.shuffle_deck() >>> player = Player(None, None) >>> dealer.signal_hit(player) >>> player.hand [10] """ card = self.deck.draw() if card: player.deal_to(card) def play_round(self): """ A dealer should hit if his hand totals to 16 or less >>> import random; random.seed(1) >>> dealer = Dealer() >>> dealer.shuffle_deck() >>> dealer.play_round() >>> dealer.hand [10, 8] """ while not self.busted and self.card_sum <= 16: self.signal_hit(self)
class Dealer(Player): def __init__(self): self.deck = CardDeck() super().__init__('Dealer', self) return def shuffle_deck(self): self.deck.shuffle() return def signal_hit(self, player): player.deal_to(self.deck.draw()) return def play_round(self): while self.card_sum < 17: self.deal_to(self.deck.draw()) return
class Dealer(Player): def __init__(self): super().__init__('Dealer', self) self.deck = CardDeck() self.busted = False self.black_jack = False self.is_processing_done = False self.is_standing = False def shuffle_deck(self): """ >>> import random; random.seed(1) >>> dealer = Dealer() >>> dealer.shuffle_deck() >>> str(dealer.deck)[0:20] '10 8 10 6 8 9 3 10 2' """ self.deck.shuffle() def signal_hit(self, player): """ A method called by players when they want to hit Player objects should pass their `self` references to this method Should deal one card to the player that signalled a hit These doctests will not run properly if the `deal_to` method in the `Player` class is not properly implemented >>> import random; random.seed(1) >>> dealer = Dealer() >>> dealer.shuffle_deck() >>> player = Player(None, None) >>> dealer.signal_hit(player) >>> player.hand [10] """ if player != None: player.deal_to(self.deck.draw()) else: self.deal_to(self.deck.draw()) def play_round(self): """ A dealer should hit if his hand totals to 16 or less >>> import random; random.seed(1) >>> dealer = Dealer() >>> dealer.shuffle_deck() >>> dealer.play_round() >>> dealer.play_round() >>> dealer.hand [10, 8] """ if len(self.hand) < 2: if len(self.hand) == 0: self.signal_hit(None) return if len(self.hand) == 1: self.signal_hit(None) if self.card_sum > 16 and self.card_sum < 21: self.is_standing = True return if self.card_sum == 21: self.busted = True self.black_jack = True return if self.card_sum > 21: self.busted = True return if self.card_sum <= 16: while self.card_sum <= 16: self.signal_hit(None) if self.card_sum > 16 and self.card_sum < 21: self.is_standing = True break if self.card_sum == 21: self.busted = True self.black_jack = True break if self.card_sum > 21: self.busted = True break def get_name(self): return self.__class__.__name__ def __str__(self): """Return string representation for str().""" return f'Dealer: {self.hand} 0/0/0'
class Kabal: deck: CardDeck placed_cards: list def __init__(self): self.deck = CardDeck() self.deck.shuffle() self.placed_cards = [] for _ in range(0, 9): card = self.deck.take() self.placed_cards.append(card) def write_status(self): return f"{self}\nCards left: {len(self.deck)}" def __str__(self): text = "Cards placed: \n" text += "Index\tCardType\tCardValue\n\n" index: int = 0 for card in self.placed_cards: text += f"{str(index)}\t{str(card)}\n" index += 1 return text def is_game_over(self): return len(self.deck) <= 0 def place_two_cards(self, placement_index_one, placement_index_two): if not self.__check_cards_placement(placement_index_one, placement_index_two): return self.placed_cards[placement_index_one] = self.deck.take() self.placed_cards[placement_index_two] = self.deck.take() def place_three_cards(self, placement_index_one, placement_index_two, placement_index_three): if not self.__check_cards_placement(placement_index_one, placement_index_two, placement_index_three): return self.placed_cards[placement_index_one] = self.deck.take() self.placed_cards[placement_index_two] = self.deck.take() self.placed_cards[placement_index_three] = self.deck.take() @staticmethod def __check_two_cards(value_one, value_two): if value_one + value_two == 11: return True print("Cards don't equal 11, invalid configuration") return False @staticmethod def __check_three_cards(value_one, value_two, value_three): if value_one >= 11 and value_two >= 11 and value_three >= 11: return True print("Not all cards are image cards, invalid configuration") return False def __check_cards_placement(self, index_one, index_two, index_three=-1): if index_three != -1: return self.__check_three_cards( self.placed_cards[index_one].value, self.placed_cards[index_two].value, self.placed_cards[index_three].value) return self.__check_two_cards(self.placed_cards[index_one].value, self.placed_cards[index_two].value)