本文整理汇总了Python中hand.Hand.isBust方法的典型用法代码示例。如果您正苦于以下问题:Python Hand.isBust方法的具体用法?Python Hand.isBust怎么用?Python Hand.isBust使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类hand.Hand
的用法示例。
在下文中一共展示了Hand.isBust方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_bustedHandWithAce
# 需要导入模块: from hand import Hand [as 别名]
# 或者: from hand.Hand import isBust [as 别名]
def test_bustedHandWithAce(self):
hand = Hand(1)
hand.addCard(Card(1, 0))
hand.addCard(Card(1, 6))
hand.addCard(Card(1, 6))
hand.addCard(Card(1, 9))
self.assertTrue(hand.isBust())
示例2: test_emptyHandNotBust
# 需要导入模块: from hand import Hand [as 别名]
# 或者: from hand.Hand import isBust [as 别名]
def test_emptyHandNotBust(self):
hand = Hand(1)
self.assertFalse(hand.isBust())
示例3: executeRound
# 需要导入模块: from hand import Hand [as 别名]
# 或者: from hand.Hand import isBust [as 别名]
def executeRound(self):
# A map of hands to the players who control them.
handPlayerMap = {}
inactiveHandPlayerMap = {}
deck = Deck(1, 4, 13)
# Deal cards to the dealer. The dealer has a bet of 0.
dealerHand = Hand(0)
dealerHand.addCard(deck.take())
dealerHand.addCard(deck.take())
for playerAgent in self.playerAgents:
# TODO(snowden): Allow players to choose how much
# they bet each time.
playerHand = Hand(1)
playerHand.addCard(deck.take())
playerHand.addCard(deck.take())
handPlayerMap[playerHand] = playerAgent
# While there are still hands in play, ask the
# agent controlling the hand for the next action.
while handPlayerMap:
# It isn't possible to modify the keys of the existing
# map, so we have to create a new one each iteration.
newHandPlayerMap = {}
remainingHandPlayerMap = handPlayerMap
for (hand, playerAgent) in handPlayerMap.items():
currentHandPlayerMap = dict(newHandPlayerMap.items() +
remainingHandPlayerMap.items())
del remainingHandPlayerMap[hand]
action = playerAgent.getNextAction(
GameState(currentHandPlayerMap,
dealerHand, deck), hand)
if action == Actions.HIT:
hand.hit(deck)
if hand.isBust():
inactiveHandPlayerMap[hand] = playerAgent
else:
newHandPlayerMap[hand] = playerAgent
elif action == Actions.STAND:
hand.stand(deck)
# If the action is to stand, remove the hand from
# the map of active hands and add it to the map
# of inactive hands.
inactiveHandPlayerMap[hand] = playerAgent
elif action == Actions.SPLIT:
splitHands = hand.split(deck)
newHandPlayerMap[splitHands[0]] = playerAgent
newHandPlayerMap[splitHands[1]] = playerAgent
elif action == Actions.DOUBLE_DOWN:
hand.doubleDown(deck)
# After doubling down, the player may take no
# further actions.
inactiveHandPlayerMap[hand] = playerAgent
else:
raise ValueError("Not yet implemented.")
handPlayerMap = newHandPlayerMap
# All agents have either indicated that they want to
# stand or else have busted, so it is the dealer's
# turn to act.
while True:
# The dealer is not permitted to act on the cards
# that players have been dealt and can only hit
# or stand with each card received.
dealerAction = self.dealerAgent.getNextAction(None, dealerHand)
if dealerAction == Actions.STAND:
break
elif dealerAction == Actions.HIT:
dealerHand.hit(deck)
if dealerHand.isBust():
break
# print
# print "Dealer has: %s" % dealerHand.getValidCount()
# print "Player has: %s" % map(Hand.getValidCount, inactiveHandPlayerMap.keys())
# The dealer has finished executing its actions. Compare
# the dealer's hands with those of the players to determine
# winners and losers.
endingState = GameState(inactiveHandPlayerMap, dealerHand, deck)
for (hand, playerAgent) in inactiveHandPlayerMap.items():
result = self.determineWinner(hand, dealerHand)
# print result
if result < 0:
playerAgent.lose(endingState, hand)
self.losses[playerAgent] += 1
self.balances[playerAgent] -= hand.getBet()
elif result > 0:
playerAgent.win(endingState, hand)
self.wins[playerAgent] += 1
self.balances[playerAgent] += hand.getBet() * 1.5 if hand.isBlackJack() else 1
else: # result == 0
playerAgent.tie(endingState, hand)
self.ties[playerAgent] += 1
# Return the cards in the hand to the deck.
for card in hand.getCards():
deck.give(card)
# Return the dealer's cards to the deck.
for card in dealerHand.getCards():
deck.give(card)
#.........这里部分代码省略.........