def testCardLookup(self):
     self.assertEqual(cardLookup(Card(0)), ('A', 'h'))
     self.assertEqual(cardLookup(Card(1)), ('2', 'h'))
     self.assertEqual(cardLookup(Card(2)), ('3', 'h'))
     self.assertEqual(cardLookup(Card(3)), ('4', 'h'))
     self.assertEqual(cardLookup(Card(4)), ('5', 'h'))
     self.assertEqual(cardLookup(Card(5)), ('6', 'h'))
     self.assertEqual(cardLookup(Card(6)), ('7', 'h'))
     self.assertEqual(cardLookup(Card(7)), ('8', 'h'))
     self.assertEqual(cardLookup(Card(8)), ('9', 'h'))
     self.assertEqual(cardLookup(Card(9)), ('10', 'h'))
     self.assertEqual(cardLookup(Card(10)), ('J', 'h'))
     self.assertEqual(cardLookup(Card(11)), ('Q', 'h'))
     self.assertEqual(cardLookup(Card(12)), ('K', 'h'))
     self.assertEqual(cardLookup(Card(13)), ('A', 'c'))
     self.assertEqual(cardLookup(Card(14)), ('2', 'c'))
     self.assertEqual(cardLookup(Card(15)), ('3', 'c'))
     self.assertEqual(cardLookup(Card(16)), ('4', 'c'))
     self.assertEqual(cardLookup(Card(17)), ('5', 'c'))
     self.assertEqual(cardLookup(Card(18)), ('6', 'c'))
     self.assertEqual(cardLookup(Card(19)), ('7', 'c'))
     self.assertEqual(cardLookup(Card(20)), ('8', 'c'))
     self.assertEqual(cardLookup(Card(21)), ('9', 'c'))
     self.assertEqual(cardLookup(Card(22)), ('10', 'c'))
     self.assertEqual(cardLookup(Card(23)), ('J', 'c'))
     self.assertEqual(cardLookup(Card(24)), ('Q', 'c'))
     self.assertEqual(cardLookup(Card(25)), ('K', 'c'))
     self.assertEqual(cardLookup(Card(26)), ('A', 'd'))
     self.assertEqual(cardLookup(Card(27)), ('2', 'd'))
     self.assertEqual(cardLookup(Card(28)), ('3', 'd'))
     self.assertEqual(cardLookup(Card(29)), ('4', 'd'))
     self.assertEqual(cardLookup(Card(30)), ('5', 'd'))
     self.assertEqual(cardLookup(Card(31)), ('6', 'd'))
     self.assertEqual(cardLookup(Card(32)), ('7', 'd'))
     self.assertEqual(cardLookup(Card(33)), ('8', 'd'))
     self.assertEqual(cardLookup(Card(34)), ('9', 'd'))
     self.assertEqual(cardLookup(Card(35)), ('10', 'd'))
     self.assertEqual(cardLookup(Card(36)), ('J', 'd'))
     self.assertEqual(cardLookup(Card(37)), ('Q', 'd'))
     self.assertEqual(cardLookup(Card(38)), ('K', 'd'))
     self.assertEqual(cardLookup(Card(39)), ('A', 's'))
     self.assertEqual(cardLookup(Card(40)), ('2', 's'))
     self.assertEqual(cardLookup(Card(41)), ('3', 's'))
     self.assertEqual(cardLookup(Card(42)), ('4', 's'))
     self.assertEqual(cardLookup(Card(43)), ('5', 's'))
     self.assertEqual(cardLookup(Card(44)), ('6', 's'))
     self.assertEqual(cardLookup(Card(45)), ('7', 's'))
     self.assertEqual(cardLookup(Card(46)), ('8', 's'))
     self.assertEqual(cardLookup(Card(47)), ('9', 's'))
     self.assertEqual(cardLookup(Card(48)), ('10', 's'))
     self.assertEqual(cardLookup(Card(49)), ('J', 's'))
     self.assertEqual(cardLookup(Card(50)), ('Q', 's'))
     self.assertEqual(cardLookup(Card(51)), ('K', 's'))
Exemple #2
0
 def __str__(self):
     return ("I" if self.insurance else "") + " ".join(("%2s%s" % cardLookup(c) for c in self.cards))
def theBook(hand, dealerFV, count):
    """
    Play a hand by 'the book' for a 6 deck, H17, double after split game
    """
    # TODO: Implement count adjustments
    # TODO: Make a version that can take into account all of the rules automatically
    handSum = hand.minHandSum()

    cards = hand.cards
    firstFV = cards[0].faceValue

    # hasTwoCards is my check to see if doubling down is available.
    # Should be replaced by a canDouble function when unlimited debt is removed
    hasTwoCards = len(hand.cards) == 2
    if hasTwoCards and (cardLookup(cards[0])[0] == cardLookup(cards[1])[0]):
        # Pairs
        if firstFV == 1:  # ACE
            return Action.Split
        elif firstFV == 10:
            return Action.Stand
        elif firstFV == 9:
            if (dealerFV == 7) or (dealerFV == 10) or (dealerFV == 1):
                return Action.Stand
            else:
                return Action.Split
        elif firstFV == 8:
            return Action.Split
        elif firstFV >= 6:
            if 1 < dealerFV <= firstFV:
                return Action.Split
            else:
                return Action.Hit
        elif firstFV == 5:
            if 2 <= dealerFV <= 9:
                return Action.Double
            else:
                return Action.Hit
        elif firstFV == 4:
            if (dealerFV == 5) or (dealerFV == 6):
                return Action.Split
            else:
                return Action.Hit
        else:
            if 1 < dealerFV <= 7:
                return Action.Split
            else:
                return Action.Hit
    elif hand.isSoft(handSum):
        # Soft Hands
        if handSum >= 10:
            return Action.Stand
        elif handSum == 9:
            if hasTwoCards and dealerFV == 6:
                return Action.Double
            else:
                return Action.Stand
        elif handSum == 8:
            if hasTwoCards and (2 <= dealerFV <= 6):
                return Action.Double
            elif dealerFV >= 9:
                return Action.Hit
            else:
                return Action.Stand
        elif handSum == 7:
            if hasTwoCards and (3 <= dealerFV <= 6):
                return Action.Double
            else:
                return Action.Hit
        elif handSum == 5 or handSum == 6:
            if hasTwoCards and (4 <= dealerFV <= 6):
                return Action.Double
            else:
                return Action.Hit
        elif handSum == 3 or handSum == 4:
            if hasTwoCards and (5 <= dealerFV <= 6):
                return Action.Double
            else:
                return Action.Hit
        else:
            print "ERROR"
            return Action.Stand  # Shouldn't get here
    # Normal Hands
    elif handSum >= 17:
        return Action.Stand
    elif handSum >= 13:
        if dealerFV >= 7:
            return Action.Hit
        else:
            return Action.Stand
    elif handSum == 12:
        if dealerFV <= 3 or dealerFV >= 7:
            return Action.Hit
        else:
            return Action.Stand
    elif handSum == 11:
        if hasTwoCards:
            return Action.Double
        else:
            return Action.Hit
    elif handSum == 10:
        if hasTwoCards and 1 < dealerFV < 10:
            return Action.Double
        else:
            return Action.Hit
    elif handSum == 9:
        if hasTwoCards and 3 <= dealerFV <= 6:
            return Action.Double
        else:
            return Action.Hit
    else:
        # handSum <= 8 is hit
        return Action.Hit
 def __str__(self):
     return "W:0 " + "\n".join(" ".join(("%2s%s" % cardLookup(c) for c in h.cards)) for h in self.hands)