コード例 #1
0
ファイル: test_meta.py プロジェクト: yinhang2/Axelrod
    def test_strategy(self):
        # We are using CooperatorHunter here, so this should lead to
        # defection
        actions = [(C, C)] * 4 + [(D, C)]
        self.versus_test(opponent=axelrod.Cooperator(),
                         expected_actions=actions)

        # All these others, however, should trigger a defection for the hunter.
        actions = [(C, D), (C, D), (C, D), (C, D), (D, D)]
        self.versus_test(opponent=axelrod.Defector(), expected_actions=actions)

        actions = [(C, C), (C, D), (C, C), (C, D), (C, C), (C, D), (D, C)]
        self.versus_test(opponent=axelrod.Alternator(),
                         expected_actions=actions)

        actions = [(C, C), (C, C), (C, C), (C, D), (C, C), (C, C), (C, C),
                   (C, D), (D, C)]
        self.versus_test(opponent=axelrod.CyclerCCCD(),
                         expected_actions=actions)

        # To test the TFT action of the strategy after 100 turns, we need to
        # remove two of the hunters from its team.
        # It is almost impossible to identify a history which reaches 100 turns
        # without triggering one of the hunters in the default team. As at
        # 16-Mar-2017, none of the strategies in the library does so.
        team = [
            axelrod.DefectorHunter, axelrod.AlternatorHunter,
            axelrod.RandomHunter, axelrod.CycleHunter,
            axelrod.EventualCycleHunter
        ]
        opponent = axelrod.MockPlayer([C] * 100 + [D])
        actions = [(C, C)] * 100 + [(C, D), (D, C)]
        self.versus_test(opponent=opponent,
                         expected_actions=actions,
                         init_kwargs={'team': team})
コード例 #2
0
ファイル: test_hunter.py プロジェクト: yashaslokesh/Axelrod
 def test_strategy(self):
     player = self.player()
     # Test against cyclers
     for opponent in [
             axelrod.CyclerCCD(),
             axelrod.CyclerCCCD(),
             axelrod.CyclerCCCCCD(),
             axelrod.Alternator(),
     ]:
         player.reset()
         for i in range(50):
             player.play(opponent)
         self.assertEqual(player.history[-1], D)
     # Test against non-cyclers and cooperators
     axelrod.seed(43)
     for opponent in [
             axelrod.Random(),
             axelrod.AntiCycler(),
             axelrod.DoubleCrosser(),
             axelrod.Cooperator(),
     ]:
         player.reset()
         for i in range(50):
             player.play(opponent)
         self.assertEqual(player.history[-1], C)
コード例 #3
0
ファイル: test_meta.py プロジェクト: yinhang2/Axelrod
    def test_strategy(self):
        # We are not using the Cooperator Hunter here, so this should lead to
        #  cooperation.
        actions = [(C, C)] * 5
        self.versus_test(opponent=axelrod.Cooperator(),
                         expected_actions=actions)

        # After long histories tit-for-tat should come into play.
        opponent = axelrod.MockPlayer([C] * 100 + [D])
        actions = [(C, C)] * 100 + [(C, D)] + [(D, C)]
        self.versus_test(opponent=opponent, expected_actions=actions)

        actions = [(C, C)] * 102
        self.versus_test(opponent=axelrod.Cooperator(),
                         expected_actions=actions)

        # All these others, however, should trigger a defection for the hunter.
        actions = [(C, D), (C, D), (C, D), (C, D), (D, D)]
        self.versus_test(opponent=axelrod.Defector(), expected_actions=actions)

        actions = [(C, C), (C, D), (C, C), (C, D), (C, C), (C, D), (D, C)]
        self.versus_test(opponent=axelrod.Alternator(),
                         expected_actions=actions)

        actions = [(C, C), (C, C), (C, C), (C, D), (C, C), (C, C), (C, C),
                   (C, D), (D, C)]
        self.versus_test(opponent=axelrod.CyclerCCCD(),
                         expected_actions=actions)
コード例 #4
0
 def test_strategy(self):
     self.first_play_test(C)
     player = self.player()
     # Test against cyclers
     for opponent in [
             axelrod.CyclerCCD(),
             axelrod.CyclerCCCD(),
             axelrod.CyclerCCCCCD(),
             axelrod.Alternator()
     ]:
         player.reset()
         for i in range(30):
             player.play(opponent)
         self.assertEqual(player.history[-1], D)
     # Test against non-cyclers
     axelrod.seed(40)
     for opponent in [
             axelrod.Random(),
             axelrod.AntiCycler(),
             axelrod.Cooperator(),
             axelrod.Defector()
     ]:
         player.reset()
         for i in range(30):
             player.play(opponent)
         self.assertEqual(player.history[-1], C)
コード例 #5
0
def tft_strats():
    strategies = [
        axelrod.TitForTat(),
        axelrod.Alternator(),
        axelrod.CyclerCCD(),
        axelrod.CyclerCCCD(),
        axelrod.CyclerCCCCCD(),
        axelrod.AntiCycler(),
        axelrod.WinStayLoseShift(),
        axelrod.FoolMeOnce()
    ]
    return strategies
コード例 #6
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
コード例 #7
0
ファイル: test_hunter.py プロジェクト: jamesjc1998/Axelrod2
 def test_strategy(self):
     player = self.player()
     # Test against cyclers
     for opponent in [
             axl.CyclerCCD(),
             axl.CyclerCCCD(),
             axl.CyclerCCCCCD(),
             axl.Alternator(),
     ]:
         player.reset()
         match = Match((player, opponent), turns=50)
         match.play()
         self.assertEqual(player.history[-1], D)
     # Test against non-cyclers and cooperators
     for opponent in [
             axl.Random(),
             axl.AntiCycler(),
             axl.DoubleCrosser(),
             axl.Cooperator(),
     ]:
         player.reset()
         match = Match((player, opponent), turns=50, seed=43)
         match.play()
         self.assertEqual(player.history[-1], C)