-
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
Add a new DynamicTwoTitsForTat strategy #1030
Changes from 4 commits
cc60038
4c89284
f07bcb7
e9abbe8
d014e39
1971111
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
from axelrod.actions import Actions, Action | ||
from axelrod.player import Player | ||
from axelrod.strategy_transformers import TrackHistoryTransformer, FinalTransformer | ||
from axelrod.random_ import random_choice | ||
|
||
C, D = Actions.C, Actions.D | ||
|
||
|
@@ -92,6 +93,41 @@ class TwoTitsForTat(Player): | |
def strategy(opponent: Player) -> Action: | ||
return D if D in opponent.history[-2:] else C | ||
|
||
class DynamicTwoTitsForTat(Player): | ||
""" | ||
A player starts by cooperating and then punishes its opponent's | ||
defectiions by opponent with a dynamic bias based off of the | ||
opponents ratio of cooperations to total moves (so their current | ||
probability of cooperating towards cooporating regardless of the | ||
move (aka: forgiveness)). | ||
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. typos and grammar: 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. "its opponent's defectiions by opponent" Should this be either 'its opponent's defections' or 'defections by opponent'? 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. "(so their current probability of cooperating towards cooporating regardless of the move (aka: forgiveness))." Sorry, but I don't understand what that line means. |
||
|
||
Names: | ||
|
||
- Dynamic Two Tits For Tat: Original name by Grant Garrett-Grossman. | ||
""" | ||
|
||
name = 'Dynamic Two Tits For Tat' | ||
classifier = { | ||
'memory_depth': 2, # Long memory, memory-2 | ||
'stochastic': True, | ||
'makes_use_of': set(), | ||
'long_run_time': False, | ||
'inspects_source': False, | ||
'manipulates_source': False, | ||
'manipulates_state': False | ||
} | ||
|
||
@staticmethod | ||
def strategy(opponent): | ||
# First move | ||
if len(opponent.history) == 0: | ||
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. this would be better as 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. FYI @FakeNameSE this gives some good background: https://stackoverflow.com/questions/53513/best-way-to-check-if-a-list-is-empty (Apologies, as is was my suggestion, thanks to @meatballs for pointing it out!) |
||
# Make sure we cooporate first turn | ||
return C | ||
if D in opponent.history[-2:]: | ||
# Probability of cooperating regardless | ||
return random_choice(opponent.cooperations / len(opponent.history)) | ||
else: | ||
return C | ||
|
||
class Bully(Player): | ||
"""A player that behaves opposite to Tit For Tat, including first move. | ||
|
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.
Blank line before
Names
please.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.
done