Beispiel #1
0
    def splitPlayableHand(self):
        """
        Split the hand corresponding to player hand idx
        Create two hands, each with one of the cards and one newly dealt one and add them to playerHands list
        returns: nothing
        """
        # Get the hand to split and remove it from the list
        handBeingSplit = self.playerHands.pop(self.playerHandIdx)

        if not handBeingSplit.isDoubles():
            raiseErrorAtLoc()

        # Create a new hand, give it the second card from original and remove from original
        newHand = Hand()
        newHand.receiveCard(handBeingSplit.hand.pop(1))

        # Deal each one a new card
        handBeingSplit.receiveCard(self.dealCard())
        newHand.receiveCard(self.dealCard())

        # Insert new hands back into the list where original was
        self.playerHands.insert(self.playerHandIdx, handBeingSplit)
        self.playerHands.insert(self.playerHandIdx + 1, newHand)

        # Apply the bet to new hand
        self.bets.insert(self.playerHandIdx + 1, self.player.getBetAmt())
Beispiel #2
0
def checkHand():
    status = []
    hand = Hand()

    # empyt starting hand
    status.append(hand.getNumCards() == 0)
    status.append(hand.getHandValue() == 0)

    # correctly appends card
    card1 = Card(Face.NINE, Suit.CLUBS)
    hand.receiveCard(card1)
    status.append(hand.getNumCards() == 1)
    status.append(hand.getHandValue() == 9)

    # checks for correct isDoubles call
    hand.receiveCard(card1)
    status.append(hand.isDoubles())
    hand.hand[1] = Card(Face.ACE, Suit.DIAMONDS)
    status.append(not hand.isDoubles())

    # Check for blackjack
    status.append(not hand.isBlackjack())
    hand.hand[0] = Card(Face.KING, Suit.CLUBS)
    status.append(hand.isBlackjack())

    # checks for soft and hard hands
    status.append(hand.isHard())
    status.append(not hand.isSoft())
    hand.receiveCard(Card(Face.QUEEN, Suit.HEARTS))
    status.append(hand.isHard())
    status.append(not hand.isSoft())

    # checks for bust
    status.append(not hand.isBust())
    hand.receiveCard(Card(Face.SEVEN, Suit.SPADES))
    status.append(hand.isBust())

    # checks for 4 aces corner case
    hand.hand[0] = Card(Face.ACE, Suit.DIAMONDS)
    hand.hand[2] = Card(Face.ACE, Suit.DIAMONDS)
    hand.hand[3] = Card(Face.ACE, Suit.DIAMONDS)
    status.append(hand.getHandValue() == 14)

    return status
Beispiel #3
0
def checkActions():
    game = Game(False, 'optimal', 100, 100, 0)
    gamestate = game.gameState
    hand = Hand()
    status = []

    # tests a playable hand (9,4)
    hand.receiveCard(Card(Face.NINE, Suit.CLUBS))
    hand.receiveCard(Card(Face.FOUR, Suit.CLUBS))
    gamestate.playerHands = [hand]
    actions = gamestate.player.getValidActions(gamestate)
    status.append(actions == ['HIT', 'STAND', 'DOUBLE DOWN'])

    # tests a doubles hand hand (9,9)
    hand.hand[1] = (Card(Face.NINE, Suit.HEARTS))
    gamestate.playerHands = [hand]
    actions = gamestate.player.getValidActions(gamestate)
    status.append(actions == ['HIT', 'STAND', 'DOUBLE DOWN', 'SPLIT'])

    # tests blackjack (Ace, King)
    hand.hand[0] = (Card(Face.ACE, Suit.HEARTS))
    hand.hand[1] = (Card(Face.KING, Suit.HEARTS))
    gamestate.playerHands = [hand]
    actions = gamestate.player.getValidActions(gamestate)
    status.append(actions == ['STAND'])

    # tests a soft hand hand (Ace,King, 3)
    hand.receiveCard(Card(Face.THREE, Suit.CLUBS))
    gamestate.playerHands = [hand]
    actions = gamestate.player.getValidActions(gamestate)
    status.append(actions == ['HIT','STAND'])

    # tests a bust hand (Ace, King, 3, 9)
    hand.receiveCard(Card(Face.NINE, Suit.CLUBS))
    gamestate.playerHands = [hand]
    actions = gamestate.player.getValidActions(gamestate)
    status.append(actions == ['STAND'])

    return status