Skip to content

Commit 4865136

Browse files
yohmmarcharper
authored andcommitted
refactoring
1 parent aedb71a commit 4865136

File tree

1 file changed

+22
-23
lines changed

1 file changed

+22
-23
lines changed

axelrod/strategies/grudger.py

Lines changed: 22 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -382,43 +382,42 @@ class Capri(Player):
382382

383383
def strategy(self, opponent: Player) -> Action:
384384
# initial history profile is full cooperation
385-
hist = [[C, C], [C, C], [C, C]]
386-
for i in range(min(len(self.history), 3)):
387-
hist[-i-1][0] = self.history[-i-1]
388-
hist[-i-1][1] = opponent.history[-i-1]
385+
hist = list(zip(self.history[-3:], opponent.history[-3:]))
386+
while len(hist) < 3:
387+
hist.insert(0, (C, C))
389388

390-
if hist == [[C,C],[C,C],[C,C]]: # Rule: C
389+
if hist == [(C, C), (C, C), (C, C)]: # Rule: C
391390
return C
392-
if hist == [[C, C], [C, C], [D, C]]: # Rule: A
391+
if hist == [(C, C), (C, C), (D, C)]: # Rule: A
393392
return C
394-
if hist == [[C, C], [D, C], [C, D]]:
393+
if hist == [(C, C), (D, C), (C, D)]:
395394
return C
396-
if hist == [[D, C], [C, D], [C, C]]:
395+
if hist == [(D, C), (C, D), (C, C)]:
397396
return C
398-
if hist == [[C, D], [C, C], [C, C]]:
397+
if hist == [(C, D), (C, C), (C, C)]:
399398
return C
400-
if hist == [[C, C], [C, C], [C, D]]: # Rule: P
399+
if hist == [(C, C), (C, C), (C, D)]: # Rule: P
401400
return D
402-
if hist == [[C, C], [C, D], [D, C]]:
401+
if hist == [(C, C), (C, D), (D, C)]:
403402
return C
404-
if hist == [[C, D], [D, C], [C, C]]:
403+
if hist == [(C, D), (D, C), (C, C)]:
405404
return C
406-
if hist == [[D, C], [C, C], [C, C]]:
405+
if hist == [(D, C), (C, C), (C, C)]:
407406
return C
408-
if hist == [[D, D], [D, D], [D, C]]: # Rule: R1
407+
if hist == [(D, D), (D, D), (D, C)]: # Rule: R1
409408
return C
410-
if hist == [[D, D], [D, C], [C, C]]:
409+
if hist == [(D, D), (D, C), (C, C)]:
411410
return C
412-
# if hist == [[D, C], [C, C], [C, C]]: # duplicate of Rule P
413-
# return C
414-
if hist == [[D, D], [D, D], [C, D]]: # Rule: R2
411+
# if hist == [(D, C), (C, C), (C, C)]: # duplicate of Rule P
412+
# return(C
413+
if hist == [(D, D), (D, D), (C, D)]: # Rule: R2
415414
return C
416-
if hist == [[D, D], [C, D], [C, C]]:
415+
if hist == [(D, D), (C, D), (C, C)]:
417416
return C
418-
# if hist == [[C, D], [C, C], [C, C]]: # duplicate of Rule A
419-
# return C
420-
if hist == [[D, D], [D, D], [C, C]]: # Rule: R3
417+
# if hist == [(C, D), (C, C), (C, C)]: # duplicate of Rule A
418+
# return(C
419+
if hist == [(D, D), (D, D), (C, C)]: # Rule: R3
421420
return C
422-
if hist == [[D, D], [C, C], [C, C]]:
421+
if hist == [(D, D), (C, C), (C, C)]:
423422
return C
424423
return D

0 commit comments

Comments
 (0)