예제 #1
0
 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 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
예제 #4
0
 def test_initial_strategy(self):
     """
     Starts by cooperating
     """
     P1 = axelrod.TitFor2Tats()
     P2 = axelrod.Player()
     self.assertEqual(P1.strategy(P2), 'C')
예제 #5
0
 def test_failures(self):
     """
     The memory test function returns False in this case as the incorrect mem
     length is used
     """
     player = axl.TitFor2Tats()
     opponent = axl.Defector()
     self.assertFalse(test_memory(player, opponent, memory_length=1))
예제 #6
0
 def test_passes(self):
     """
     The memory test function returns True in this case as the correct mem
     length is used
     """
     player = axl.TitFor2Tats()
     opponent = axl.Defector()
     self.assertTrue(test_memory(player, opponent, memory_length=2))
예제 #7
0
 def test_effect_of_strategy(self):
     """Will defect only when last two turns of opponent were defections."""
     P1 = axelrod.TitFor2Tats()
     P2 = axelrod.Player()
     P1.history = ['C', 'C', 'C']
     P2.history = ['C', 'D', 'D']
     self.assertEqual(P1.strategy(P2), 'D')
     P1.history = ['C', 'C', 'D', 'D']
     P2.history = ['D', 'D', 'D', 'C']
     self.assertEqual(P1.strategy(P2), 'C')
예제 #8
0
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
예제 #9
0
selfScore = []
oppScore = []
selfAvgList = []
oppAvgList = []
avgScore = []
oppAvgScore = []

evolveCode = [0, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 1, 1, 1, 1, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0,\
 0, 1, 1, 1, 1, 1, 1, 1, 0, 1, 0, 1, 1, 1, 0, 1, 0, 0, 0, 1, 0, 0, 1, 1, 1, 0, 1, 0, 0]     # For final experiments

singEvolveCode = [0, 1, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 0, 0, 1, 0, 0, 0, 0, 1, 1, 1, 1, 0, 1, 0, 0, 0, 0, 1,\
 0, 1, 0, 1, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 0, 1, 0, 1, 1, 1, 0, 1, 0, 0, 1, 1, 0, 0, 1, 1, 1, 0, 1, 0, 0]

# strategies = [axelrod.Cooperator(), axelrod.Defector()]
# strategies = [axelrod.TitFor2Tats(), axelrod.SuspiciousTitForTat(), axelrod.TitForTat(), axelrod.Prober()]
strategies = [axelrod.Cooperator(), axelrod.Defector(), axelrod.CyclerCCD(),axelrod.HardTitForTat(),\
axelrod.TitFor2Tats(), axelrod.SuspiciousTitForTat(), axelrod.Random(), axelrod.TitForTat(), axelrod.Prober()]

learner = axelrod.LearnerAxel(memory_depth=2, exploreProb=0.1, learnerType=2)
multAxel = axelrod.EvolveAxel(3, evolveCode, 'MULT')
singAxel = axelrod.EvolveAxel(3, evolveCode, 'SING')

ply = learner

# print ply

for p in strategies:
    print "Currently playing against strategy:", p
    for turn in range(numTurns):
        ply.play(p)
    selfList = map(ScoreMatrix, zip(ply.history, p.history))
    oppList = map(ScoreMatrix, zip(p.history, ply.history))
예제 #10
0
    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.WinStayLoseShift(),
    axl.Random()
]

# The list of agents who won or survived the most based on the previous tournaments and simulations
best_players = [
    axl.SteinAndRapoport(),
    axl.Grudger(),
    axl.RevisedDowning(),
    axl.TitForTat(),
    axl.Davis(),
    axl.Nydegger(),
    axl.Cave(),
    axl.Tranquilizer(),
    axl.White(),
예제 #11
0
scores['D']['D'] = (1, 1)


def ScoreMatrix(moves):
    moveA = moves[0]
    moveB = moves[1]
    return scores[moveA][moveB][0]


# strategies = [s() for s in axelrod.basic_strategies]
#strategies = [axelrod.Cooperator(), axelrod.Defector(), axelrod.CyclerCCCD(), axelrod.CyclerCCD(), \
# axelrod.HardGoByMajority(), axelrod.GoByMajority(), axelrod.HardTitForTat(), axelrod.Random(), axelrod.TitForTat(), \
# axelrod.SuspiciousTitForTat(), axelrod.TitFor2Tats(), axelrod.Prober(), axelrod.Prober2(), axelrod.Prober3()]

strategies = [axelrod.Cooperator(), axelrod.Defector(), axelrod.CyclerCCD(), axelrod.HardGoByMajority(), axelrod.GoByMajority(), \
axelrod.HardTitForTat(), axelrod.TitFor2Tats(), axelrod.SuspiciousTitForTat(), axelrod.Random(), axelrod.TitForTat(), axelrod.Prober()]

creator.create(
    "FitnessMax", base.Fitness,
    weights=(1.0, ))  #Weight is a tuple, so here we use a single objective
creator.create(
    "Individual", list,
    fitness=creator.FitnessMax)  #Define the structure of the individuals

toolbox = base.Toolbox()  #Initialize it?

memLength = 3

toolbox.register("attr_bool", random.randint, 0, 1)  # Random boolean
toolbox.register(
    "individual", tools.initRepeat, creator.Individual, toolbox.attr_bool,
예제 #12
0
 def test_stochastic(self):
     self.assertFalse(axelrod.TitFor2Tats().stochastic)
예제 #13
0
 def test_representation(self):
     P1 = axelrod.TitFor2Tats()
     self.assertEqual(str(P1), 'Tit For 2 Tats')