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

Added some of the strategies listed in Ashlock2009. #1231

Merged
Merged
Show file tree
Hide file tree
Changes from 4 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
4 changes: 4 additions & 0 deletions axelrod/strategies/_strategies.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@
Pun1,
Raider,
Ripoff,
UsuallyCooperates,
UsuallyDefects,
SolutionB1,
SolutionB5,
Thumper,
Expand Down Expand Up @@ -419,6 +421,8 @@
TrickyLevelPunisher,
Tullock,
TwoTitsForTat,
UsuallyCooperates,
UsuallyDefects,
VeryBad,
Weiner,
White,
Expand Down
62 changes: 62 additions & 0 deletions axelrod/strategies/finite_state_machines.py
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,68 @@ def __init__(self) -> None:
super().__init__(transitions=transitions, initial_state=1, initial_action=D)


class UsuallyCooperates(FSMPlayer):
"""
This strategy cooperates except after a C following a D.

Names:

- Usually Cooperates (UC): [Ashlock2009]_
"""

name = "UsuallyCooperates"
classifier = {
"memory_depth": 2,
"stochastic": False,
"makes_use_of": set(),
"long_run_time": False,
"inspects_source": False,
"manipulates_source": False,
"manipulates_state": False,
}

def __init__(self) -> None:
transitions = (
(1, C, 1, C),
(1, D, 2, C),
(2, C, 1, D),
(2, D, 1, C),
)

super().__init__(transitions=transitions, initial_state=1, initial_action=C)


class UsuallyDefects(FSMPlayer):
"""
This strategy defects except after a D following a C.

Names:

- Usually Defects (UD): [Ashlock2009]_
"""

name = "UsuallyDefects"
classifier = {
"memory_depth": 2,
"stochastic": False,
"makes_use_of": set(),
"long_run_time": False,
"inspects_source": False,
"manipulates_source": False,
"manipulates_state": False,
}

def __init__(self) -> None:
transitions = (
(1, C, 2, D),
(1, D, 1, D),
(2, C, 1, D),
(2, D, 1, C),
)

super().__init__(transitions=transitions, initial_state=1, initial_action=D)


class SolutionB1(FSMPlayer):
"""
FSM player described in http://DOI.org/10.1109/TCIAIG.2014.2326012.
Expand Down
1 change: 1 addition & 0 deletions axelrod/strategies/grudger.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ class Grudger(Player):
- Grim: [Berg2015]_
- Grim Trigger: [Banks1990]_
- Spite: [Beaufils1997]_
- Vengeful: [Ashlock2009]_
"""

name = "Grudger"
Expand Down
1 change: 1 addition & 0 deletions axelrod/strategies/titfortat.py
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,7 @@ class AntiTitForTat(Player):
Names:

- Anti Tit For Tat: [Hilbe2013]_
- Psycho (PSYC): [Ashlock2009]_
"""

name = "Anti Tit For Tat"
Expand Down
66 changes: 66 additions & 0 deletions axelrod/tests/strategies/test_finite_state_machines.py
Original file line number Diff line number Diff line change
Expand Up @@ -512,6 +512,72 @@ def test_strategy(self):
self.transitions_test(state_and_actions)


class TestUsuallyCooperates(TestFSMPlayer):
name = "UsuallyCooperates"
player = axelrod.UsuallyCooperates
expected_classifier = {
"memory_depth": 2,
"stochastic": False,
"makes_use_of": set(),
"long_run_time": False,
"inspects_source": False,
"manipulates_source": False,
"manipulates_state": False,
}
"""
transitions = (
(1, C, 1, C),
(1, D, 2, C),
(2, C, 1, D),
(2, D, 1, C)
)
"""

def test_strategy(self):
# Never leaves state 1 if C
state_and_actions = [(1, C)] * 10
self.transitions_test(state_and_actions)
# Visits state 2, but then comes back
gaffney2010 marked this conversation as resolved.
Show resolved Hide resolved
state_and_actions = [(1, D), (2, D)]
self.transitions_test(state_and_actions)
# Visits state 2, but then comes back
state_and_actions = [(1, D), (2, C)]
self.transitions_test(state_and_actions)


class TestUsuallyDefects(TestFSMPlayer):
name = "UsuallyDefects"
player = axelrod.UsuallyDefects
expected_classifier = {
"memory_depth": 2,
"stochastic": False,
"makes_use_of": set(),
"long_run_time": False,
"inspects_source": False,
"manipulates_source": False,
"manipulates_state": False,
}
"""
transitions = (
(1, C, 2, D),
(1, D, 1, D),
(2, C, 1, D),
(2, D, 1, C)
)
"""

def test_strategy(self):
# Never leaves state 1 if C
gaffney2010 marked this conversation as resolved.
Show resolved Hide resolved
state_and_actions = [(1, D)] * 10
self.transitions_test(state_and_actions)
# Visits state 2, but then comes back
state_and_actions = [(1, C), (2, D)]
self.transitions_test(state_and_actions)
# Visits state 2, but then comes back
state_and_actions = [(1, C), (2, C)]
self.transitions_test(state_and_actions)


class TestSolutionB1(TestFSMPlayer):

name = "SolutionB1"
Expand Down
2 changes: 1 addition & 1 deletion docs/tutorials/advanced/classification_of_strategies.rst
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ range of memory_depth values, we can use the 'min_memory_depth' and
... }
>>> strategies = axl.filtered_strategies(filterset)
>>> len(strategies)
59
61

We can also identify strategies that make use of particular properties of the
tournament. For example, here is the number of strategies that make use of the
Expand Down