コード例 #1
0
 def get_action(self, game: GameDriver, hand: BlackjackHand):
     if hand.is_splittable() and self.should_i_split(
             hand, game.dealer_card):
         return BlackjackAction.Split
     elif hand.is_soft():
         highest_value = hand.get_hand_total()
         return self.soft_action_grid.loc[highest_value][
             game.dealer_card.value]
     else:  # Hard hand
         highest_value = hand.get_hand_total()
         return self.hard_action_grid.loc[highest_value][
             game.dealer_card.value]
コード例 #2
0
 def get_action(self, game: GameDriver, hand: BlackjackHand):
     if hand.is_soft():
         if hand.get_hand_total() >= 17 + (
                 1 if Ruleset.rules().get("dealer_hits_on_soft_17") else 0):
             return BlackjackAction.Stay
         else:
             return BlackjackAction.Hit
     else:
         if hand.get_hand_total() >= 17:
             return BlackjackAction.Stay
         else:
             return BlackjackAction.Hit
コード例 #3
0
 def get_action(self, game: GameDriver, hand: BlackjackHand):
     if (Ruleset.rules().get("late_surrender") and hand.is_surrenderable()
             and self.df_surrender.loc[hand.get_hand_total(),
                                       game.dealer_card.value]):
         return BlackjackAction.Surrender
     elif hand.is_splittable() and self.df_split.loc[
             hand.cards[0].value, game.dealer_card.value]:
         return BlackjackAction.Split
     elif hand.is_soft():
         df = self.df_soft
         return df.loc[hand.get_hand_total(), game.dealer_card.value]
     else:
         df = self.df_hard
         return df.loc[hand.get_hand_total(), game.dealer_card.value]
コード例 #4
0
    def payout(self, hands: List[Tuple[Player, BlackjackHand]],
               dealer_hand: BlackjackHand):
        dealer_total = dealer_hand.get_hand_total()

        print("\nResults:")
        print(f"Hand - {dealer_hand} - {dealer_total}")
        summary_table = []
        for player, hand in hands:
            hand_summary = []
            player_total = hand.get_hand_total()
            if player == self.house:
                continue

            hand_summary += [
                player.name,
                ",".join([str(x) for x in hand.cards]),
                hand.get_hand_total(),
            ]
            if dealer_hand.is_blackjack():
                if hand.is_blackjack():
                    player.add_money(hand.bet)
                    hand_summary.append("Bump")
                    hand_summary.append(0)
                else:
                    hand_summary.append("Got jacked!")
                    hand_summary.append(-1 * hand.bet)
            else:
                if hand.is_busted():
                    hand_summary.append("Busted")
                    hand_summary.append(-1 * hand.bet)
                elif hand.is_blackjack():
                    hand_summary.append("Blackjack")
                    blackjack_win = (1.5 if Ruleset.rules().get(
                        "blackjack_pays_3_to_2", False) else 1.2) * hand.bet
                    hand_summary.append(blackjack_win)
                    player.add_money(blackjack_win + hand.bet)

                elif dealer_total > 21:
                    player.add_money(hand.bet * 2)  # original and winnings
                    hand_summary.append("Dealer Busted!")
                    hand_summary.append(hand.bet)

                elif dealer_total > player_total:
                    hand_summary.append("Dealer wins")
                    hand_summary.append(-1 * hand.bet)
                elif player_total > dealer_total:
                    player.add_money(hand.bet * 2)
                    hand_summary.append("In the money")
                    hand_summary.append(hand.bet)
                elif player_total == dealer_total:
                    player.add_money(hand.bet)
                    hand_summary.append("Bump")
                    hand_summary.append(0)
            summary_table.append(hand_summary)
        print(tabulate(summary_table))