本文整理汇总了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")
示例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())