@@ -1094,7 +1094,6 @@ def __init__(self):
1094
1094
self .move_history = np .zeros ([4 , 2 ])
1095
1095
# Will cache value only for testing purposes, not used otherwise
1096
1096
self .chi_squared = None
1097
- self .history_row = 0
1098
1097
1099
1098
self .more_coop = 0 # This schedules cooperation for future turns
1100
1099
# Initial last_generous_n_turns_ago to 3 because this counts up and
@@ -1231,24 +1230,26 @@ def strategy(self, opponent: Player) -> Action:
1231
1230
# If not Defect mode, proceed to update history and check for random,
1232
1231
# check if burned, and check if opponent's fairweather.
1233
1232
1234
- # History only gets updated outside of Defect mode.
1235
- if turn > 2 :
1236
- if opponent .history [- 1 ] == D :
1237
- self .recorded_defects += 1
1238
- opp_col = 1 if opponent .history [- 1 ] == D else 0
1239
- self .move_history [self .history_row , opp_col ] += 1
1240
-
1241
- # Detect random
1242
- if turn % 15 == 0 and turn > 15 and not self .was_defective :
1243
- if self .detect_random (turn ):
1244
- self .mode = "Defect"
1245
- return self .try_return (D , lower_flags = False ) # Lower_flags not used here.
1246
-
1247
- # history_row only gets updated if not in Defect mode AND not entering
1248
- # Defect mode.
1249
- self .history_row = 1 if opponent .history [- 1 ] == D else 0
1250
- if self .history [- 1 ] == D :
1251
- self .history_row += 2
1233
+ # If we haven't yet entered Defect mode
1234
+ if not self .was_defective :
1235
+ if turn > 2 :
1236
+ if opponent .history [- 1 ] == D :
1237
+ self .recorded_defects += 1
1238
+
1239
+ # Column decided by opponent's last turn
1240
+ history_col = 1 if opponent .history [- 1 ] == D else 0
1241
+ # Row is decided by opponent's move two turns ago and our move
1242
+ # two turns ago.
1243
+ history_row = 1 if opponent .history [- 2 ] == D else 0
1244
+ if self .history [- 2 ] == D :
1245
+ history_row += 2
1246
+ self .move_history [history_row , history_col ] += 1
1247
+
1248
+ # Try to detect random opponent
1249
+ if turn % 15 == 0 and turn > 15 :
1250
+ if self .detect_random (turn ):
1251
+ self .mode = "Defect"
1252
+ return self .try_return (D , lower_flags = False ) # Lower_flags not used here.
1252
1253
1253
1254
# If generous 2 turns ago and opponent defected last turn
1254
1255
if self .last_generous_n_turns_ago == 2 and opponent .history [- 1 ] == D :
0 commit comments