@@ -1055,3 +1055,109 @@ def test_strategy(self):
10551055 actions += [(D , D )] # Three of last four are disagreements.
10561056 actions += [(D , D )] # Now there are 5/9 disagreements, so Defect.
10571057 self .versus_test (axelrod .WinShiftLoseStay (), expected_actions = actions , attrs = {"num_agreements" : 5 })
1058+
1059+
1060+ class TestYamachi (TestPlayer ):
1061+ name = 'Yamachi'
1062+ player = axelrod .Yamachi
1063+ expected_classifier = {
1064+ 'memory_depth' : float ('inf' ),
1065+ 'stochastic' : False ,
1066+ 'makes_use_of' : set (),
1067+ 'long_run_time' : False ,
1068+ 'inspects_source' : False ,
1069+ 'manipulates_source' : False ,
1070+ 'manipulates_state' : False
1071+ }
1072+
1073+ def test_strategy (self ):
1074+ actions = [(C , C )] * 100
1075+ self .versus_test (axelrod .Cooperator (), expected_actions = actions )
1076+
1077+ actions = [(C , D )] * 2 # Also Cooperate in first two moves (until we update `count_them_us_them`.)
1078+ actions += [(C , D )] # them_three_ago defaults to C, so that (C, C, *) gets updated, then (D, C, *) get checked.
1079+ # It's actually impossible to Defect on the third move.
1080+ actions += [(D , D )] # (D, C, *) gets updated, then checked.
1081+ actions += [(C , D )] # (D, C, *) gets updated, but (D, D, *) checked.
1082+ actions += [(D , D )] * 30 # (D, D, *) gets updated and checked from here on.
1083+ self .versus_test (axelrod .Defector (), expected_actions = actions )
1084+
1085+ actions = [(C , C ), (C , D )]
1086+ actions += [(C , C )] # Increment (C, C, C). Check (C, C, *). Cooperate.
1087+ # Reminder that first C is default value and last C is opponent's first move.
1088+ actions += [(C , D )] # Increment (C, C, D). Check (D, C, *) = 0. Cooperate.
1089+ actions += [(C , C )] # Increment (D, C, C). Check (C, C, *) = 0. Cooperate.
1090+ # There is one Defection and one Cooperation in this scenario,
1091+ # but the Cooperation was due to a default value only. We can see where this is going.
1092+ actions += [(C , D )] # Increment (C, C, D). Check (D, C, *) = 1. Cooperate.
1093+ actions += [(D , C )] # Increment (D, C, C). Check (C, C, *) = -1. Defect.
1094+ actions += [(C , D )] # Increment (C, C, D). Check (D, D, *) = 0 (New). Cooperate.
1095+ actions += [(D , C )] # Increment (D, D, C). Check (C, C, *) < 0. Defect.
1096+ actions += [(C , D )] # Increment (C, C, D). Check (D, D, *) > 0. Cooperate.
1097+ actions += [(D , C ), (C , D )] * 15 # This pattern continues for a while.
1098+ actions += [(D , C ), (D , D )] * 30 # Defect from turn 41 on, since near 50% Defections.
1099+ self .versus_test (axelrod .Alternator (), expected_actions = actions )
1100+
1101+ # Rip-off is the most interesting interaction.
1102+ actions = [(C , D ),
1103+ (C , C ),
1104+ (C , D ),
1105+ (D , C ),
1106+ (C , C ),
1107+ (D , C ),
1108+ (C , D ),
1109+ (D , C ),
1110+ (C , D ),
1111+ (D , C ),
1112+ (C , D ),
1113+ (D , C ),
1114+ (C , D ),
1115+ (D , C ),
1116+ (C , D ),
1117+ (D , C ),
1118+ (C , D ),
1119+ (D , C ),
1120+ (C , D ),
1121+ (D , C ),
1122+ (C , D ),
1123+ (D , C ),
1124+ (C , D ),
1125+ (D , C ),
1126+ (C , D ),
1127+ (D , C ),
1128+ (C , D ),
1129+ (D , C ),
1130+ (C , D ),
1131+ (D , C ),
1132+ (C , D ),
1133+ (D , C ),
1134+ (C , D ),
1135+ (D , C ),
1136+ (C , D ),
1137+ (D , C ),
1138+ (C , D ),
1139+ (D , C ),
1140+ (C , D ),
1141+ (D , C )]
1142+ my_dict = {(C , C , C ): 1 ,
1143+ (C , C , D ): 18 ,
1144+ (C , D , C ): 1 ,
1145+ (C , D , D ): 0 ,
1146+ (D , C , C ): 1 ,
1147+ (D , C , D ): 0 ,
1148+ (D , D , C ): 17 ,
1149+ (D , D , D ): 0 }
1150+ RipoffPlayer = axelrod .Ripoff ()
1151+ self .versus_test (RipoffPlayer , expected_actions = actions , attrs = {"count_them_us_them" : my_dict })
1152+ self .assertEqual (RipoffPlayer .defections , 19 ) # Next turn, `portion_defect` = 0.4756
1153+
1154+ # The pattern (C, D), (D, C) will continue indefintely unless overriden.
1155+ actions += [(D , D )] # Next turn, `portion_defect` = 0.4881
1156+ actions += [(D , D )] # Next turn, `portion_defect` = 0.5
1157+ actions += [(D , D )] # Next turn, `portion_defect` = 0.5114
1158+ actions += [(D , D )] # Next turn, `portion_defect` = 0.5222
1159+ actions += [(D , D )] # Next turn, `portion_defect` = 0.5326
1160+ actions += [(D , D )] # Next turn, `portion_defect` = 0.5426
1161+ actions += [(D , D )] # Next turn, `portion_defect` = 0.5521
1162+ actions += [(D , D ), (C , D ), (D , C ), (C , D )] # Takes a turn to fall back into the cycle.
1163+ self .versus_test (axelrod .Ripoff (), expected_actions = actions )
0 commit comments