def test_strategy(self): """If opponent has defected more than 10 percent of the time, defect.""" P1 = axelrod.ForgivingTitForTat() P2 = axelrod.Player() P1.history = ['C', 'C', 'C', 'C'] P2.history = ['C', 'C', 'C', 'C'] self.assertEqual(P1.strategy(P2), 'C') P1.history = [ 'C', 'C', 'C', 'C', 'D', ] P2.history = [ 'C', 'C', 'C', 'D', 'C', ] self.assertEqual(P1.strategy(P2), 'C') P1.history = ['C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C'] P2.history = ['C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'D'] self.assertEqual(P1.strategy(P2), 'C') P1.history = ['C', 'C', 'C', 'C'] P2.history = ['C', 'C', 'C', 'D'] self.assertEqual(P1.strategy(P2), 'D')
def test_initial_strategy(self): """ Starts by cooperating """ P1 = axelrod.ForgivingTitForTat() P2 = axelrod.Player() self.assertEqual(P1.strategy(P2), 'C')
import axelrod as axl me = axl.Human(name='me') players = [axl.ForgivingTitForTat(), me] match = axl.Match(players, turns=5) match.play() print(match.result) print(match.sparklines()) print(match.scores()) print(match.final_score())
def test_stochastic(self): self.assertFalse(axelrod.ForgivingTitForTat().stochastic)
def test_representation(self): P1 = axelrod.ForgivingTitForTat() self.assertEqual(str(P1), 'Forgiving Tit For Tat')