@@ -1908,3 +1908,125 @@ def test_strategy(self):
19081908 self .versus_test (custom_opponent , expected_actions = actions , attrs = {
19091909 "distrust_points" : 2 }) # But no more
19101910
1911+
1912+ class TestAppold (TestPlayer ):
1913+ name = "Appold"
1914+ player = axelrod .Appold
1915+ expected_classifier = {
1916+ "memory_depth" : float ("inf" ),
1917+ "stochastic" : True ,
1918+ "makes_use_of" : set (),
1919+ "long_run_time" : False ,
1920+ "inspects_source" : False ,
1921+ "manipulates_source" : False ,
1922+ "manipulates_state" : False ,
1923+ }
1924+
1925+ def test_strategy (self ):
1926+ # Should cooperate 100% of the time with the cooperator
1927+ actions = [(C , C )] * 100
1928+ self .versus_test (axelrod .Cooperator (), expected_actions = actions )
1929+
1930+ opponent = axelrod .Defector ()
1931+ # Cooperate always the first 4 turns
1932+ actions = [(C , D )] * 4
1933+ # Should cooperate because we forgive the first_opp_def after the fourth
1934+ # turn.
1935+ actions += [(C , D )]
1936+ # Own move two turns ago is C, so D.
1937+ actions += [(D , D )]
1938+ # Then defect most of the time, depending on the random number. We
1939+ # don't defect 100% of the time, because of the way that initialize
1940+ # opp_c_after_x.
1941+ actions += [(D , D ),
1942+ (C , D ),
1943+ (D , D ),
1944+ (D , D ), # C can never be two moves after a C.
1945+ (D , D ),
1946+ (D , D ),
1947+ (D , D ),
1948+ (D , D ),
1949+ (D , D ),
1950+ (D , D ),
1951+ (C , D ),
1952+ (C , D ),
1953+ (D , D ),
1954+ (D , D ),
1955+ (D , D ),
1956+ (D , D ),
1957+ (D , D ),
1958+ (C , D ),
1959+ (D , D ),
1960+ (D , D ),
1961+ (D , D ),
1962+ (D , D ),
1963+ (D , D ),
1964+ (D , D ),
1965+ (C , D ),
1966+ (C , D ),
1967+ (D , D ),
1968+ (D , D )]
1969+ self .versus_test (opponent , expected_actions = actions , seed = 1 ,
1970+ attrs = {"first_opp_def" : True })
1971+
1972+ # An opponent who defects for a long time, then tries cooperating
1973+ opponent_actions = [C ] * 30 + [D ] + [C ] * 10
1974+ MostlyCooperates = axelrod .MockPlayer (actions = opponent_actions )
1975+ # Cooperate always at first
1976+ actions = [(C , C )] * 30
1977+ # The opponent defects once
1978+ actions += [(C , D )]
1979+ # But we forgive it.
1980+ actions += [(C , C )] * 10
1981+ self .versus_test (MostlyCooperates , expected_actions = actions )
1982+
1983+ opponent = axelrod .CyclerDC ()
1984+ # First three opponent actions get counted as reactions to C. Fourth
1985+ # action will get counted on next turn.
1986+ actions = [(C , D ), (C , C ), (C , D ), (C , C )]
1987+ self .versus_test (opponent , expected_actions = actions ,
1988+ attrs = {"opp_c_after_x" : {C : 1 , D : 1 },
1989+ "total_num_of_x" : {C : 3 , D : 1 }})
1990+ # Will cooperate 50% of the time
1991+ actions += [(C , D )]
1992+ self .versus_test (opponent , expected_actions = actions ,
1993+ attrs = {"opp_c_after_x" : {C : 2 , D : 1 },
1994+ "total_num_of_x" : {C : 4 , D : 1 },
1995+ "first_opp_def" : False }, seed = 100 )
1996+ # Always cooperate, because we forgive the first defect
1997+ actions += [(C , C )]
1998+ self .versus_test (opponent , expected_actions = actions ,
1999+ attrs = {"first_opp_def" : True }, seed = 100 )
2000+
2001+ # Against a random opponent, will respond mostly randomly too.
2002+ actions = [(C , C ),
2003+ (C , C ),
2004+ (C , D ),
2005+ (C , C ),
2006+ (C , C ),
2007+ (C , D ),
2008+ (C , C ),
2009+ (C , C ),
2010+ (C , C ),
2011+ (D , C ),
2012+ (C , D ),
2013+ (D , D ),
2014+ (C , D ),
2015+ (C , D ),
2016+ (C , C ),
2017+ (C , C ),
2018+ (D , C ),
2019+ (C , D ),
2020+ (D , D ),
2021+ (C , C ),
2022+ (C , D ),
2023+ (C , C ),
2024+ (C , C ),
2025+ (C , D ),
2026+ (D , C ),
2027+ (C , D ),
2028+ (D , D ),
2029+ (C , D ),
2030+ (C , C ),
2031+ (D , C )]
2032+ self .versus_test (axelrod .Random (0.5 ), expected_actions = actions , seed = 7 )
0 commit comments