Пример #1
0
 def test_strategy(self):
     """If opponent has defected more than 10 percent of the time, defect."""
     P1 = axelrod.ForgivingTitForTat()
     P2 = axelrod.Player()
     P1.history = ['C', 'C', 'C', 'C']
     P2.history = ['C', 'C', 'C', 'C']
     self.assertEqual(P1.strategy(P2), 'C')
     P1.history = [
         'C',
         'C',
         'C',
         'C',
         'D',
     ]
     P2.history = [
         'C',
         'C',
         'C',
         'D',
         'C',
     ]
     self.assertEqual(P1.strategy(P2), 'C')
     P1.history = ['C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C']
     P2.history = ['C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'D']
     self.assertEqual(P1.strategy(P2), 'C')
     P1.history = ['C', 'C', 'C', 'C']
     P2.history = ['C', 'C', 'C', 'D']
     self.assertEqual(P1.strategy(P2), 'D')
Пример #2
0
 def test_initial_strategy(self):
     """
     Starts by cooperating
     """
     P1 = axelrod.ForgivingTitForTat()
     P2 = axelrod.Player()
     self.assertEqual(P1.strategy(P2), 'C')
Пример #3
0
import axelrod as axl
me = axl.Human(name='me')
players = [axl.ForgivingTitForTat(), me]
match = axl.Match(players, turns=5)
match.play() 
print(match.result)
print(match.sparklines())
print(match.scores())
print(match.final_score())
Пример #4
0
 def test_stochastic(self):
     self.assertFalse(axelrod.ForgivingTitForTat().stochastic)
Пример #5
0
 def test_representation(self):
     P1 = axelrod.ForgivingTitForTat()
     self.assertEqual(str(P1), 'Forgiving Tit For Tat')