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
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))
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
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))