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


Python Hand.addCard方法代码示例

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


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

示例1: test_bustedHandWithAce

# 需要导入模块: from hand import Hand [as 别名]
# 或者: from hand.Hand import addCard [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())
开发者ID:melonhead901,项目名称:vegas,代码行数:9,代码来源:hand_test.py

示例2: createFourCard20PointHand

# 需要导入模块: from hand import Hand [as 别名]
# 或者: from hand.Hand import addCard [as 别名]
 def createFourCard20PointHand(self):
     hand = Hand(1)
     hand.addCard(Card(1, 1))
     hand.addCard(Card(1, 2))
     hand.addCard(Card(1, 3))
     hand.addCard(Card(1, 4))
     return hand
开发者ID:melonhead901,项目名称:vegas,代码行数:9,代码来源:hand_test.py

示例3: test_stand

# 需要导入模块: from hand import Hand [as 别名]
# 或者: from hand.Hand import addCard [as 别名]
 def test_stand(self):
     hand = Hand(1)
     hand.addCard(Card(0, 1))
     hand.addCard(Card(1, 1))
     deck = HandTest.FakeDeck()
     self.assertTrue(hand.canStand())
     hand.stand(deck)
开发者ID:melonhead901,项目名称:vegas,代码行数:9,代码来源:hand_test.py

示例4: test_4CardHand

# 需要导入模块: from hand import Hand [as 别名]
# 或者: from hand.Hand import addCard [as 别名]
 def test_4CardHand(self):
     hand = Hand(0)
     hand.addCard(Card(1, 6))
     hand.addCard(Card(1, 4))
     hand.addCard(Card(1, 2))
     hand.addCard(Card(1, 0))
     dealer = DealerAgent()
     self.assertEqual(Actions.HIT, dealer.getNextAction(None, hand))
开发者ID:melonhead901,项目名称:vegas,代码行数:10,代码来源:dealer_agent_test.py

示例5: test_hit

# 需要导入模块: from hand import Hand [as 别名]
# 或者: from hand.Hand import addCard [as 别名]
 def test_hit(self):
     hand = Hand(1)
     hand.addCard(Card(0, 1))
     hand.addCard(Card(1, 1))
     deck = HandTest.FakeDeck()
     self.assertTrue(hand.canHit())
     hand.hit(deck)
     self.assertTrue(hand.canHit())
     hand.hit(deck)
开发者ID:melonhead901,项目名称:vegas,代码行数:11,代码来源:hand_test.py

示例6: testEntireDeckNoCountMultiRound

# 需要导入模块: from hand import Hand [as 别名]
# 或者: from hand.Hand import addCard [as 别名]
 def testEntireDeckNoCountMultiRound(self):
     # The entire deck should be neutral
     deck = Deck(1, 4, 13)
     dealerHand = Hand(1)
     for _ in range(6):
         dealerHand.addCard(deck.take())
     playerHandMap = {}
     for i in range(3):
         hand = Hand(1)
         for _ in range(6):
             hand.addCard(deck.take())
         playerHandMap[hand] = i
             
     self.assertEqual(52-6*4, deck.numActiveCards())    
     gameState = GameState(playerHandMap, dealerHand, deck)
     self.agent.gameOver(gameState, playerHandMap.keys()[0], 1)
     
     dealerHand = Hand(1)
     for _ in range(7):
         dealerHand.addCard(deck.take())
     playerHandMap = {}
     for i in range(3):
         hand = Hand(1)
         for _ in range(7):
             hand.addCard(deck.take())
         playerHandMap[hand] = i
         
     self.assertEqual(0, deck.numActiveCards())   
     gameState = GameState(playerHandMap, dealerHand, deck)
     self.agent.gameOver(gameState, playerHandMap.keys()[0], 1)
     self.assertEqual(0, self.agent.count)
开发者ID:melonhead901,项目名称:vegas,代码行数:33,代码来源:count_learning_agent_test.py

示例7: printAcePolicy

# 需要导入模块: from hand import Hand [as 别名]
# 或者: from hand.Hand import addCard [as 别名]
def printAcePolicy(agent):
    printPolicyHeader("aces")
    for nonAceCard in range(10,1,-1):
        printString = "{0}\t".format(nonAceCard)
        for dealerSoftCard in range(2,12):
            dummyHand = Hand(1)
            dummyHand.addCard(Card(1, 0))
            dummyHand.addCard(Card(1, nonAceCard-1))
            # Construct features for this cell
            features = (nonAceCard+1, True, dealerSoftCard)
            # print the action for that features
            action = agent.getPolicy(features, dummyHand)[0]
            color = getColor(action)
            printString += '{0}{1}\t'.format(color, action)
