-
Notifications
You must be signed in to change notification settings - Fork 269
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
Add the K86R (MoreGrofman) Strategy #1124
Merged
drvinceknight
merged 18 commits into
Axelrod-Python:master
from
buckbaskin:more-grofman
Sep 19, 2017
Merged
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
a93d74a
Write out strategy logic
buckbaskin aca96ae
Fix some identified pep8 compliance issues
buckbaskin 1a9fa68
Update the strategies/_strategies.py file with MoreGrofman
buckbaskin 6ffdaea
Add MoreGrofman strategy to the list of strategies
buckbaskin bc50c84
Add tests to verify the MoreGrofman logic
buckbaskin 900e885
Make advised syntax changes with double quote, using count
buckbaskin 29de9ba
Add test that demonstrates error in strategy logic
buckbaskin f3625e8
Add an extended test to match a 30 round Fortran match
buckbaskin e870730
Adjust indexing for an off-by-1 error. Test passes, will try longer test
buckbaskin 2480ca7
Repair off-by-1 error in Python implementation and Add tests to verify
buckbaskin 79f0499
Update comments to reflect behavior that matches Fortran behavior
buckbaskin 8f64aad
Clarify behavior re: inspection of history
buckbaskin 37664eb
Make a style change to else logic
buckbaskin 1334535
Change expected test memory depth to 8
buckbaskin 251da15
Fix Spacing Issue that broke docs compilation
buckbaskin 60ac912
Make style changes to MoreGrofman strategy
buckbaskin 64efcae
Shorten the actions list for testing against Fortran examples
buckbaskin ad55ec5
Merge branch 'master' of github.com:Axelrod-Python/Axelrod into more-…
buckbaskin 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
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 |
---|---|---|
|
@@ -410,3 +410,60 @@ def strategy(self, opponent: Player) -> Action: | |
return C | ||
return D | ||
return opponent.history[-1] | ||
|
||
|
||
class MoreGrofman(Player): | ||
""" | ||
Submitted to Axelrod's second tournament by Bernard Grofman. | ||
|
||
This strategy has 3 phases: | ||
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. Also need a space here.
|
||
|
||
1. First it cooperates on the first two rounds | ||
2. For rounds 3-7 inclusive, it plays the same as the opponent's last move | ||
3. Thereafter, it applies the following logic, looking at its memory of the | ||
last 8\* rounds (ignoring the most recent round). | ||
|
||
- If its own previous move was C and the opponent has defected less than | ||
3 times in the last 8\* rounds, cooperate | ||
- If its own previous move was C and the opponent has defected 3 or | ||
more times in the last 8\* rounds, defect | ||
- If its own previous move was D and the opponent has defected only once | ||
or not at all in the last 8\* rounds, cooperate | ||
- If its own previous move was D and the opponent has defected more than | ||
once in the last 8\* rounds, defect | ||
|
||
\* The code looks at the first 7 of the last 8 rounds, ignoring the most | ||
recent round. | ||
|
||
Names: | ||
- Grofman's strategy: [Axelrod1980b]_ | ||
- K86R: [Axelrod1980b]_ | ||
""" | ||
name = "MoreGrofman" | ||
classifier = { | ||
'memory_depth': 8, | ||
'stochastic': False, | ||
'makes_use_of': set(), | ||
'long_run_time': False, | ||
'inspects_source': False, | ||
'manipulates_source': False, | ||
'manipulates_state': False | ||
} | ||
|
||
def strategy(self, opponent: Player) -> Action: | ||
# Cooperate on the first two moves | ||
if len(self.history) < 2: | ||
return C | ||
# For rounds 3-7, play the opponent's last move | ||
elif 2 <= len(self.history) <= 6: | ||
return opponent.history[-1] | ||
else: | ||
# Note: the Fortran code behavior ignores the opponent behavior | ||
# in the last round and instead looks at the first 7 of the last | ||
# 8 rounds. | ||
opponent_defections_last_8_rounds = opponent.history[-8:-1].count(D) | ||
if self.history[-1] == C and opponent_defections_last_8_rounds <= 2: | ||
return C | ||
if self.history[-1] == D and opponent_defections_last_8_rounds <= 1: | ||
return C | ||
return D |
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
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.
Can we add the Fortran rule name (K86R) to the docstring?