def test_initial_nice_strategy(self): """ Starts by cooperating """ P1 = axelrod.Grumpy() P2 = axelrod.Player() self.assertEqual(P1.strategy(P2), 'C')
def test_initial_grumpy_strategy(self): """ Starts by defecting if grumpy """ P1 = axelrod.Grumpy(starting_state='Grumpy') P2 = TestOpponent() self.assertEqual(P1.strategy(P2), D)
def test_reset_method(self): """ tests the reset method """ P1 = axelrod.Grumpy(starting_state='Grumpy') P1.history = [C, D, D, D] P1.state = 'Nice' P1.reset() self.assertEqual(P1.history, []) self.assertEqual(P1.state, 'Grumpy')
def test_strategy(self): """ Tests that grumpy will play c until threshold is ht at which point it will become grumpy. Player will then not become nice until lower nice threshold is hit. """ P1 = axelrod.Grumpy(grumpy_threshold=3, nice_threshold=0) P2 = TestOpponent() test_responses(self, P1, P2, [C, D, D, D], [C, C, C, C], [C]) P1 = axelrod.Grumpy(grumpy_threshold=3, nice_threshold=0) P2 = TestOpponent() test_responses(self, P1, P2, [C, C, D, D, D], [D, D, D, D, D], [D]) P1 = axelrod.Grumpy(grumpy_threshold=3, nice_threshold=0) P2 = TestOpponent() test_responses(self, P1, P2, [C, C, D, D, D, D, D, D], [D, D, D, D, D, C, C, C], [D]) P1 = axelrod.Grumpy(grumpy_threshold=3, nice_threshold=0) P2 = TestOpponent() test_responses(self, P1, P2, [C, C, D, D, D, D, D, D, D, D, D], [D, D, D, D, D, C, C, C, C, C, C], [C])
def test_effect_of_strategy(self): """ Tests that grumpy will play c until threshold is ht at which point it will become grumpy. Player will then not become nice until lower nice threshold is hit. """ P1 = axelrod.Grumpy(grumpy_threshold = 3, nice_threshold=0) P2 = axelrod.Player() P1.history = ['C', 'D', 'D', 'D'] P2.history = ['C', 'C', 'C', 'C'] self.assertEqual(P1.strategy(P2), 'C') P1.history = ['C', 'C', 'D', 'D', 'D'] P2.history = ['D', 'D', 'D', 'D', 'D'] self.assertEqual(P1.strategy(P2), 'D') P1.history = ['C', 'C', 'D', 'D', 'D', 'D', 'D', 'D'] P2.history = ['D', 'D', 'D', 'D', 'D', 'C', 'C', 'C'] self.assertEqual(P1.strategy(P2), 'D') P1.history = ['C', 'C', 'D', 'D', 'D', 'D', 'D', 'D', 'D', 'D', 'D'] P2.history = ['D', 'D', 'D', 'D', 'D', 'C', 'C', 'C', 'C', 'C', 'C'] self.assertEqual(P1.strategy(P2), 'C')
def test_strategy(self): # Play against opponents actions = [(C, D), (D, C), (C, C), (C, C), (C, D), (D, D)] self.versus_test(axelrod.Random(), expected_actions=actions, seed=0) actions = [(C, C), (C, C), (C, D), (D, C), (C, D), (D, D)] self.versus_test(axelrod.Random(), expected_actions=actions, seed=1) actions = [(C, C), (C, D), (D, C), (C, D), (D, C)] self.versus_test(axelrod.Alternator(), expected_actions=actions) actions = [(C, C) * 50, (D, C), (C, C) * 5] self.versus_test(axelrod.Cooperator(), expected_actions=actions) actions = [(C, D), (D, D) * 49, (D, D) * 6] self.versus_test(axelrod.Defector(), expected_actions=actions) actions = [(C, C) * 50, (D, C), (C, C) * 5] self.versus_test(axelrod.Grumpy(), expected_actions=actions) actions = [(C, C) * 50, (D, C), (C, D) * 5] self.versus_test(axelrod.Grudger(), expected_actions=actions)
def test_reset_state_with_non_default_init(self): player = axl.Grumpy(starting_state='Grumpy') player.state = 'Nice' player.reset() self.assertEqual(player.state, 'Grumpy')
def test_reset_state_with_non_default_init(self): player = axl.Grumpy(starting_state="Grumpy") player.state = "Nice" player.reset() self.assertEqual(player.state, "Grumpy")
def test_reset_state_with_non_default_init(self): P1 = axelrod.Grumpy(starting_state='Grumpy') P1.state = 'Nice' P1.reset() self.assertEqual(P1.state, 'Grumpy')
def test_stochastic(self): self.assertFalse(axelrod.Grumpy().stochastic)
def test_representation(self): """ Tests string representation of class """ P1 = axelrod.Grumpy() self.assertEqual(str(P1), 'Grumpy')
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() ]
def test_reset(self): P1 = axelrod.Grumpy(starting_state='Grumpy') P1.state = 'Nice' P1.reset() self.assertEqual(P1.state, 'Grumpy')