#           key = (features, action)
#           if key in agent.q_values:
#               str += "%0.2f\t" % agent.q_values[key]
#           else:
#               str += '\t'
        print printString + "\033[1;37m"
开发者ID:melonhead901,项目名称:vegas,代码行数:22,代码来源:game.py

示例8: play

# 需要导入模块: from hand import Hand [as 别名]
# 或者: from hand.Hand import addCard [as 别名]
   def play(self, deck, dealer_hand = None):

      # play all hands once
      i = 0
      while i < len(self._chairs):
         chair = self._chairs[i]
         i+=1

         while not chair['hand'].isOver():
            action = self._strategy.chooseAction(chair['hand'], dealer_hand)

            if action == 'P':
               chair['hand'].addCard(deck.pick())
            if action == 'L':
               break;
            if action == 'D':
               self._pot -= chair['bet']
               chair['bet'] *= 2
               chair['hand'].addCard(deck.pick())
               break;
            if action == 'A':
               chair['hand']._is_abandonned = True
               break;
            if action == 'S':
               # append 2 new hands
               for l in [0, 1]:
                  # take one of the 2 cards 
                  hand = Hand()
                  hand.addCard(chair['hand']._cards[l])
                  hand.addCard(deck.pick())
                  # bet 
                  bet = chair['bet']
                  self._pot -= bet
                  # will be played later
                  new_chair = { 'hand': hand, 'bet': bet }
                  self._chairs.append(new_chair)
               # remove splited hand 
               self._pot += chair['bet']
               self._chairs.remove(chair)
               i-=1
               break;
开发者ID:RAM128,项目名称:blackjack,代码行数:43,代码来源:player.py

示例9: getReward

# 需要导入模块: from hand import Hand [as 别名]
# 或者: from hand.Hand import addCard [as 别名]
    def getReward(self, state, action, transitionState):
        isDone, isFirst, isDoubleDown, hasAce, hardCount, dealerSoftCount = transitionState
        multiplier = 2 if isDoubleDown else 1
        if hardCount > 21:
            return -2 * multiplier

        softCount = hardCount + 10 if hasAce and hardCount <= 11 else hardCount
        if isDone:
            if isFirst and softCount == 21:
                return multiplier
            # Simulate the dealer's actions
            dealerAgent = DealerAgent()
            dealerCardValue = dealerSoftCount - 1 if dealerSoftCount != 11 else 0
            card = Card(0, dealerCardValue)
            dealerHand = Hand(1)
            dealerHand.addCard(card)
            deck = Deck(1, 4, 13)
            dealerHand.addCard(deck.take())
            while dealerAgent.getNextAction(None, dealerHand) == Actions.HIT:
                dealerHand.addCard(deck.take())
            return (
                multiplier
                if softCount > dealerHand.getSoftCount()
                else (0 if softCount == dealerHand.getSoftCount() else -multiplier)
            )
        else:
            return 0
开发者ID:melonhead901,项目名称:vegas,代码行数:29,代码来源:blackjack_markov_decision_process.py

示例10: test_str

# 需要导入模块: from hand import Hand [as 别名]
# 或者: from hand.Hand import addCard [as 别名]
    def test_str(self):
        hand = Hand(1)
        hand.addCard(Card(0, 6))
        hand.addCard(Card(2, 4))
        self.assertEqual("[7 of Clubs, 5 of Spades] with soft " \
                             "count 12 and hard count 12", str(hand))

        hand.addCard(Card(3, 10))
        self.assertEqual("[7 of Clubs, 5 of Spades, Jack of " \
                             "Hearts] with soft count 22 and " \
                             "hard count 22 (Bust)", str(hand))

        hand = Hand(1)
        hand.addCard(Card(0, 0))
        hand.addCard(Card(0, 12))
        self.assertEqual("[Ace of Clubs, King of Clubs] with " \
                             "soft count 21 and hard count 11 " \
                             "(BlackJack)", str(hand))
开发者ID:melonhead901,项目名称:vegas,代码行数:20,代码来源:hand_test.py

示例11: test_doubleDown

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

示例12: test_split

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

示例13: GameLogicTest

