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


Python Hand.is_soft方法代码示例

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


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

示例1: Player

# 需要导入模块: from hand import Hand [as 别名]
# 或者: from hand.Hand import is_soft [as 别名]
class Player():
    def __init__(self, name, bankroll):
        self.hand = Hand()
        self.bankroll = bankroll
        self.name = name
        self.bet = 0

    def play_hand(self, dealer_card):
        while True:
            recommend = basic_strategy(self.hand.value(), dealer_card.value(), self.hand.is_soft())

            if len(self.hand.cards) == 2:
                move = raw_input("%s: %s - hit/stand/double? (we recommend %s) " % (self.name, self.hand, recommend)).lower()
            else:
                # for simplicity. This is not true for soft 18.
                if recommend == 'double':
                    recommend = 'hit'

                move = raw_input("%s: %s - hit/stand? (we recommend %s) " % (self.name, self.hand, recommend)).lower()

            if move.startswith('h'):
                return 'hit'
            elif move.startswith('s'):
                return 'stand'
            elif move.startswith('d'):
                return 'double'

            print "Invalid move"

    def __str__(self):
        return '(%s, $%s)' % (self.name, self.bankroll)

    def is_bust(self):
        return self.hand.value() > 21
开发者ID:v,项目名称:blackjack,代码行数:36,代码来源:player.py

示例2: Dealer

# 需要导入模块: from hand import Hand [as 别名]
# 或者: from hand.Hand import is_soft [as 别名]
class Dealer(object):

	def __init__(self):
		self.hand = Hand()

	def deal_card(self, card_table):
		card = card_table.shoe.get_next_card()
		for chair in card_table.chairs:
			chair.player.observe_card(card)
		return card

	def deal_round(self, card_table):
		for _ in range(2):
			for chair in card_table.chairs:
				if chair.hands[0]['bet'] is not "bankrupt":
					chair.hands[0]['hand'].add_card(self.deal_card(card_table))
				else:
					chair.active = False
			for chair in card_table.chairs:
				if chair.active:
					self.hand.add_card(self.deal_card(card_table))
					break

	def hit_dealer(self, card_table):
		while self.hand.is_soft():
			if self.hand.total < 18:
				self.hand.add_card(self.deal_card(card_table))
			else:
				break
		while self.hand.total < 17:
			self.hand.add_card(self.deal_card(card_table))

	def pay_player(self, hand, chair):
		chair.player.bankroll += hand['bet'] * 2

	def pay_player_blackjack(self, chair, blackjack_payout):
		bet = chair.hands[0]['bet'] + chair.hands[0]['bet'] * blackjack_payout
		chair.player.bankroll += bet

	def refund_player(self, hand, chair):
		chair.player.bankroll += hand['bet']

	def resolve_round(self, card_table):
		for chair in card_table.chairs:
			if chair.active:
				self.hit_dealer(card_table)
				break
		for chair in card_table.chairs:
			if chair.active:
				if self.hand.is_busted():
					for hand in chair.hands:
						if hand['hand'].is_busted() is False:
							self.pay_player(hand, chair)
				else:
					for hand in chair.hands:
						if self.hand.total < hand['hand'].total:
							self.pay_player(hand, chair)
						elif self.hand.total is hand['hand'].total:
							self.refund_player(hand, chair)

	def showing(self):
		return self.hand.cards[0].get_value()
开发者ID:andyrockenbach,项目名称:Projects,代码行数:64,代码来源:dealer.py


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