Skip to content

Commit 8c59778

Browse files
committed
First first by Grofman.
1 parent 0bf356c commit 8c59778

File tree

4 files changed

+18
-26
lines changed

4 files changed

+18
-26
lines changed

axelrod/strategies/_strategies.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
FirstByDavis,
1010
FirstByFeld,
1111
FirstByGraaskamp,
12-
Grofman,
12+
FirstByGrofman,
1313
Joss,
1414
Nydegger,
1515
RevisedDowning,
@@ -329,7 +329,7 @@
329329
SecondByGraaskampKatzen,
330330
Gradual,
331331
GradualKiller,
332-
Grofman,
332+
FirstByGrofman,
333333
Grudger,
334334
GrudgerAlternator,
335335
Grumpy,

axelrod/strategies/axelrod_first.py

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -349,16 +349,14 @@ def strategy(self, opponent: Player) -> Action:
349349
return C
350350

351351

352-
# TODO Need to check this one, a MoreGrofman existed in
353-
# axelrod_second
354-
class Grofman(Player):
352+
class FirstByGrofman(Player):
355353
"""
356-
Submitted to Axelrod's first tournament by Bernard Grofman.
354+
Submitted to Axelrod's first tournament by Bernard Grofman..
355+
356+
The description written in [Axelrod1980]_ is:
357357
358-
Cooperate on the first two rounds and
359-
returns the opponent's last action for the next 5. For the rest of the game
360-
Grofman cooperates if both players selected the same action in the previous
361-
round, and otherwise cooperates randomly with probability 2/7.
358+
> "If the players did different things on the previous move, this rule
359+
> cooperates with probability 2/7. Otherwise this rule always cooperates."
362360
363361
This strategy came 4th in Axelrod's original tournament.
364362
@@ -367,24 +365,18 @@ class Grofman(Player):
367365
- Grofman: [Axelrod1980]_
368366
"""
369367

370-
name = "Grofman"
368+
name = "First tournament by Grofman"
371369
classifier = {
372-
"memory_depth": float("inf"),
370+
"memory_depth": 1,
373371
"stochastic": True,
374372
"makes_use_of": set(),
375373
"long_run_time": False,
376374
"inspects_source": False,
377375
"manipulates_source": False,
378376
"manipulates_state": False,
379377
}
380-
381378
def strategy(self, opponent: Player) -> Action:
382-
round_number = len(self.history) + 1
383-
if round_number < 3:
384-
return C
385-
if round_number < 8:
386-
return opponent.history[-1]
387-
if self.history[-1] == opponent.history[-1]:
379+
if len(self.history) == 0 or self.history[-1] == opponent.history[-1]:
388380
return C
389381
return random_choice(2 / 7)
390382

axelrod/tests/strategies/test_axelrod_first.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -242,12 +242,12 @@ def test_strategy(self):
242242
)
243243

244244

245-
class TestGrofman(TestPlayer):
245+
class TestFirstByGrofman(TestPlayer):
246246

247-
name = "Grofman"
248-
player = axelrod.Grofman
247+
name = "First tournament by Grofman"
248+
player = axelrod.FirstByGrofman
249249
expected_classifier = {
250-
"memory_depth": float("inf"),
250+
"memory_depth": 1,
251251
"stochastic": True,
252252
"makes_use_of": set(),
253253
"long_run_time": False,
@@ -264,11 +264,11 @@ def test_strategy(self):
264264
self.versus_test(axelrod.Alternator(), expected_actions=actions)
265265

266266
opponent = axelrod.MockPlayer(actions=[D] * 8)
267-
actions = [(C, D)] * 2 + [(D, D)] * 5 + [(C, D)] + [(C, D)]
267+
actions = [(C, D), (C, D), (D, D), (C, D), (D, D), (C, D), (C, D), (D, D)]
268268
self.versus_test(opponent, expected_actions=actions, seed=1)
269269

270270
opponent = axelrod.MockPlayer(actions=[D] * 8)
271-
actions = [(C, D)] * 2 + [(D, D)] * 5 + [(C, D)] + [(D, D)]
271+
actions = [(C, D), (D, D), (C, D), (D, D), (C, D), (C, D), (C, D), (D, D)]
272272
self.versus_test(opponent, expected_actions=actions, seed=2)
273273

274274

docs/reference/overview_of_strategies.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ An indication is given as to whether or not this strategy is implemented in the
1919
"Tit For Tat", "Anatol Rapoport", ":class:`TitForTat <axelrod.strategies.titfortat.TitForTat>`"
2020
"Tideman and Chieruzzi", "T Nicolaus Tideman and Paula Chieruzz", ":class:`TidemanAndChieruzzi <axelrod.strategies.axelrod_first.TidemanAndChieruzzi>`"
2121
"Nydegger", "Rudy Nydegger", ":class:`Nydegger <axelrod.strategies.axelrod_first.Nydegger>`"
22-
"Grofman", "Bernard Grofman", ":class:`Grofman <axelrod.strategies.axelrod_first.Grofman>`"
22+
"Grofman", "Bernard Grofman", ":class:`Grofman <axelrod.strategies.axelrod_first.FirstByGrofman>`"
2323
"Shubik", "Martin Shubik", ":class:`Shubik <axelrod.strategies.axelrod_first.Shubik>`"
2424
"Stein and Rapoport", "Stein and Anatol Rapoport", ":class:`SteinAndRapoport <axelrod.strategies.axelrod_first.SteinAndRapoport>`"
2525
"Grudger", "James W Friedman", ":class:`Grudger <axelrod.strategies.grudger.Grudger>`"

0 commit comments

Comments
 (0)