当前位置: 首页>>代码示例>>Python>>正文


Python Hand.value_the_cards方法代码示例

本文整理汇总了Python中hand.Hand.value_the_cards方法的典型用法代码示例。如果您正苦于以下问题:Python Hand.value_the_cards方法的具体用法?Python Hand.value_the_cards怎么用?Python Hand.value_the_cards使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在hand.Hand的用法示例。


在下文中一共展示了Hand.value_the_cards方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: __init__

# 需要导入模块: from hand import Hand [as 别名]
# 或者: from hand.Hand import value_the_cards [as 别名]
class PlayTheHands:
    def __init__(self):
        self.deck = Deck()
        self.players_hand = Hand()
        self.dealers_hand = Hand()

    def players_logic(self):
        Hand.initial_deal(self.players_hand)
        print("Player holding: ", self.players_hand)
        print("Player's cards tally: ", self.players_hand.value_the_cards())
        while self.players_hand.value_the_cards() < 21:
            hit = input("Hit or Stay? H/S ").lower()
            if hit == 'h':
                Hand.draw_a_card(self.players_hand)
                print("Player holding: ", self.players_hand)
                print("Player's cards tally: ", self.players_hand.value_the_cards())  # for testing
                if self.players_hand.value_the_cards() > 21:
                    print("Player's hand is a bust.")
            else:
                print("Player's cards tally: ", self.players_hand.value_the_cards())
                break
        player_total = self.players_hand.value_the_cards()
        return player_total

    def dealers_logic(self):
        Hand.initial_deal(self.dealers_hand)
        print("Dealer holding: ", self.dealers_hand)
        while self.dealers_hand.value_the_cards() < 17:
            Hand.draw_a_card(self.dealers_hand)
            print("Dealer now holding: ", self.dealers_hand)
            # print("Dealer's cards tally: ", self.dealers_hand.value_the_cards())  # for testing
        if self.dealers_hand.value_the_cards() > 21:
            print("Dealer's hand is bust at {}.".format(self.dealers_hand.value_the_cards()))
        else:
            print("Dealer's hand: ", self.dealers_hand.value_the_cards())
        dealer_total = self.dealers_hand.value_the_cards()
        return dealer_total
开发者ID:hpaasch,项目名称:blackjack,代码行数:39,代码来源:heptest.py

示例2: __init__

# 需要导入模块: from hand import Hand [as 别名]
# 或者: from hand.Hand import value_the_cards [as 别名]
class PlayTheHands:
    def __init__(self):
        self.deck = Deck()
        self.players_hand = Hand()
        self.dealers_hand = Hand()
        self.bet = 10

    def opening(self):
        Hand.initial_deal(self.players_hand)
        Hand.initial_deal(self.dealers_hand)
        print("-" * 40)
        print("\nThe hand opens: \n")
        print("Dealer showing one: {}".format(self.dealers_hand.cards_in_hand[0]))
        print("Player showing: ", self.players_hand)
        print("Player's cards tally: ", self.players_hand.value_the_cards())

    def players_logic(self):
        print("-" * 40)
        while self.players_hand.value_the_cards() < 21:
            hit = input("Hit or Stay? H/S ").lower()
            if hit == 'h':
                Hand.draw_a_card(self.players_hand)
                print("Player holding: ", self.players_hand)
                print("Player's cards tally: ", self.players_hand.value_the_cards())
                if self.players_hand.value_the_cards() > 21:
                    print("Player's hand is a bust.")
            else:
                print("Player's cards tally: ", self.players_hand.value_the_cards())
                break
        return self.players_hand.value_the_cards()

    def dealers_logic(self):
        print("-" * 40)
        print("Dealer showing both now: ", self.dealers_hand)
        if self.players_hand.value_the_cards() > 21:
            self.bet = -10
            print("Dealer wins.")
        elif self.dealers_hand.value_the_cards() > self.players_hand.value_the_cards():
            self.bet = -10
            print("Dealer wins with {}.".format(self.dealers_hand.value_the_cards()))
        else:
            while self.dealers_hand.value_the_cards() < 17:
                Hand.draw_a_card(self.dealers_hand)
                print("Dealer takes a card: ", self.dealers_hand)
            if self.dealers_hand.value_the_cards() > 21:
                print("Dealer's hand busted at {}. Player wins.".format(self.dealers_hand.value_the_cards()))
            elif self.dealers_hand.value_the_cards() == self.players_hand.value_the_cards():
                self.bet = -10
                print("Dealer: {}. Player: {}. Dealer wins ties.".format(self.dealers_hand.value_the_cards(),
                                                                         self.players_hand.value_the_cards()))
            elif self.dealers_hand.value_the_cards() < self.players_hand.value_the_cards() < 22:
                print("Dealer's tally: {}. Player wins.".format(self.dealers_hand.value_the_cards()))
            else:
                self.bet = -10
                print("Dealer wins with {}.".format(self.dealers_hand.value_the_cards()))
        return self.dealers_hand.value_the_cards()
开发者ID:hpaasch,项目名称:blackjack,代码行数:58,代码来源:player.py


注:本文中的hand.Hand.value_the_cards方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。