def do_hand(self, hand, bet, can_blackjack=True): if can_blackjack: if is_21(self.dealer_hand) and is_21(hand): self.count_card(self.dealer_hand[0]) if self.debug: print("DUAL BLACKJACK!") return elif is_21(hand): self.safe_remove(hand) self.player_money += bet * self.blackjack_pays self.count_card(self.dealer_hand[0]) if self.debug: print("PLAYER BLACKJACK!") print("player wins = ", bet * self.blackjack_pays) if self.need_to_play_dealer(): self.play_dealer() return elif is_21(self.dealer_hand): self.safe_remove(hand) self.player_money -= bet self.count_card(self.dealer_hand[0]) if self.debug: print("DEALER BLACKJACK!") print("player loses = ", bet) return move = self.get_move(hand) if move == "split": self.split_hand(hand, bet) return self.evaluate_move(move, hand, bet)
def need_to_play_dealer(self): """ If other player have a non-blackjack, non-busted hand, dealer must play """ if self.num_other_players == 0: return False for h in self.other_players: if not is_21(h) and sum(h) < 21: return True if is_21(h) and len(h) > 2: return True return False
def play(self): if self.debug: print("DummyPlayer.play", self.hand) if is_21(self.hand): if self.debug: print("DummyPlayer, got 21") return move = self.get_move(self.hand) if self.debug: print("DummyPlayer to play", move) if move == "stand": return if move == "split": if self.debug: print("DummyPlayer to split with splits_left=", self.splits_left) self.splits_left -= 1 hand0 = [self.hand[0]] hand1 = [self.hand[1]] hand0.append(self.game.get_card()) hand1.append(self.game.get_card()) if self.debug: print("DummyPlayer to play 2 hands", hand0, hand1) print("DummyPlayer now has splits_left=", self.splits_left) DummyPlayer(hand0, self.game, splits_left=self.splits_left).play() DummyPlayer(hand1, self.game, splits_left=self.splits_left).play() return if move == "double": self.hand.append(self.game.get_card()) if self.debug: print("DummyPlayer doubled and ends with", self.hand) return while move == "hit": self.hand.append(self.game.get_card()) if self.debug: print("DummyPlayer hit, now has", self.hand) if sum(self.hand) > 21: if self.debug: print("DummyPlayer busted") return move = self.get_move(self.hand)