-
Notifications
You must be signed in to change notification settings - Fork 264
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
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
d2ed293
grudger: changed ForgetfulGrudger. tests now use self.versus_test
eric-s-s 9d6ac1d
GeneralSoftGrudger changed to cover edge cases. edge case tests included
eric-s-s 7841213
reverted GeneralSoftGrudger tests
eric-s-s 63bcaa2
removed changes for cases that will not occur
eric-s-s 2ce541c
added attrs to tests in ForgetfulGrudger
eric-s-s 4351ca0
closer to original TestForgetfulGrudger
eric-s-s File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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: | ||
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): | ||
|
@@ -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): | ||
|
@@ -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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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: | ||
|
||
|
@@ -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 | ||
|
@@ -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): | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