def test_strategy(self): self.first_play_test(C) P1 = axelrod.Calculator() P1.history = [C] * 20 P2 = axelrod.Player() P2.history = [C, D] * 10 # Defects on cycle detection self.assertEqual(D, P1.strategy(P2)) # Test non-cycle response history = [C, C, D, C, C, D, C, C, C, D, C, C, C, C, D, C, C, C, C, C] P2.history = history self.assertEqual(C, P1.strategy(P2)) # Test post 20 rounds responses self.responses_test([D], [C] * 21, [C] * 21) history = [ C, C, D, C, C, D, C, C, C, D, C, C, C, C, D, C, C, C, C, C, D ] self.responses_test([D], [C] * 21, history) history = [ C, C, D, C, C, D, C, C, C, D, C, C, C, C, D, C, C, C, C, C, D, C ] self.responses_test([C], [C] * 22, history)
def test_default_single_opponent_e2e(self): temp_file = tempfile.NamedTemporaryFile() # we will set the objective to be cycler_objective = axl_dojo.prepare_objective(name="score", turns=10, repetitions=1) # Lets use an opponent_list of just one: opponent_list = [axl.TitForTat(), axl.Calculator()] cycler = axl.EvolvableCycler # params to pass through cycler_kwargs = {"cycle_length": 10} # assert file is empty to start self.assertEqual(temp_file.readline(), b'') # note that .readline() reads bytes hence b'' population = axl_dojo.Population(player_class=cycler, params_kwargs=cycler_kwargs, size=20, objective=cycler_objective, output_filename=temp_file.name, opponents=opponent_list) generations = 5 population.run(generations, print_output=False) # assert the output file exists and is not empty self.assertTrue(os.path.exists(temp_file.name)) self.assertNotEqual(temp_file.readline(), b'') # note that .readline() reads bytes hence b'' # close the temp file temp_file.close()
def sp_strategies(): """The list of strategies used in Stewart and Plotkin's 2012 tournament.""" strategies = [ axelrod.Cooperator(), # ALLC axelrod.Defector(), # ALLD axelrod.GTFT(), axelrod.GoByMajority(soft=False), # HARD_MAJO #axelrod.GoByMajority(soft=True), # SOFT_MAJO axelrod.TitFor2Tats(), # TFT2 axelrod.HardTitFor2Tats(), # HARD_TFT2 axelrod.Random(), # RANDOM axelrod.WinStayLoseShift(), # WSLS axelrod.TitForTat(), axelrod.HardTitForTat(), # HARD_TFT axelrod.Grudger(), # GRIM axelrod.Joss(), # HARD_JOSS axelrod.ZDGTFT2(), axelrod.ZDExtort2(), axelrod.Prober(), axelrod.Prober2(), axelrod.Prober3(), axelrod.HardProber(), axelrod.Calculator(), ] return strategies
def test_cycle_detection(self): P1 = axelrod.Calculator() P1.history = [C] * 20 P2 = axelrod.Player() P2.history = [C] * 20 self.assertTrue(P1.detect_cycle(P2.history)) P2.history = [D] * 20 self.assertTrue(P1.detect_cycle(P2.history)) P2.history = [C, D] * 10 self.assertTrue(P1.detect_cycle(P2.history)) P2.history = [C, D, D, C] * 5 self.assertTrue(P1.detect_cycle(P2.history))
def test_strategy(self): self.first_play_test(C) P1 = axelrod.Calculator() P1.history = [C] * 20 P2 = axelrod.Player() P2.history = [C, D] * 10 # Defects on cycle detection self.assertEqual('D', P1.strategy(P2)) # Test non-cycle response history = [C, C, D, C, C, D, C, C, C, D, C, C, C, C, D, C, C, C, C, C] P2.history = history self.assertFalse(P1.detect_cycle(P2.history)) self.assertEqual('C', P1.strategy(P2))
axl.Tranquilizer(), axl.Weiner(), axl.White(), axl.WmAdams(), axl.Yamachi() ] # The list of agents playing in the Stewart-Plotkin's tournament. steward_plotkin_players = [ axl.ZDExtort2(), axl.HardGoByMajority(), axl.HardTitForTat(), axl.HardTitFor2Tats(), axl.GTFT(), axl.ZDGTFT2(), axl.Calculator(), axl.Prober(), axl.Prober2(), axl.Prober3(), axl.HardProber(), axl.NaiveProber() ] # The list of agents playing in the Case's simulation case_players = [ axl.Cooperator(), axl.Defector(), axl.TitForTat(), axl.Grudger(), axl.Detective(), axl.TitFor2Tats(),
(axl.Cooperator(), axl.ALLCorALLD()), (axl.Cooperator(), axl.PSOGambler2_2_2()), (axl.Alternator(), axl.Random()), (axl.Alternator(), axl.ZDExtort2()), (axl.Alternator(), axl.GTFT()), (axl.Alternator(), axl.ALLCorALLD()), (axl.Alternator(), axl.PSOGambler2_2_2()), (axl.ALLCorALLD(), axl.Cooperator()), (axl.ALLCorALLD(), axl.Defector()), (axl.ALLCorALLD(), axl.TitForTat()), (axl.Alternator(), axl.Cooperator()), (axl.Alternator(), axl.Defector()), (axl.Alternator(), axl.TitForTat()), (axl.Alternator(), axl.WinStayLoseShift()), (axl.Defector(), axl.WinStayLoseShift()), (axl.Calculator(), axl.ALLCorALLD()), (axl.Calculator(), axl.ArrogantQLearner()), (axl.Calculator(), axl.Random()), (axl.Cooperator(), axl.TitForTat()), (axl.Defector(), axl.Cooperator()), (axl.Defector(), axl.TitForTat()), (axl.Random(), axl.Cooperator()), (axl.Random(), axl.Defector()), (axl.Random(), axl.TitForTat()), (axl.WinStayLoseShift(), axl.TitForTat())] max_N = 20 repetitions = 1000 df = pd.read_csv( outcomes_file,