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


Python Hand.deal方法代码示例

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


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

示例1: hit_stand

# 需要导入模块: from hand import Hand [as 别名]
# 或者: from hand.Hand import deal [as 别名]
def hit_stand():

    hand = Hand()
    hand.deal()

    h = ""
    s = ""

    choice = input("Would you like to Hit or Stand? H or S: ").lower()

    if choice == h:
        card = hand.deal(False)
        return card
开发者ID:williamjohngardner,项目名称:blackjack,代码行数:15,代码来源:functions.py

示例2: __init__

# 需要导入模块: from hand import Hand [as 别名]
# 或者: from hand.Hand import deal [as 别名]
class Player:

	def __init__(self,card1,card2):
		self.hand = Hand()
		self.hand.deal(card1,card2)
		self.blackjack = False

		if self.hand.getValue() == 21:
			self.blackjack = True

	def getHand(self):
		return self.hand

	def hit(self, card):
		self.hand.draw(card)

	def hasBlackjack(self):
		return self.blackjack

	def printHand(self):
		for card in self.hand:
			print(card)
		print("Value = %d\n" % self.hand.getValue())
开发者ID:snchzsrg,项目名称:blackjack-trainer,代码行数:25,代码来源:player.py

示例3: __init__

# 需要导入模块: from hand import Hand [as 别名]
# 或者: from hand.Hand import deal [as 别名]
class Blackjack:
    def __init__(self, players):
        self.deck = cards.standard_deck()
        self.players = players
        self.hand = 0

    def new_hand(self):
        self.hand = Hand(self.players, self.deck)
        self.deck.shuffle_deck()
        self.hand.deal(2)

        if self.check_outright_win() == True:
            pass

        else:
            starting_players = self.hand.get_players()
            dealer_number = 0

            # [:] is taking the whole array and making a new copy rather than reference
            # so that it can be modified within the 'for' loop.

            for p in starting_players[:]:
                if p.player_type == 'user':
                    p.set_bet(input(
                        "\nCurrent Money: {0}\nHow much would you like to bet?\n > "
                        .format(p.get_current_money())
                        ))

                    self.evaluate_cards(p)

                elif p.player_type == 'dealer':
                    # IMPLICIT ASSUMPTION: dealer is appended last to the player array
                    dealer_number = self.dealer_behavior(p)

            remaining_players = self.hand.get_players()

            for p in remaining_players[:]:
                if p.player_type == 'user':
                    self.calculate_winners(p, dealer_number)

    def calculate_winners(self, player, dealer_number):
        player_number = self.calculate_hand_value(player)

        if dealer_number == None or player_number > dealer_number:
            print("\n{0} WINS!\n+ ${1}\n".format(
                player.get_name(),
                player.get_bet(),
                ))

            player.set_current_money(player.get_current_money() + player.get_bet())

        elif player_number < dealer_number:
            print("{0} LOSES ... {1}\n".format(
                player.get_name(),
                player_number
                ))

    def calculate_hand_value(self, player):
        current_val = 0
        current_hand = player.player_hand.get_current_cards()
        num_aces = 0

        for card in current_hand:
            current_val += card.get_value()
            if card.get_face() =='A':
                num_aces += 1

        while current_val > 21 and num_aces > 0:
            current_val = current_val - 10
            num_aces -= 1

        return current_val

    def get_highest_handval(self):
        highest = 0
        for p in self.hand.get_players():
            this_handval = self.calculate_hand_value(p)
            if this_handval > highest:
                highest = this_handval

        return highest

    def evaluate_cards(self, player):
        player.player_hand.times_evaluated += 1

        the_number = self.calculate_hand_value(player)

        if the_number > 21:
            self.bust(player)

        elif the_number < 21:
            self.get_choices(player)

        elif the_number == 21:
            print("Current Hand {0}, Total: {1}\n"
            .format(
                player.player_hand.display_current_hand(),
                self.calculate_hand_value(player)
            ))

#.........这里部分代码省略.........
开发者ID:Rsq2,项目名称:blackjack,代码行数:103,代码来源:blackjack.py


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