From b31de751683db1384556617cbedb649111439ead Mon Sep 17 00:00:00 2001 From: Marc Harper Date: Sat, 29 Jul 2017 03:58:54 -0700 Subject: [PATCH 1/3] Add code snippet to rerun Axelrod's second tournament to readme --- README.rst | 37 +++++++++++++++++++++++++++-------- src/axelrod_fortran/player.py | 3 +-- 2 files changed, 30 insertions(+), 10 deletions(-) diff --git a/README.rst b/README.rst index 4616cfe..51e770a 100644 --- a/README.rst +++ b/README.rst @@ -18,15 +18,36 @@ Installation Usage ===== -:: +Running a match: + +.. code-block:: python + + >>> import axelrod_fortran as axlf + >>> import axelrod as axl + >>> p1 = axlf.Player('k31r') + >>> p2 = axlf.Player('k33r') + >>> match = axl.Match((p1, p2), turns=5) + >>> match.play() + [(C, C), (C, C), (C, D), (C, D), (C, C)] + +Reproducing Axelrod's second tournament: + +.. code-block:: python + + import axelrod as axl + from axelrod_fortran.strategies import characteristics + from axelrod_fortran.player import Player + + players = [Player(name) for name in characteristics.keys() + if characteristics[name]["original_rank"] is not None] + + print(len(players), "players") - >>> import axelrod_fortran as axlf - >>> import axelrod as axl - >>> p1 = axlf.Player('k31r') - >>> p2 = axlf.Player('k33r') - >>> match = axl.Match((p1, p2), turns=5) - >>> match.play() - [(C, C), (C, C), (C, D), (C, D), (C, C)] + tournament = axl.Tournament(players, repetitions=100) + results = tournament.play(processes=4) + results.write_summary('summary.csv') + plot = axl.Plot(results) + plot.save_all_plots("second_tournament") Contributing ============ diff --git a/src/axelrod_fortran/player.py b/src/axelrod_fortran/player.py index 26e50e0..47209ae 100644 --- a/src/axelrod_fortran/player.py +++ b/src/axelrod_fortran/player.py @@ -3,7 +3,6 @@ import axelrod as axl from axelrod.interaction_utils import compute_final_score from axelrod.action import Action -from axelrod import Game from ctypes import cdll, c_int, c_float, byref, POINTER from .strategies import characteristics @@ -49,7 +48,7 @@ def original_name(self, value): if value in characteristics: self.__original_name = value else: - raise ValueError(f'{value} is not a valid Fortran function') + raise ValueError('{} is not a valid Fortran function'.format(value)) @property def original_function(self): From 1f3dfe1fc52a621dd2b8061665d61249653d4656 Mon Sep 17 00:00:00 2001 From: Marc Harper Date: Sat, 29 Jul 2017 04:22:20 -0700 Subject: [PATCH 2/3] Update tournament snippet in readme --- README.rst | 26 ++++++++++++-------------- 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/README.rst b/README.rst index 51e770a..1797c3b 100644 --- a/README.rst +++ b/README.rst @@ -30,24 +30,22 @@ Running a match: >>> match.play() [(C, C), (C, C), (C, D), (C, D), (C, C)] -Reproducing Axelrod's second tournament: +Running an instance of Axelrod's second tournament: .. code-block:: python - import axelrod as axl - from axelrod_fortran.strategies import characteristics - from axelrod_fortran.player import Player - - players = [Player(name) for name in characteristics.keys() - if characteristics[name]["original_rank"] is not None] - - print(len(players), "players") + >>> import axelrod_fortran as axlf + >>> import axelrod as axl + >>> players = [axlf.Player(name) for name in axlf.characteristics.keys() + >>> if axlf.characteristics[name]["original_rank"] is not None] + >>> print(len(players), "players") + 62 players + >>> tournament = axl.Tournament(players, repetitions=1, turns=200) + >>> results = tournament.play() + >>> results.write_summary('summary.csv') + >>> plot = axl.Plot(results) + >>> plot.save_all_plots("second_tournament") - tournament = axl.Tournament(players, repetitions=100) - results = tournament.play(processes=4) - results.write_summary('summary.csv') - plot = axl.Plot(results) - plot.save_all_plots("second_tournament") Contributing ============ From 3b60e9f326d982e69c7b9544bd9f6b0ce5facc6b Mon Sep 17 00:00:00 2001 From: Marc Harper Date: Sat, 29 Jul 2017 04:56:26 -0700 Subject: [PATCH 3/3] Create list for players in the original second tournament --- README.rst | 3 +-- src/axelrod_fortran/__init__.py | 3 ++- src/axelrod_fortran/strategies.py | 5 +++++ 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/README.rst b/README.rst index 1797c3b..64bdd2e 100644 --- a/README.rst +++ b/README.rst @@ -36,8 +36,7 @@ Running an instance of Axelrod's second tournament: >>> import axelrod_fortran as axlf >>> import axelrod as axl - >>> players = [axlf.Player(name) for name in axlf.characteristics.keys() - >>> if axlf.characteristics[name]["original_rank"] is not None] + >>> players = [axlf.Player(name) for name in axlf.second_tournament_strategies] >>> print(len(players), "players") 62 players >>> tournament = axl.Tournament(players, repetitions=1, turns=200) diff --git a/src/axelrod_fortran/__init__.py b/src/axelrod_fortran/__init__.py index 804bf0b..bb675c3 100644 --- a/src/axelrod_fortran/__init__.py +++ b/src/axelrod_fortran/__init__.py @@ -1,4 +1,5 @@ __version__ = "0.1.0" from .player import Player -from .strategies import characteristics, all_strategies +from .strategies import (all_strategies, characteristics, + second_tournament_strategies) diff --git a/src/axelrod_fortran/strategies.py b/src/axelrod_fortran/strategies.py index 481ffab..ec149ff 100644 --- a/src/axelrod_fortran/strategies.py +++ b/src/axelrod_fortran/strategies.py @@ -349,3 +349,8 @@ } all_strategies = characteristics.keys() + +# Players from Axelrod's second tournament. +second_tournament_strategies = [ + name for name in characteristics.keys() + if characteristics[name]["original_rank"] is not None]