Skip to content

Commit 8f64b6a

Browse files
committed
Add EasyGo strategy
1 parent 32c228c commit 8f64b6a

File tree

3 files changed

+61
-1
lines changed

3 files changed

+61
-1
lines changed

axelrod/strategies/_strategies.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
HardGoByMajority5)
3030
from .gradualkiller import GradualKiller
3131
from .grudger import (Grudger, ForgetfulGrudger, OppositeGrudger, Aggravater,
32-
SoftGrudger, GrudgerAlternator)
32+
SoftGrudger, GrudgerAlternator, EasyGo)
3333
from .grumpy import Grumpy
3434
from .handshake import Handshake
3535
from .hunter import (
@@ -97,6 +97,7 @@
9797
DefectorHunter,
9898
Desperate,
9999
DoubleCrosser,
100+
EasyGo,
100101
Eatherley,
101102
EventualCycleHunter,
102103
Feld,

axelrod/strategies/grudger.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,3 +201,32 @@ def strategy(self, opponent):
201201
if self.history[-1] == Actions.C:
202202
return Actions.D
203203
return Actions.C
204+
205+
206+
207+
class EasyGo(Player):
208+
"""
209+
A player starts by defecting however will cooperate if at any point the opponent has defected.
210+
211+
Names:
212+
213+
- Easy Go [PRISON1998]_
214+
"""
215+
216+
name = 'EasyGo'
217+
classifier = {
218+
'memory_depth': float('inf'), # Long memory
219+
'stochastic': False,
220+
'makes_use_of': set(),
221+
'long_run_time': False,
222+
'inspects_source': False,
223+
'manipulates_source': False,
224+
'manipulates_state': False
225+
}
226+
227+
@staticmethod
228+
def strategy(opponent):
229+
"""Begins by playing D, then plays C for the remaining rounds if the opponent ever plays D."""
230+
if opponent.defections:
231+
return C
232+
return D

axelrod/tests/unit/test_grudger.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,3 +227,33 @@ def test_starategy_random_number_rounds(self):
227227
my_hist = [C] * (i + 1)
228228
expected_response = [D if r % 2 == 0 else C for r in range(j)]
229229
self.responses_test(my_hist, opp_hist, expected_response)
230+
231+
232+
233+
234+
class TestEasyGo(TestPlayer):
235+
236+
name = "EasyGo"
237+
player = axelrod.EasyGo
238+
expected_classifier = {
239+
'memory_depth': float('inf'), # Long memory
240+
'stochastic': False,
241+
'makes_use_of': set(),
242+
'long_run_time': False,
243+
'inspects_source': False,
244+
'manipulates_source': False,
245+
'manipulates_state': False
246+
}
247+
248+
def test_initial_strategy(self):
249+
"""
250+
Starts by cooperating
251+
"""
252+
self.first_play_test(D)
253+
254+
def test_strategy(self):
255+
"""
256+
If opponent defects at any point then the player will cooperate forever
257+
"""
258+
self.responses_test([C, D, D, D], [C, C, C, C], [D])
259+
self.responses_test([C, C, D, D, D], [C, D, C, C, C], [C])

0 commit comments

Comments
 (0)