Skip to content

Commit 890d930

Browse files
committed
Moved probabilities in Leyvraz to dict for readability.
1 parent aa5fa8a commit 890d930

File tree

1 file changed

+14
-9
lines changed

1 file changed

+14
-9
lines changed

axelrod/strategies/axelrod_second.py

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1486,18 +1486,23 @@ class Leyvraz(Player):
14861486
'manipulates_state': False
14871487
}
14881488

1489+
def __init__(self) -> None:
1490+
super().__init__()
1491+
self.prob_coop = {
1492+
(C, C, C): 1.0,
1493+
(C, C, D): 0.5,
1494+
(C, D, C): 0.0,
1495+
(C, D, D): 0.25,
1496+
(D, C, C): 1.0,
1497+
(D, C, D): 1.0,
1498+
(D, D, C): 1.0,
1499+
(D, D, D): 0.5
1500+
}
1501+
14891502
def strategy(self, opponent: Player) -> Action:
14901503
recent_history = [C, C, C] # Default to C.
14911504
for go_back in range(1, 4):
14921505
if len(opponent.history) >= go_back:
14931506
recent_history[-go_back] = opponent.history[-go_back]
14941507

1495-
if recent_history[-1] == D and recent_history[-2] == D:
1496-
return random_choice(0.25)
1497-
if recent_history[-3] == D:
1498-
return C
1499-
if recent_history[-2] == D:
1500-
return D
1501-
if recent_history[-1] == D:
1502-
return random_choice(0.5)
1503-
return C # recent_history == [C, C, C]
1508+
return random_choice(self.prob_coop[tuple(recent_history)])

0 commit comments

Comments
 (0)