Пример #1
0
    def play_dealer(self):
        hard, soft = get_hard_soft(self.dealer_hand)

        has_soft = soft != hard
        hit_if_less_than = 18 if (has_soft and self.dealer_hit_on_soft_17) else 17

        while soft < hit_if_less_than:
            self.dealer_hand.append(self.get_card())
            hard, soft = get_hard_soft(self.dealer_hand)
        if self.debug:
            print("dealer done", self.dealer_hand)
        return soft
Пример #2
0
    def evaluate_move(self, move, hand, bet):
        dh = self.dealer_hidden
        if move == "stand":

            if self.debug:
                hard, soft = get_hard_soft(hand)
                print("player stands at", soft)

            if self.hands:
                if self.debug:
                    print("MULTIPLE HANDS", self.hands)
                # wait until all hands are played before dealer plays
                self.deferred.append(partial(self.eval_stand, hand, bet))
                self.safe_remove(hand)
                return
            else:
                return self.eval_stand(hand, bet)

        if move == "hit":
            hand.append(self.get_card())
            hard, soft = get_hard_soft(hand)
            if self.debug:
                print("player hit, now has", hand)
            if hard > 21:
                self.safe_remove(hand)
                self.player_money -= bet
                self.count_card(dh)
                if self.debug:
                    print("player busted", hard, "loses", bet)
                if self.need_to_play_dealer():
                    self.play_dealer()
                return
            move = self.get_move(hand)
            self.evaluate_move(move, hand, bet)

        if move == "double":
            hand.append(self.get_card())
            hard, soft = get_hard_soft(hand)
            if self.debug:
                print("player doubles, now has", hand)
            if hard > 21:
                self.safe_remove(hand)
                self.player_money -= bet * 2
                self.count_card(dh)
                if self.debug:
                    print("player doubled and busted", hard, "loses", bet * 2)
                if self.need_to_play_dealer():
                    self.play_dealer()
                return
            self.evaluate_move("stand", hand, bet * 2)
Пример #3
0
    def get_move(self, hand):
        # unfortunate duplication of Game.get_move FIXME
        dealershows = self.game.dealershows
        first = len(hand) == 2
        hard, soft = get_hard_soft(hand)
        can_split = first and (hand[0] == hand[1])

        if can_split and bool(self.splits_left):
            split = bs.basic_strategy_split[hand[0]][dealershows]
            if split:
                return "split"

        use_hard = hard == soft
        if use_hard:
            move = bs.basic_strategy_hard[hard][dealershows]
        else:
            move = bs.basic_strategy_soft[soft][dealershows]

        if self.allowed_splits is not None:
            has_not_split = self.allowed_splits == self.splits_left
        else:
            has_not_split = self.splits_left == -1

        can_double = first and (self.can_double_after_split or has_not_split)
        if not can_double and move == "double":
            move = "hit" if soft < 17 else "stand"

        return move
Пример #4
0
    def get_move(self, hand):
        """Pass in hand b/c of split"""
        dealershows = self.dealershows
        first = len(hand) == 2
        hard, soft = get_hard_soft(hand)
        can_split = first and (hand[0] == hand[1])

        if can_split and bool(self.splits_left):
            split = bs.basic_strategy_split[hand[0]][dealershows]
            if split:
                return "split"

        use_hard = hard == soft
        if use_hard:
            move = bs.basic_strategy_hard[hard][dealershows]
        else:
            move = bs.basic_strategy_soft[soft][dealershows]

        if self.allowed_splits is not None:
            has_not_split = self.allowed_splits == self.splits_left
        else:
            has_not_split = self.splits_left == -1

        can_double = first and (self.can_double_after_split or has_not_split)
        # not quite sure about this. strategy says double
        # but, we can't double - we have split and not can_double_after_split.
        # or, we have more than 2 cards, so the time for doubling is over.
        # I think that means we hit ... always?
        # should this be configurable or is there a hard rule?
        if not can_double and move == "double":
            move = "hit"  # if soft < 17 else "stand"

        return move
Пример #5
0
 def eval_stand(self, hand, bet):
     hard, soft = get_hard_soft(hand)
     self.count_card(self.dealer_hidden)
     dealer_total = self.play_dealer()
     if self.debug:
         print("dealer has", dealer_total)
         print("player hand", hand)
     if dealer_total > 21:
         self.player_money += bet
         if self.debug:
             print("dealer busted. adding bet=", bet)
         return
     elif soft > dealer_total:
         self.player_money += bet
         if self.debug:
             print("player wins", bet)
         return
     elif soft == dealer_total:
         if self.debug:
             print("push")
         return
     else:
         self.player_money -= bet
         if self.debug:
             print("player loses", bet)
         return