def tscizzle_strategies(): """The list of strategies used in @tscizzle's Morality Metrics paper.""" strategies = [ axelrod.Cooperator(), axelrod.Defector(), axelrod.Eatherley(), axelrod.Champion(), axelrod.GTFT(p=0.1), axelrod.GTFT(p=0.3), axelrod.GoByMajority(soft=True), axelrod.GoByMajority(soft=False), axelrod.TitFor2Tats(), axelrod.Random(0.8), axelrod.Random(0.5), axelrod.Random(0.2), axelrod.WinStayLoseShift(), # Pavlov axelrod.TitForTat(), axelrod.TwoTitsForTat(), axelrod.Grudger(), # Friedman axelrod.Tester(), axelrod.SuspiciousTitForTat(), axelrod.Joss(0.9), axelrod.Joss(0.7), ] return strategies
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_multiple_instances(self): """Certain instances of classes of strategies will have different classifiers based on the initialisation variables""" P1 = axelrod.MemoryOnePlayer((.5, .5, .5, .5)) P2 = axelrod.MemoryOnePlayer((1, 0, 0, 1)) self.assertNotEqual(P1.classifier, P2.classifier) P1 = axelrod.Joss() P2 = axelrod.Joss(0) self.assertNotEqual(P1.classifier, P2.classifier) P1 = axelrod.GTFT(1) P2 = axelrod.GTFT(.5) self.assertNotEqual(P1.classifier, P2.classifier) P1 = axelrod.StochasticWSLS() P2 = axelrod.StochasticWSLS(0) self.assertNotEqual(P1.classifier, P2.classifier) P1 = axelrod.GoByMajority(5) P2 = axelrod.StochasticWSLS(.1) self.assertNotEqual(P1.classifier, P2.classifier)
def test_multiple_instances(self): """Certain instances of classes of strategies will have different classifiers based on the initialisation variables""" P1 = axl.MemoryOnePlayer(four_vector=(.5, .5, .5, .5)) P2 = axl.MemoryOnePlayer(four_vector=(1, 0, 0, 1)) self.assertNotEqual(P1.classifier, P2.classifier) P1 = axl.Joss() P2 = axl.Joss(p=0) self.assertNotEqual(P1.classifier, P2.classifier) P1 = axl.GTFT(p=1) P2 = axl.GTFT(p=.5) self.assertNotEqual(P1.classifier, P2.classifier) P1 = axl.StochasticWSLS() P2 = axl.StochasticWSLS(ep=0) self.assertNotEqual(P1.classifier, P2.classifier) P1 = axl.GoByMajority(memory_depth=5) P2 = axl.StochasticWSLS(ep=.1) self.assertNotEqual(P1.classifier, P2.classifier)
def main(): strategies = [ axelrod.Cooperator(), axelrod.Defector(), axelrod.Random(0.4), axelrod.Random(0.5), axelrod.Random(0.9), axelrod.Alternator(), axelrod.TitForTat(), axelrod.GTFT(), axelrod.WinStayLoseShift(), axelrod.ZDGTFT2(), axelrod.ZDExtort2(), axelrod.TitFor2Tats(), axelrod.TwoTitsForTat(), axelrod.CyclerCCD(), axelrod.CyclerCCCD(), axelrod.CyclerCCCCCD(), axelrod.HardTitForTat(), axelrod.AntiCycler(), axelrod.Grudger() ] for opponent in strategies: data_dict, test_results, estimate = infer_depth(opponent) print opponent print "-" * len(str(opponent)) print "Collected Data" print_dict(data_dict) C_count = sum(v[0] for (k, v) in data_dict.items()) D_count = sum(v[1] for (k, v) in data_dict.items()) print "C count, D count: %s, %s" % (C_count, D_count) print "\nFisher Exact Tests" print_dict(test_results) print "\nEstimated Memory One Probabilities" print_dict(estimate) print
import axelrod as axl players = [s() for s in axl.strategies if "length" not in s.classifier["makes_use_of"]] parameterized_players = [axl.Random(0.1), axl.Random(0.3), axl.Random(0.7), axl.Random(0.9), axl.GTFT(0.1), axl.GTFT(0.3), axl.GTFT(0.7), axl.GTFT(0.9)] players += parameterized_players players.sort(key=lambda p:p.__repr__())
axl.RichardHufford(), axl.Tester(), 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.seed(0) # Set a seed #players = [s() for s in axl.demo_strategies] # Create players #tournament = axl.Tournament(players) # Create a tournament #results = tournament.play() # Play the tournament #results.ranked_names #plot = axl.Plot(results) #plot.boxplot().savefig('boxplot.png') parameterized_players = [ axl.Random(0.1), axl.Random(0.3), axl.Random(0.7), axl.Random(0.9), axl.GTFT(0.1), axl.GTFT(0.3), axl.GTFT(0.7), axl.GTFT(0.9), axl.MetaWinner(team=[ axl.EvolvedHMM5, axl.EvolvedLookerUp2_2_2, axl.EvolvedFSM16, axl.EvolvedANN5, axl.PSOGambler2_2_2, axl.FoolMeOnce, axl.DoubleCrosser, axl.Gradual ]), ] players = [s() for s in axl.strategies] + parameterized_players """ A script with utility functions to get the tournament results """ from collections import namedtuple
if __name__ == "__main__": outcomes_file = "../data/outcomes.csv" output_file = "../data/fixation_validation.csv" with open(output_file, "w") as f: f.write("Repetitions,N,i,Player 1,Player 2,Theoretic,Simulated\n") player_pairs = [(axl.Defector(), axl.Defector()), (axl.Defector(), axl.Alternator()), (axl.Defector(), axl.Cooperator()), (axl.Defector(), axl.TitForTat()), (axl.Defector(), axl.WinStayLoseShift()), (axl.Random(), axl.Random()), (axl.Random(), axl.ZDExtort2()), (axl.Random(), axl.GTFT()), (axl.Random(), axl.ALLCorALLD()), (axl.Random(), axl.PSOGambler2_2_2()), (axl.Cooperator(), axl.Random()), (axl.Cooperator(), axl.ZDExtort2()), (axl.Cooperator(), axl.GTFT()), (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()),