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


Python Hand.getCards方法代码示例

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


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

示例1: test_doubleDown

# 需要导入模块: from hand import Hand [as 别名]
# 或者: from hand.Hand import getCards [as 别名]
    def test_doubleDown(self):
        hand = Hand(1)
        hand.addCard(Card(0, 1))
        hand.addCard(Card(1, 1))
        deck = HandTest.FakeDeck()
        self.assertTrue(hand.canDoubleDown())
        hand.doubleDown(deck)
        self.assertEqual(2, hand.getBet())
        self.assertEqual(3, len(hand.getCards()))
        self.assertEqual(Card(3, 0), hand.getCards()[2])

        hand = Hand(1)
        hand.addCard(Card(0, 1))
        hand.addCard(Card(1, 1))
        hand.addCard(Card(2, 1))
        self.assertFalse(hand.canDoubleDown())
开发者ID:melonhead901,项目名称:vegas,代码行数:18,代码来源:hand_test.py

示例2: test_split

# 需要导入模块: from hand import Hand [as 别名]
# 或者: from hand.Hand import getCards [as 别名]
    def test_split(self):
        hand = Hand(1)
        hand.addCard(Card(0, 1))
        hand.addCard(Card(1, 1))
        deck = HandTest.FakeDeck()
        self.assertTrue(hand.canSplit())
        self.assertFalse(hand.isSplit())
        splitHands = hand.split(deck)
        self.assertEqual(1, splitHands[0].getBet())
        self.assertEqual(1, splitHands[1].getBet())
        self.assertTrue(splitHands[0].isSplit())
        self.assertTrue(splitHands[1].isSplit())
        self.assertFalse(splitHands[0].canSplit())
        self.assertFalse(splitHands[1].canSplit())
        self.assertEqual(hand.getCards()[0], splitHands[0].getCards()[0])
        self.assertEqual(Card(3, 0), splitHands[0].getCards()[1])
        self.assertEqual(hand.getCards()[1], splitHands[1].getCards()[0])
        self.assertEqual(Card(3, 1), splitHands[1].getCards()[1])

        hand = Hand(1)
        hand.addCard(Card(0, 1))
        hand.addCard(Card(1, 1))
        hand.addCard(Card(2, 1))
        self.assertFalse(hand.canSplit())
开发者ID:melonhead901,项目名称:vegas,代码行数:26,代码来源:hand_test.py

示例3: executeRound

# 需要导入模块: from hand import Hand [as 别名]
# 或者: from hand.Hand import getCards [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)
#.........这里部分代码省略.........
开发者ID:melonhead901,项目名称:vegas,代码行数:103,代码来源:game.py

示例4: Player

# 需要导入模块: from hand import Hand [as 别名]
# 或者: from hand.Hand import getCards [as 别名]
class Player(object):
    HUMAN = 1
    COMPUTER = 0
    
    def __init__(self,name,tyyppi):
        self.__name=name
        self.__cottages=0
        self.__points=0
        self.__hand = Hand()
        self.__type = tyyppi
        self.__stack = Hand()
        
    '''
    name methods
    '''
    def getName(self):
        return self.__name
        
    '''
    point methods
    '''
    def updatePoints(self,amount):
        self.__points += amount
        
    def setPoints(self,amount):
        self.__points = amount
        
    def getPoints(self):
        return self.__points
        
    '''
    cottage methods
    '''
    def getCottages(self):
        return self.__cottages  
        
    def raiseCottages(self,amount):
        self.__cottages+=amount
        
    def setCottages(self,amount):
        self.__cottages=amount
        
    def clearCottages(self):
        self.__cottages=0
        
    '''
    hand methods
    '''
    def getHand(self):
        return self.__hand
    
    def addCardsToHand(self,cards):
        self.__hand.addCards(cards)
            
    def addCardToHand(self,card):
        self.__hand.append(cards)
    
    def setHand(self,cards):
        self.__hand.clear()
        self.__hand.addCards(cards)
    
    def hasCards(self):
        return len(self.__hand.getCards())>0
    
    '''
    stack methods
    '''
    def getStack(self):
        return self.__stack
    
    def clearStack(self):
        self.__stack=Hand()
    
    def addCardsToStack(self,cards):
        for card in cards:
            self.addCardToStack(card)
            
    def addCardToStack(self,card):
        self.__stack.addCard(card)
    
    def setStack(self,cards):
        self.__stack.clear()
        self.__stack.addCards(cards)
    
    '''
    type methods
    '''
    def getType(self):
        return self.__type
            
    '''
    other methods
    '''
    def getScoreFromStack(self):
        points = self.__cottages
        points += self.__stack.getSureValue()
        return points
    
    def __str__(self):
        return self.__name+"-"+str(self.__points)
#.........这里部分代码省略.........
开发者ID:severi,项目名称:Casino,代码行数:103,代码来源:player.py


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