-
Notifications
You must be signed in to change notification settings - Fork 263
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
Gladstein strategy #1110
Gladstein strategy #1110
Conversation
axelrod/strategies/axelrod_second.py
Outdated
|
||
This strategy is a TFT variant that defects on the first round in order to | ||
test the opponent's response. If the opponent ever defects, the strategy | ||
'apologies' by cooperating and then plays TFT for the rest of the game. |
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.
typo - should be 'apologizes'
axelrod/strategies/axelrod_second.py
Outdated
""" | ||
Submitted to Axelrod's second tournament by David Gladstein. | ||
|
||
This strategy is also known as Tester and is based of the reverse |
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.
typo - should be 'is based on'
|
||
Names: | ||
|
||
- Gladstein: [Axelrod1980b]_ |
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.
Could you add the name Tester here, please?
axelrod/strategies/axelrod_second.py
Outdated
super().__init__() | ||
# This strategy assumes the opponent is a patsy | ||
self.patsy = True | ||
self.cooperation_ratio = 0 |
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.
There is no need to maintain this ratio between calls to the play method. The original fortran strategy had to do that, but we pass the entire history to the player at each turn, so it can always be calculated within the play method.
axelrod/strategies/axelrod_second.py
Outdated
self.patsy = False | ||
return C | ||
# Cooperate as long as the cooperation ratio is below 0.5 | ||
self.cooperation_ratio = self.cooperations / len(self.history) |
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.
As above, this can be calculated directly from the history without the need for an instance variable. For example:
from collections import Counter
cooperation_ratio = Counter(self.history)[C] / len(self.history)
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.
Actually, I was forgetting we have that count already built into the Player class, so it becomes even simpler:
cooperation_ratio = self.cooperations / len(self.history)
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.
Using self.cooperations
is better, recomputing each time is O(n^2).
actions = [(D, C), (C, C), (D, C), (C, D), (C, D)] | ||
self.versus_test(opponent, expected_actions=actions, | ||
attrs={'patsy': False, | ||
'cooperation_ratio': 0.3333333333333333}) |
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.
Could we have this as 'cooperation_ratio': 1/3
.
axelrod/strategies/axelrod_second.py
Outdated
|
||
name = "Gladstein" | ||
classifier = { | ||
'memory_depth': 1, |
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.
This strategy has infinite memory depth : float('inf')
as it keeps track of it's cooperations.
(You'll need to adjust the corresponding doctest.)
I added the requested changes. I had to change a test in test_meta.py for |
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.
Could you also amend the overview of strategies doc to show that K76R has been implemented by this new class?
Thanks for this @dmanc! |
This is the implementation of the K76R Fortran strategy mentioned in #1102. The strategy was named Gladstein after the author's last name.