Exemple #1
0
 def test_strategy(self):
     """Tests that it chooses the best strategy."""
     random.seed(9)
     p1 = axelrod.CautiousQLearner()
     p1.state = 'CCDC'
     p1.Qs = {'': {C: 0, D: 0}, 'CCDC': {C: 2, D: 6}}
     p2 = axelrod.Cooperator()
     test_responses(self, p1, p2, [], [], [C, C, C, C, C, C, C])
Exemple #2
0
 def test_prev_state_updates(self):
     """Test that the q and v values update."""
     random.seed(5)
     p1 = axelrod.CautiousQLearner()
     p2 = axelrod.Cooperator()
     simulate_play(p1, p2)
     self.assertEqual(p1.prev_state, '0.0')
     simulate_play(p1, p2)
     self.assertEqual(p1.prev_state, 'C1.0')
Exemple #3
0
 def test_reset_method(self):
     """Tests the reset method."""
     P1 = axelrod.CautiousQLearner()
     P1.Qs = {'': {C: 0, D: -0.9}, '0.0': {C: 0, D: 0}}
     P1.Vs = {'': 0, '0.0': 0}
     P1.history = [C, D, D, D]
     P1.prev_state = C
     P1.reset()
     self.assertEqual(P1.prev_state, '')
     self.assertEqual(P1.Vs, {'': 0})
     self.assertEqual(P1.Qs, {'': {C: 0, D: 0}})
Exemple #4
0
 def test_reset_method(self):
     """Tests the reset method."""
     P1 = axelrod.CautiousQLearner()
     P1.Qs = {'': {'C': 0, 'D': -0.9}, '0.0': {'C': 0, 'D': 0}}
     P1.Vs = {'': 0, '0.0': 0}
     P1.history = ['C', 'D', 'D', 'D']
     P1.prev_state = 'C'
     P1.reset()
     self.assertEqual(P1.prev_state, '')
     self.assertEqual(P1.history, [])
     self.assertEqual(P1.Vs, {'': 0})
     self.assertEqual(P1.Qs, {'': {'C': 0, 'D': 0}})
Exemple #5
0
 def test_vs_update(self):
     """Test that the q and v values update."""
     random.seed(5)
     p1 = axelrod.CautiousQLearner()
     p2 = axelrod.Cooperator()
     simulate_play(p1, p2)
     self.assertEqual(p1.Vs, {'': 0.1, '0.0': 0})
     simulate_play(p1, p2)
     self.assertEqual(p1.Vs, {
         '': 0.1,
         '0.0': 0.30000000000000004,
         'C1.0': 0
     })
Exemple #6
0
 def test_strategy(self):
     """Tests that it chooses the best strategy."""
     random.seed(9)
     p1 = axelrod.CautiousQLearner()
     p1.state = 'CCDC'
     p1.Qs = {'': {'C': 0, 'D': 0}, 'CCDC': {'C': 2, 'D': 6}}
     p2 = axelrod.Cooperator()
     self.assertEqual(p1.strategy(p2), 'C')
     self.assertEqual(p1.strategy(p2), 'D')
     self.assertEqual(p1.strategy(p2), 'D')
     self.assertEqual(p1.strategy(p2), 'D')
     self.assertEqual(p1.strategy(p2), 'D')
     self.assertEqual(p1.strategy(p2), 'D')
Exemple #7
0
 def test_prev_state_updates(self):
     """Test that the q and v values update."""
     random.seed(5)
     p1 = axelrod.CautiousQLearner()
     p2 = axelrod.Cooperator()
     play_1, play_2 = p1.strategy(p2), p2.strategy(p1)
     p1.history.append(play_1)
     p2.history.append(play_2)
     self.assertEqual(p1.prev_state, '0.0')
     play_1, play_2 = p1.strategy(p2), p2.strategy(p1)
     p1.history.append(play_1)
     p2.history.append(play_2)
     self.assertEqual(p1.prev_state, 'C1.0')
Exemple #8
0
 def test_vs_update(self):
     """
     Test that the q and v values update
     """
     random.seed(5)
     p1 = axelrod.CautiousQLearner()
     p2 = axelrod.Cooperator()
     play_1, play_2 = p1.strategy(p2), p2.strategy(p1)
     p1.history.append(play_1)
     p2.history.append(play_2)
     self.assertEqual(p1.Vs, {'': 0, '0.0': 0})
     play_1, play_2 = p1.strategy(p2), p2.strategy(p1)
     p1.history.append(play_1)
     p2.history.append(play_2)
     self.assertEqual(p1.Vs, {'': 0, '0.0': 0.1, 'C1.0': 0})
Exemple #9
0
 def test_stochastic(self):
     self.assertTrue(axelrod.CautiousQLearner().stochastic)
Exemple #10
0
 def test_representation(self):
     """
     Tests string representation of class
     """
     P1 = axelrod.CautiousQLearner()
     self.assertEqual(str(P1), 'Cautious QLearner')