# 需要导入模块: from hand import Hand [as 别名]
# 或者: from hand.Hand import addCard [as 别名]
class GameLogicTest(unittest.TestCase):
    def setUp(self):
        dealerAgent = None
        playerAgents = []
        self.game = Game(dealerAgent, playerAgents)
        self.playaHand = Hand(1)
        self.dealerHand = Hand(0)

    # Ensure that player blackjack beats dealer non-blackjack
    def testPlayaBlackjackBeatsDealerNonBlackJack(self):
        self.playaHand.addCard(Card(1, 0))
        self.playaHand.addCard(Card(1, 10))
        self.dealerHand.addCard(Card(1, 4))
        self.dealerHand.addCard(Card(1, 5))
        self.dealerHand.addCard(Card(1, 10))
        self.assertGreater(self.game.determineWinner(self.playaHand, self.dealerHand), 0)

    # Ensure that player blackjack beats dealer non-blackjack
    def testPlaya17LosesDealer21(self):
        self.playaHand.addCard(Card(1, 0))
        self.playaHand.addCard(Card(1, 6))
        self.dealerHand.addCard(Card(1, 4))
        self.dealerHand.addCard(Card(1, 5))
        self.dealerHand.addCard(Card(1, 10))
        self.assertLess(self.game.determineWinner(self.playaHand, self.dealerHand), 0)

    # Ensure that player blackjack beats dealer blackjack
    def testPlayaBlackJackLosesDealerBlackjack(self):
        self.playaHand.addCard(Card(1, 0))
        self.playaHand.addCard(Card(1, 10))
        self.dealerHand.addCard(Card(1, 0))
        self.dealerHand.addCard(Card(1, 10))
        self.assertGreater(self.game.determineWinner(self.playaHand, self.dealerHand), 0)

    # Ensure that player blackjack beats dealer blackjack
    def testPlaya21LosesDealerBlackjack(self):
        self.playaHand.addCard(Card(1, 4))
        self.playaHand.addCard(Card(1, 5))
        self.playaHand.addCard(Card(1, 10))
        self.dealerHand.addCard(Card(1, 0))
        self.dealerHand.addCard(Card(1, 10))
        self.assertLess(self.game.determineWinner(self.playaHand, self.dealerHand), 0)

    # Ensure that player bust loses to dealer bust
    def testPlayaBustLosesDealerBust(self):
        self.playaHand.addCard(Card(1, 5))
        self.playaHand.addCard(Card(1, 6))
        self.playaHand.addCard(Card(1, 10))
        self.dealerHand.addCard(Card(1, 5))
        self.dealerHand.addCard(Card(1, 5))
        self.dealerHand.addCard(Card(1, 10))
        self.assertLess(self.game.determineWinner(self.playaHand, self.dealerHand), 0)
开发者ID:melonhead901,项目名称:vegas,代码行数:54,代码来源:game_test.py

示例14: test_compare

# 需要导入模块: from hand import Hand [as 别名]
# 或者: from hand.Hand import addCard [as 别名]
    def test_compare(self):
        hand1 = Hand(1)
        hand1.addCard(Card(0, 6))
        hand1.addCard(Card(0, 7))
        hand2 = Hand(1)
        hand2.addCard(Card(0, 9))
        hand2.addCard(Card(0, 3))
        self.assertGreater(hand1.compare(hand2), 0)
        self.assertLess(hand2.compare(hand1), 0)
        self.assertEqual(hand1.compare(hand1), 0)

        # BlackJack should beat a normal 21 hand.
        hand1 = Hand(1)
        hand1.addCard(Card(0, 0))
        hand1.addCard(Card(0, 11))
        self.assertTrue(hand1.isBlackJack())
        hand2 = Hand(1)
        hand2.addCard(Card(0, 3))
        hand2.addCard(Card(0, 9))
        hand2.addCard(Card(0, 6))
        self.assertEqual(21, hand2.getValidCount())
        self.assertFalse(hand2.isBlackJack())
        self.assertGreater(hand1.compare(hand2), 0)
        self.assertLess(hand2.compare(hand1), 0)
        self.assertEqual(hand1.compare(hand1), 0)
开发者ID:melonhead901,项目名称:vegas,代码行数:27,代码来源:hand_test.py

示例15: test_Soft17

# 需要导入模块: from hand import Hand [as 别名]
# 或者: from hand.Hand import addCard [as 别名]
 def test_Soft17(self):
     hand = Hand(0)
     hand.addCard(Card(1, 6))
     hand.addCard(Card(1, 0))
     dealer = DealerAgent()
     self.assertEqual(Actions.STAND, dealer.getNextAction(None, hand))
开发者ID:melonhead901,项目名称:vegas,代码行数:8,代码来源:dealer_agent_test.py


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