def test_rounds(self): self.versus_test( axl.FoolMeOnce(), axl.Bully(), [C, C, D, D, D, D], [D, D, D, C, C, C], )
def test_rounds(self): self.versus_test( axl.TitFor2Tats(), axl.Bully(), [C, C, D, D, C, C, C, D], [D, D, D, C, C, D, D, D], )
def test_rounds(self): self.versus_test( axl.WinStayLoseShift(), axl.Bully(), [C, D, C, C, D], [D, D, C, D, D], )
def test_rounds(self): self.versus_test( axl.ZDGTFT2(), axl.Bully(), [C, D, D, C, C, D], [D, D, C, C, D, D], seed=2, )
def playWithFixed(TD, DP, MC): C = axl.Cooperator() D = axl.Defector() TFT = axl.TitForTat() BUL = axl.Bully() PAV = Pavlov() APAV = axl.APavlov2011() for learner in [TD,DP,MC]: players = [C, D, TFT, BUL, PAV, APAV, learner] tournament = axl.Tournament(players, turns=10000) results = tournament.play() title = learner.name + " VS Fixed Strategy Players" plot = axl.Plot(results) p = plot.boxplot(title) p.savefig(learner.name)
def test_rounds(self): self.versus_test(axelrod.ZDGTFT2(), axelrod.Bully(), [C, D, D, C, C, D], [D, D, C, C, D, D], random_seed=2)
def test_rounds(self): self.versus_test(axelrod.TitForTat(), axelrod.Bully(), [C, D, D, C, C, D], [D, D, C, C, D, D])
def test_strategy(self): opponent = axelrod.Bully() actions = [(C, D), (D, D), (D, C), (C, C), (C, D), (D, D), (D, C), (C, C)] expected_attrs = { "num_turns_after_good_defection": 0, "one_turn_after_good_defection_ratio": 5, "two_turns_after_good_defection_ratio": 0, "one_turn_after_good_defection_ratio_count": 1, "two_turns_after_good_defection_ratio_count": 1 } self.versus_test(opponent, expected_actions=actions, attrs=expected_attrs) # Tests whether TitForTat is played given score is below 1.75 opponent = axelrod.Defector() actions = [(C, D)] + [(D, D)] * 20 expected_attrs = { "num_turns_after_good_defection": 0, "one_turn_after_good_defection_ratio": 5, "two_turns_after_good_defection_ratio": 0, "one_turn_after_good_defection_ratio_count": 1, "two_turns_after_good_defection_ratio_count": 1 } self.versus_test(opponent, expected_actions=actions, attrs=expected_attrs) opponent = axelrod.MockPlayer([C] * 2 + [D] * 8 + [C] * 4) actions = [(C, C), (C, C)] + [(C, D)] + [(D, D)] * 7 + [(D, C)] + [(C, C)] * 3 expected_attrs = { "num_turns_after_good_defection": 0, "one_turn_after_good_defection_ratio": 5, "two_turns_after_good_defection_ratio": 0, "one_turn_after_good_defection_ratio_count": 1, "two_turns_after_good_defection_ratio_count": 1 } self.versus_test(opponent, expected_actions=actions, attrs=expected_attrs) # If score is between 1.75 and 2.25, may cooperate or defect opponent = axelrod.MockPlayer(actions=[D] * 3 + [C] * 4 + [D] * 2) actions = [(C, D)] + [(D, D)] * 2 + [(D, C)] + [(C, C)] * 3 + [(C, D)] actions += ([(C, D)]) # <-- Random expected_attrs = { "num_turns_after_good_defection": 0, "one_turn_after_good_defection_ratio": 5, "two_turns_after_good_defection_ratio": 0, "one_turn_after_good_defection_ratio_count": 1, "two_turns_after_good_defection_ratio_count": 1 } self.versus_test(opponent, expected_actions=actions, seed=0, attrs=expected_attrs) opponent = axelrod.MockPlayer(actions=[D] * 3 + [C] * 4 + [D] * 2) actions = [(C, D)] + [(D, D)] * 2 + [(D, C)] + [(C, C)] * 3 + [(C, D)] actions += ([(D, D)]) # <-- Random expected_attrs = { "num_turns_after_good_defection": 0, "one_turn_after_good_defection_ratio": 5, "two_turns_after_good_defection_ratio": 0, "one_turn_after_good_defection_ratio_count": 1, "two_turns_after_good_defection_ratio_count": 1 } self.versus_test(opponent, expected_actions=actions, seed=17, attrs=expected_attrs) """If score is greater than 2.25 either cooperate or defect, if turn number <= 5; cooperate""" opponent = axelrod.MockPlayer(actions=[C] * 5) actions = [(C, C)] * 5 expected_attrs = { "num_turns_after_good_defection": 0, "one_turn_after_good_defection_ratio": 5, "two_turns_after_good_defection_ratio": 0, "one_turn_after_good_defection_ratio_count": 1, "two_turns_after_good_defection_ratio_count": 1 } self.versus_test(opponent, expected_actions=actions, seed=1, attrs=expected_attrs) opponent = axelrod.MockPlayer(actions=[C] * 5) actions = [(C, C)] * 4 + [(D, C)] expected_attrs = { "num_turns_after_good_defection": 1, "one_turn_after_good_defection_ratio": 5, "two_turns_after_good_defection_ratio": 0, "one_turn_after_good_defection_ratio_count": 1, "two_turns_after_good_defection_ratio_count": 1 } self.versus_test(opponent, expected_actions=actions, seed=89, attrs=expected_attrs) """ Given score per turn is greater than 2.25, Tranquilizer will never defect twice in a row""" opponent = axelrod.MockPlayer(actions=[C] * 6) actions = [(C, C)] * 4 + [(D, C), (C, C)] expected_attrs = { "num_turns_after_good_defection": 2, "one_turn_after_good_defection_ratio": 5, "two_turns_after_good_defection_ratio": 0, "one_turn_after_good_defection_ratio_count": 2, "two_turns_after_good_defection_ratio_count": 1 } self.versus_test(opponent, expected_actions=actions, seed=89, attrs=expected_attrs) # Tests cooperation after update_state opponent = axelrod.MockPlayer(actions=[C] * 5) actions = [(C, C)] * 4 + [(D, C)] + [(C, C)] expected_attrs = { "num_turns_after_good_defection": 2, "one_turn_after_good_defection_ratio": 5, "two_turns_after_good_defection_ratio": 0, "one_turn_after_good_defection_ratio_count": 2, "two_turns_after_good_defection_ratio_count": 1 } self.versus_test(opponent, expected_actions=actions, seed=89, attrs=expected_attrs) # Ensures FD1 values are calculated opponent = axelrod.MockPlayer(actions=[C] * 6) actions = [(C, C)] * 4 + [(D, C), (C, C)] expected_attrs = { "num_turns_after_good_defection": 2, "one_turn_after_good_defection_ratio": 5, "two_turns_after_good_defection_ratio": 0, "one_turn_after_good_defection_ratio_count": 2, "two_turns_after_good_defection_ratio_count": 1 } self.versus_test(opponent, expected_actions=actions, seed=89, attrs=expected_attrs) # Ensures FD2 values are calculated opponent = axelrod.MockPlayer(actions=[C] * 6) actions = [(C, C)] * 4 + [(D, C)] + [(C, C)] * 2 expected_attrs = { "num_turns_after_good_defection": 0, "one_turn_after_good_defection_ratio": 5, "two_turns_after_good_defection_ratio": 1.5, "one_turn_after_good_defection_ratio_count": 2, "two_turns_after_good_defection_ratio_count": 2 } self.versus_test(opponent, expected_actions=actions, seed=89, attrs=expected_attrs) # Ensures scores are being counted opponent = axelrod.Defector() actions = [(C, D)] + [(D, D)] * 19 expected_attrs = { "num_turns_after_good_defection": 0, "one_turn_after_good_defection_ratio": 5, "two_turns_after_good_defection_ratio": 0, "one_turn_after_good_defection_ratio_count": 1, "two_turns_after_good_defection_ratio_count": 1 } self.versus_test(opponent, expected_actions=actions, attrs=expected_attrs)
import axelrod as axl import csv import json import jsonpickle # strats = [axl.Alternator(), axl.AntiTitForTat(), axl.Bully(), axl.Cooperator(),axl.Defector(), axl.SuspiciousTitForTat(), axl.TitForTat(), axl.Grudger(),axl.WinShiftLoseStay(), axl.WinStayLoseShift()] # strats1 = [axl.Alternator(), axl.AntiTitForTat(), axl.Bully(), axl.Cooperator(),axl.Defector(), axl.SuspiciousTitForTat(), axl.TitForTat(), axl.Grudger(),axl.WinShiftLoseStay(), axl.WinStayLoseShift()] strats1 = [ axl.Cooperator(), axl.Defector(), axl.Grudger(), axl.TitForTat(), axl.WinStayLoseShift(), axl.StochasticCooperator(), axl.Bully(), axl.Grumpy(), axl.CollectiveStrategy(), axl.APavlov2011() ] strats2 = [ axl.Cooperator(), axl.Defector(), axl.Grudger(), axl.TitForTat(), axl.WinStayLoseShift(), axl.StochasticCooperator(), axl.Bully(), axl.Grumpy(), axl.CollectiveStrategy(), axl.APavlov2011()