Skip to content

Commit 654bcd7

Browse files
kjurgielajtismarcharper
authored andcommitted
Removed if statement, added setup for next_random_defection_turn
1 parent 2acc705 commit 654bcd7

File tree

1 file changed

+17
-15
lines changed

1 file changed

+17
-15
lines changed

axelrod/strategies/axelrod_first.py

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -262,22 +262,24 @@ def strategy(self, opponent: Player) -> Action:
262262
return D
263263
return C
264264

265-
if len(self.history) >= 57:
266-
# Check if opponent plays randomly, if so, defect
267-
p_value = chisquare([opponent.cooperations, opponent.defections]).pvalue
268-
self.opponent_is_random = (p_value >= self.alpha) or self.opponent_is_random
265+
# Check if opponent plays randomly, if so, defect
266+
p_value = chisquare([opponent.cooperations, opponent.defections]).pvalue
267+
self.opponent_is_random = (p_value >= self.alpha) or self.opponent_is_random
269268

270-
if self.opponent_is_random:
271-
return D
272-
if all(opponent.history[i] == self.history[i - 1] for i in range(1, len(self.history))):
273-
# Check if opponent plays Tit for Tat
274-
if opponent.history[-1] == D:
275-
return D
276-
return C
277-
278-
if len(self.history) == self.next_random_defection_turn:
279-
self.next_random_defection_turn = random.randint(5, 15) + len(self.history) # resample the next defection turn
280-
return D
269+
if self.opponent_is_random:
270+
return D
271+
if all(opponent.history[i] == self.history[i - 1] for i in range(1, len(self.history))):
272+
# Check if opponent plays Tit for Tat
273+
if opponent.history[-1] == D:
274+
return D
275+
return C
276+
277+
if self.next_random_defection_turn is None:
278+
self.next_random_defection_turn = random.randint(5, 15) + len(self.history)
279+
280+
if len(self.history) == self.next_random_defection_turn:
281+
self.next_random_defection_turn = random.randint(5, 15) + len(self.history) # resample the next defection turn
282+
return D
281283
return C
282284

283285

0 commit comments

Comments
 (0)