def _ace_split_hit(self, player: Player, hand: Hand) -> None: """Handle a hand made by splitting a pair of aces. It also handles hands hit after doubling down. :param player: The player who owns the hand. :param hand: The hand to hit. :return: None. :rtype: None. """ card = self._draw() card.flip() hand.append(card) self.ui.hit(player, hand) self.ui.stand(player, hand)
def _double_down(self, player: Player, hand: Hand) -> None: """Handle the double down decision on a hand. :param player: The player who owns the hand. :param hand: The hand to make the decision on. :return: None. :rtype: None. """ scores = [score for score in hand.score() if score < 12 and score > 8] if (scores and not hand.is_blackjack() and player.chips >= self.buyin and player.will_double_down(hand, self)): hand.doubled_down = True player.chips -= self.buyin self.ui.doubledown(player, self.buyin)
def deserialize(cls, s): """When called with a Player object serialized as a JSON string, return the deserialized Player object. """ serial = loads(s) serial['hands'] = [Hand.deserialize(hand) for hand in serial['hands']] return cls.fromdict(serial)
def _split(self, hand: Hand, player: Player) -> bool: """Handle the splitting decision on a hand. :param hand: The hand to determine whether to split. :param player: The player who owns the hand. :return: Whether the hand was split. :rtype: bool """ if (hand[0].rank == hand[1].rank and player.will_split(hand, self) and player.chips >= self.buyin): new_hand1 = Hand([hand[0],]) new_hand2 = Hand([hand[1],]) player.hands = (new_hand1, new_hand2) player.chips -= self.buyin self.ui.splits(player, 20) return True return False
def will_hit_dealer(self, hand:Hand, the_game=None) -> bool: """Determine whether the player will hit or stand on the hand. :param hand: The hand to make the decision on. :return: The hit decision. True to hit. False to stand. :rtype: Bool. """ scores = [score for score in sorted(hand.score()) if score <= 21] try: score = scores[-1] except IndexError: return STAND else: if score >= 17: return STAND return HIT
def will_hit_recommended(self, hand:Hand, the_game) -> bool: """Make hit decisions as recommended by bicycle.com.""" dhand = the_game.dealer.hands[0] scores = [score for score in hand.score() if score <= 21] try: score = scores.pop() except IndexError: return False if scores and score <= 18: return True elif (dhand[0].rank >= 7 or dhand[0].rank == 1) and score < 17: return True elif dhand[0].rank <= 3 and score < 13: return True elif score < 12: return True return False
def will_double_down_recommended(self, hand: Hand, the_game) -> bool: """The player will follow the double down recommendation from bicycle.com. :param hand: The hand to make the decision on. :param the_game: The information about the current game to use to make a decision. :return: A decision whether to double down. :rtype: bool """ scores = [score for score in hand.score() if score <= 21] dcard = the_game.dealer.hands[0][0] if 11 in scores: return True elif 10 in scores and dcard.rank < 10 and dcard.rank > 1: return True elif 9 in scores and dcard.rank >= 2 and dcard.rank <= 6: return True return False
def _build_hand(self): """create the initial hand and deal a card into it.""" card = self._draw() card.flip() return Hand([card,])
def _build_hand(deck): """create the initial hand and deal a card into it.""" card = deck.draw() card.flip() return Hand([card,])