Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

884 grudger - with 1 to 3 issues #993

Merged
merged 6 commits into from
Apr 30, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 17 additions & 15 deletions axelrod/strategies/grudger.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,16 +63,16 @@ def __init__(self) -> None:
def strategy(self, opponent: Player) -> Action:
"""Begins by playing C, then plays D for mem_length rounds if the
opponent ever plays D."""
if self.grudge_memory >= self.mem_length:
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

strategy docstring says defect for 10 rounds. strategy code said detect for 11 rounds. I changed the code to fit the docstring.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

if self.grudge_memory == self.mem_length:
self.grudge_memory = 0
self.grudged = False

if D in opponent.history[-1:]:
self.grudged = True

if self.grudged:
self.grudge_memory += 1
return D
elif D in opponent.history[-1:]:
self.grudged = True
return D
return C

def reset(self):
Expand Down Expand Up @@ -206,9 +206,9 @@ def strategy(self, opponent: Player) -> Action:
"""Begins by playing C, then plays Alternator for the remaining rounds
if the opponent ever plays D."""
if opponent.defections:
if self.history[-1] == Actions.C:
return Actions.D
return Actions.C
if self.history[-1] == C:
return D
return C


class EasyGo(Player):
Expand Down Expand Up @@ -240,13 +240,14 @@ def strategy(opponent: Player) -> Action:
return C
return D


class GeneralSoftGrudger(Player):
"""
A generalization of the SoftGrudger strategy. SoftGrudger punishes by playing:
D, D, D, D, C, C. after a defection by the opponent. GeneralSoftGrudger
only punishes after its opponent defects a specified amount of times consecutively.
The punishment is in the form of a series of defections followed by a 'penance' of
a series of consecutive cooperations.
A generalization of the SoftGrudger strategy. SoftGrudger punishes by
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

changed docstring to fit line-llen = 80.

playing: D, D, D, D, C, C. after a defection by the opponent.
GeneralSoftGrudger only punishes after its opponent defects a specified
amount of times consecutively. The punishment is in the form of a series of
defections followed by a 'penance' of a series of consecutive cooperations.

Names:

Expand All @@ -268,11 +269,11 @@ def __init__(self, n: int=1, d: int=4, c: int=2) -> None:
"""
Parameters
----------
n, int
n: int
The number of defections by the opponent to trigger punishment
d, int
d: int
The number of defections to punish the opponent
c, int
c: int
The number of cooperations in the 'penance' stage

Special Cases
Expand Down Expand Up @@ -303,6 +304,7 @@ def strategy(self, opponent: Player) -> Action:
elif [D] * self.n == opponent.history[-self.n:]:
self.grudged = True
return D

return C

def reset(self):
Expand Down
Loading