Ejemplo n.º 1
0
 def test_constant_fitness_case(self):
     # Scores between an Alternator and Defector will be: (1,  6)
     axelrod.seed(0)
     players = (axelrod.Alternator(), axelrod.Alternator(),
                axelrod.Defector(), axelrod.Defector())
     mp = MoranProcess(players, turns=2)
     winners = []
     for _ in range(100):
         mp.play()
         winners.append(mp.winning_strategy_name)
         mp.reset()
     winners = Counter(winners)
     self.assertEqual(winners["Defector"], 88)
Ejemplo n.º 2
0
 def test_reset(self):
     p1, p2 = axl.Cooperator(), axl.Defector()
     mp = MoranProcess((p1, p2), seed=45)
     mp.play()
     self.assertEqual(len(mp), 2)
     self.assertEqual(len(mp.score_history), 1)
     mp.reset()
     self.assertEqual(len(mp), 1)
     self.assertEqual(mp.winning_strategy_name, None)
     self.assertEqual(mp.score_history, [])
     # Check that players reset
     for player, initial_player in zip(mp.players, mp.initial_players):
         self.assertEqual(str(player), str(initial_player))
Ejemplo n.º 3
0
 def test_standard_fixation(self):
     """Test a traditional Moran process with a MockMatch."""
     axelrod.seed(0)
     players = (axelrod.Cooperator(), axelrod.Cooperator(),
                axelrod.Defector(), axelrod.Defector())
     mp = MoranProcess(players, match_class=MockMatch)
     winners = []
     for i in range(100):
         mp.play()
         winner = mp.winning_strategy_name
         winners.append(winner)
         mp.reset()
     winners = Counter(winners)
     self.assertEqual(winners["Cooperator"], 82)
Ejemplo n.º 4
0
 def test_reset(self):
     p1, p2 = axelrod.Cooperator(), axelrod.Defector()
     random.seed(8)
     mp = MoranProcess((p1, p2))
     mp.play()
     self.assertEqual(len(mp), 4)
     self.assertEqual(len(mp.score_history), 3)
     mp.reset()
     self.assertEqual(len(mp), 1)
     self.assertEqual(mp.winning_strategy_name, None)
     self.assertEqual(mp.score_history, [])
     # Check that players reset
     for player, intial_player in zip(mp.players, mp.initial_players):
         self.assertEqual(str(player), str(intial_player))
Ejemplo n.º 5
0
 def test_constant_fitness_case(self):
     # Scores between an Alternator and Defector will be: (1,  6)
     axelrod.seed(0)
     players = (
         axelrod.Alternator(),
         axelrod.Alternator(),
         axelrod.Defector(),
         axelrod.Defector(),
     )
     mp = MoranProcess(players, turns=2)
     winners = []
     for _ in range(100):
         mp.play()
         winners.append(mp.winning_strategy_name)
         mp.reset()
     winners = Counter(winners)
     self.assertEqual(winners["Defector"], 88)