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


Python Hand.split方法代码示例

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


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

示例1: NormalPlayer

# 需要导入模块: from hand import Hand [as 别名]
# 或者: from hand.Hand import split [as 别名]
class NormalPlayer(Player):
    '''This class corresponds to normal players in the table'''
    def __init__(self, hand=None, money=0, name = "Stranger"):
        Player.__init__(self, hand, money, name)
        self._issplit=False

    def startMatch(self,cards):
        self._hand=Hand(cards)

    def hasEnoughToBet(self,bet=0):
        '''Check whether a player has enough to bet'''
        return self.money()>=bet

    def isSplit(self):
        '''Check whether the player has split.'''
        return self._issplit

    def extraChips(self,dollar):
        ''' extraChips(int) -> None -- Receive dollar worth of money'''
        assert(dollar >= 0)
        self._money += dollar

    def updateAfterDouble(self,card,bet=0):
        '''Updates player's instance after doubling and makes sure player has enough'''
        try:
            if self.hasEnoughToBet(int(bet)):
                self._money-=bet
                self._hand.receive(card)
            else:
                print("Not enough money to double")
        except ValueError:
            print ("Bet is not an integer")

    def updateAfterSplit(self,bet=0):
        '''Updates player after he split his pair. Creates an alternative hand'''
        try:
            if self.hasEnoughToBet(int(bet)):
                self._money-=bet
                self._secondhand = self._hand.split()
                self._issplit=True
            else:
                print("Not enough money to double")
        except ValueError:
            print ("Bet is not an integer")

    def updateAfterSecondHit(self):
        pass

    def updateAfterBet(self,bet=0):
        '''Updates player's money after betting and makes sure player has enough'''
        try:
            if self.hasEnoughToBet(int(bet)):
                self.money-=bet
            else:
                print("Not enough money to bet")
        except ValueError:
            print ("Bet is not an integer")
开发者ID:JeromeLefebvre,项目名称:CardsForTheWorkingMathematician,代码行数:59,代码来源:player.py

示例2: test_split

# 需要导入模块: from hand import Hand [as 别名]
# 或者: from hand.Hand import split [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


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