Example #1
0
 def make_dealer_move(self):
     if len(self.cards) == 0:
         return
     if Rulebook.check_dealer_hit(Rulebook.check_hand_value(self.cards)):
         self.cards.append(self.deck.draw_card())
         if Rulebook.check_bust(Rulebook.check_hand_value(self.cards)):
             self.end_hand()
             return
         self.update_view()
         self.make_dealer_move()
Example #2
0
 def get_player_move(self):
     print("Hit? [Y/N]")
     option = input()
     if option.upper() == "Y":
         self.player.add_card(self.deck.draw_card())
         if not Rulebook.check_bust(
                 Rulebook.check_hand_value(self.player.get_cards())):
             self.update_view()
             self.get_player_move()
         else:
             self.end_hand()
Example #3
0
    def end_hand(self):
        if len(self.cards) == 0:
            return
        self.hand_hidden = False
        message = ""

        #case for player bust:
        if Rulebook.check_bust(
                Rulebook.check_hand_value(self.player.get_cards())):
            message = "Player busts! Dealer wins."
        #case for dealer bust:
        elif Rulebook.check_bust(Rulebook.check_hand_value(self.cards)):
            message = "Dealer busts! Player wins."
        #case for player beating dealer:
        elif Rulebook.check_player_win(
                Rulebook.check_hand_value(self.cards),
                Rulebook.check_hand_value(self.player.get_cards())):
            message = "Player wins!"
        #case for dealer beating player:
        elif Rulebook.check_dealer_win(
                Rulebook.check_hand_value(self.cards),
                Rulebook.check_hand_value(self.player.get_cards())):
            message = "Dealer wins!"
        #case for tie
        else:
            message = "Tie!"

        self.update_view(message)

        #Reset cards
        self.cards = []
        self.player.collect_cards()
Example #4
0
 def get_score(self):
     return Rulebook.check_hand_value(self.get_cards())
Example #5
0
 def update_view(self, custom_message=""):
     ModelView.update_view(
         self.cards, self.player.get_cards(),
         Rulebook.check_hand_value(self.cards, self.hand_hidden),
         Rulebook.check_hand_value(self.player.get_cards()),
         self.hand_hidden, custom_message)
Example #6
0
 def test_chv_shown_ace(self):
     self.assertEqual(Rulebook.check_hand_value(['3', 'A'], True), "1 or 11")
Example #7
0
 def test_chv_hidden_ace(self):
     self.assertEqual(Rulebook.check_hand_value(['A', '6'], True), "6")
Example #8
0
 def test_chv_ace(self):
     self.assertEqual(Rulebook.check_hand_value(['3', 'A']), "4 or 14")
Example #9
0
 def test_chv(self):
     self.assertEqual(Rulebook.check_hand_value(['3', '5']), "8")