def setUp(self):
     # An agent every test can use
     self.agent = CountLearningAgent()
Ejemplo n.º 2
0
 def stateToFeatures(self, gameState, playerHand):
     aceCount = gameState.getDeck().aceCount
     return (
         CountLearningAgent.stateToFeatures(self, gameState, playerHand) +
         (aceCount, ))
class CountLearningAgentTest(unittest.TestCase):


    def setUp(self):
        # An agent every test can use
        self.agent = CountLearningAgent()

    def testNoCardNoCount(self):
        self.assertEqual(0, self.agent.count)        
        
    def testNoValCardsNoCount(self):
        hand = Hand(1)
        hand.addCard(Card(1, 6))        
        hand.addCard(Card(1, 6))
        self.agent.updateCount(hand)
        self.assertEqual(0, self.agent.count)
        
    def testOffsettingCardsNoCount(self):
        hand = Hand(1)
        hand.addCard(Card(1, 0))        
        hand.addCard(Card(1, 2))
        self.agent.updateCount(hand)
        self.assertEqual(0, self.agent.count)        
        
    def testEntireDeckNoCount(self):
        # The entire deck should be neutral
        deck = Deck(1, 4, 13)
        dealerHand = Hand(1)
        for _ in range(13):
            dealerHand.addCard(deck.take())
        playerHandMap = {}
        for i in range(3):
            hand = Hand(1)
            for _ in range(13):
                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)
        
    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)
Ejemplo n.º 4
0
    iterations = args.iterations
    if realRounds <= 0:
        print "Number of real rounds must be > 0 but was {0}".format(realRounds)
        sys.exit(1)

    if randomSeed:
        random.seed(randomSeed)

    playerAgentStrings = args.playerAgents

    playerAgents = []
    for playerAgentString in playerAgentStrings:
        if playerAgentString == "QLearningAgent":
            playerAgents.append(QLearningAgent(args.alpha, args.discount, args.epsilon))
        elif playerAgentString == "CountLearningAgent":
            playerAgents.append(CountLearningAgent())            
        elif playerAgentString == "AceCountLearningAgent":
            playerAgents.append(AceCountLearningAgent())
        elif playerAgentString == "ReflexAgent":
            playerAgents.append(ReflexAgent())
        elif playerAgentString == "StandingAgent":
            playerAgents.append(StandingAgent())
        elif playerAgentString == "NoBustAgent":
            playerAgents.append(NoBustAgent())
        elif playerAgentString == "HumanAgent":
            playerAgents.append(HumanAgent())
        elif playerAgentString == "ValueIterationAgent":
            if not iterations:
                print "Number of iterations must be specified with ValueIterationAgent"
                sys.exit(1)
            playerAgents.append(ValueIterationAgent(iterations))
Ejemplo n.º 5
0
 def stateToFeatures(self, gameState, playerHand):
     aceCount = gameState.getDeck().aceCount
     return (CountLearningAgent.stateToFeatures(self, gameState, playerHand) + (aceCount,))
 def setUp(self):
     # An agent every test can use
     self.agent = CountLearningAgent()
class CountLearningAgentTest(unittest.TestCase):
    def setUp(self):
        # An agent every test can use
        self.agent = CountLearningAgent()

    def testNoCardNoCount(self):
        self.assertEqual(0, self.agent.count)

    def testNoValCardsNoCount(self):
        hand = Hand(1)
        hand.addCard(Card(1, 6))
        hand.addCard(Card(1, 6))
        self.agent.updateCount(hand)
        self.assertEqual(0, self.agent.count)

    def testOffsettingCardsNoCount(self):
        hand = Hand(1)
        hand.addCard(Card(1, 0))
        hand.addCard(Card(1, 2))
        self.agent.updateCount(hand)
        self.assertEqual(0, self.agent.count)

    def testEntireDeckNoCount(self):
        # The entire deck should be neutral
        deck = Deck(1, 4, 13)
        dealerHand = Hand(1)
        for _ in range(13):
            dealerHand.addCard(deck.take())
        playerHandMap = {}
        for i in range(3):
            hand = Hand(1)
            for _ in range(13):
                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)

    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)