Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: Axelrod-Python/Axelrod
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v4.13.1
Choose a base ref
...
head repository: Axelrod-Python/Axelrod
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: dev
Choose a head ref
  • 19 commits
  • 40 files changed
  • 6 contributors

Commits on Nov 5, 2024

  1. Change cache pattern

    gaffney2010 committed Nov 5, 2024
    Copy the full SHA
    35833ac View commit details
  2. Reduce match init complexity

    gaffney2010 committed Nov 5, 2024
    Copy the full SHA
    f700bae View commit details

Commits on Nov 10, 2024

  1. Normalize -> Normalise (#1452)

    gaffney2010 authored Nov 10, 2024
    Copy the full SHA
    f8391f6 View commit details
  2. Fix the dead links in the README. (#1450)

    * Fix the dead links in the README.
    
    Closes #1449
    
    * Fix remaining links.
    drvinceknight authored Nov 10, 2024
    Copy the full SHA
    6514780 View commit details

Commits on Nov 11, 2024

  1. Run black on match.py

    gaffney2010 committed Nov 11, 2024
    Copy the full SHA
    997444e View commit details
  2. Fix typo

    gaffney2010 committed Nov 11, 2024
    Copy the full SHA
    8c49ea3 View commit details
  3. Fix minor bug, set self.cache on early exit

    gaffney2010 committed Nov 11, 2024
    Copy the full SHA
    9e36c76 View commit details
  4. Run black with line length

    gaffney2010 committed Nov 11, 2024
    Copy the full SHA
    9a5f9da View commit details

Commits on Nov 13, 2024

  1. Create MatchChunk dataclass

    gaffney2010 committed Nov 13, 2024
    Copy the full SHA
    9460cf1 View commit details
  2. Merge pull request #1454 from gaffney2010/match-init

    Reduce match init complexity
    gaffney2010 authored Nov 13, 2024
    Copy the full SHA
    75f6e77 View commit details
  3. run black

    gaffney2010 committed Nov 13, 2024
    Copy the full SHA
    bb0733b View commit details

Commits on Nov 16, 2024

  1. Fix import order

    gaffney2010 committed Nov 16, 2024
    Copy the full SHA
    d0e9984 View commit details

Commits on Nov 21, 2024

  1. Merge pull request #1456 from gaffney2010/match_generator

    Create MatchChunk dataclass
    gaffney2010 authored Nov 21, 2024
    Copy the full SHA
    8b659a6 View commit details

Commits on Nov 30, 2024

  1. Merge pull request #1453 from gaffney2010/change-cache-pattern

    Change cache pattern
    gaffney2010 authored Nov 30, 2024
    Copy the full SHA
    d2184c6 View commit details

Commits on Dec 9, 2024

  1. Improve extend method in LimitedHistory to enforce memory depth (#1458)

    * Improve extend method in LimitedHistory to enforce memory depth
    
    - Updated the extend method in the LimitedHistory class to properly truncate oldest entries when the combined history exceeds the defined memory depth.
    
    - Added a corresponding unit test in axelrod/tests/unit/test_history.py to validate this behavior.
    
    - Formatted all committed files using black for consistent code style.
    
    * Ignore workflow failures by adding suppress_health_check
    - add suppress_health_check to test_equality function in test_game.py to prevent workflow failure in Github remote.
    - Update HealthCheck module import order in test_game.py
    LindyZh authored Dec 9, 2024
    Copy the full SHA
    a7bab91 View commit details

Commits on Jan 10, 2025

  1. Add/update a few citations (#1464)

    marcharper authored Jan 10, 2025
    Copy the full SHA
    cfa5889 View commit details
  2. add freqAnalyzer strategy (#1444)

    * add freqAnalyzer strat
    
    * cleanup + wip
    
    * remove spurious changes
    
    * fixed freq analyzer test
    
    * Delete axelrod/tests/strategies/test_freqanalyzer.py
    
    * bump num strats
    
    * remove unnecessary lines
    
    * fix type error
    
    * fix test
    
    * formatting
    
    * python black with correct options
    
    * add strat to index
    
    * code cleanup
    miller-ian authored Jan 10, 2025
    Copy the full SHA
    684b354 View commit details

Commits on Jan 13, 2025

  1. add original index to summary (#1466)

    * add original index to summary
    
    * formatting
    
    * fix summary test
    
    * rm spurious print statement
    
    * fix failing doctest
    
    * doctest attempt
    
    * attempt
    
    * cleanup
    
    * formatting
    miller-ian authored Jan 13, 2025
    Copy the full SHA
    6a6c8a9 View commit details
  2. Get mypy working again (#1457)

    * Get mypy working again
    
    * Add test for new assert
    
    * Test error string
    
    * Inject get_data for testing
    
    * More typing stuff for mypy to pass
    
    * Ran black
    
    * Added more mypy stuff to plot
    gaffney2010 authored Jan 13, 2025
    Copy the full SHA
    6d2d465 View commit details
Showing with 569 additions and 171 deletions.
  1. +11 −14 README.rst
  2. +2 −2 axelrod/deterministic_cache.py
  3. +3 −3 axelrod/ecosystem.py
  4. +10 −10 axelrod/fingerprint.py
  5. +2 −1 axelrod/game.py
  6. +9 −1 axelrod/history.py
  7. +9 −9 axelrod/interaction_utils.py
  8. +9 −3 axelrod/load_data_.py
  9. +36 −36 axelrod/match.py
  10. +22 −2 axelrod/match_generator.py
  11. +2 −2 axelrod/mock_player.py
  12. +5 −6 axelrod/moran.py
  13. +52 −19 axelrod/plot.py
  14. +4 −0 axelrod/result_set.py
  15. +2 −0 axelrod/strategies/_strategies.py
  16. +2 −2 axelrod/strategies/adaptive.py
  17. +8 −5 axelrod/strategies/ann.py
  18. +3 −1 axelrod/strategies/calculator.py
  19. +4 −4 axelrod/strategies/cycler.py
  20. +8 −8 axelrod/strategies/finite_state_machines.py
  21. +109 −0 axelrod/strategies/frequency_analyzer.py
  22. +2 −2 axelrod/strategies/handshake.py
  23. +2 −2 axelrod/strategies/hmm.py
  24. +3 −3 axelrod/strategies/memoryone.py
  25. +2 −2 axelrod/strategies/prober.py
  26. +159 −0 axelrod/tests/strategies/test_frequency_analyzer.py
  27. +2 −2 axelrod/tests/unit/test_game.py
  28. +11 −0 axelrod/tests/unit/test_history.py
  29. +13 −1 axelrod/tests/unit/test_load_data.py
  30. +2 −2 axelrod/tests/unit/test_match_generator.py
  31. +20 −0 axelrod/tests/unit/test_plot.py
  32. +5 −1 axelrod/tests/unit/test_resultset.py
  33. +4 −2 axelrod/tests/unit/test_tournament.py
  34. +15 −16 axelrod/tournament.py
  35. +5 −3 citations.md
  36. +1 −1 docs/index.rst
  37. +2 −0 docs/reference/strategy_index.rst
  38. +5 −5 docs/tutorials/new_to_game_theory_and_or_python/summarising_tournaments.rst
  39. +1 −1 run_mypy.py
  40. +3 −0 tox.ini
25 changes: 11 additions & 14 deletions README.rst
Original file line number Diff line number Diff line change
@@ -7,8 +7,6 @@
.. image:: https://github.com/Axelrod-Python/Axelrod/workflows/CI/badge.svg
:target: https://github.com/Axelrod-Python/Axelrod/actions

|Join the chat at https://gitter.im/Axelrod-Python/Axelrod|

Axelrod
=======

@@ -32,29 +30,29 @@ Features
With Axelrod you:

- have access `to over 200 strategies
<http://axelrod.readthedocs.io/en/stable/reference/all_strategies.html>`_, including original and classics like Tit
<https://axelrod.readthedocs.io/en/stable/reference/strategy_index.html>`_, including original and classics like Tit
For Tat and Win Stay Lose Shift. These are extendable through parametrization
and a collection of strategy transformers.
- can create `head to head matches
<http://axelrod.readthedocs.io/en/stable/tutorials/getting_started/match.html>`_ between pairs of strategies.
<https://axelrod.readthedocs.io/en/stable/tutorials/new_to_game_theory_and_or_python/match.html>`_ between pairs of strategies.
- can create `tournaments
<http://axelrod.readthedocs.io/en/stable/tutorials/getting_started/tournament.html>`_ over a number of strategies.
<https://axelrod.readthedocs.io/en/stable/tutorials/new_to_game_theory_and_or_python/tournament.html>`_ over a number of strategies.
- can study population dynamics through `Moran processes
<http://axelrod.readthedocs.io/en/stable/tutorials/getting_started/moran.html>`_ and an `infinite
<https://axelrod.readthedocs.io/en/stable/tutorials/new_to_game_theory_and_or_python/moran.html>`_ and an `infinite
population model
<http://axelrod.readthedocs.io/en/stable/tutorials/further_topics/ecological_variant.html>`_.
<https://axelrod.readthedocs.io/en/stable/how-to/run_axelrods_ecological_variant.html>`_.
- can analyse detailed `results of tournaments
<http://axelrod.readthedocs.io/en/stable/tutorials/getting_started/summarising_tournaments.html>`_ and matches.
<https://axelrod.readthedocs.io/en/stable/tutorials/new_to_game_theory_and_or_python/summarising_tournaments.html>`_ and matches.
- can `visualise results
<http://axelrod.readthedocs.io/en/stable/tutorials/getting_started/visualising_results.html>`_ of tournaments.
<https://axelrod.readthedocs.io/en/stable/tutorials/new_to_game_theory_and_or_python/visualising_results.html>`_ of tournaments.

.. image:: http://axelrod.readthedocs.io/en/stable/_images/demo_strategies_boxplot.svg
:height: 300 px
:align: center

- can reproduce a number of contemporary research topics such as `fingerprinting <http://axelrod.readthedocs.io/en/stable/tutorials/further_topics/fingerprinting.html>`_ of
- can reproduce a number of contemporary research topics such as `fingerprinting <https://axelrod.readthedocs.io/en/stable/how-to/fingerprint.html>`_ of
strategies and `morality metrics
<http://axelrod.readthedocs.io/en/stable/tutorials/further_topics/morality_metrics.html>`_.
<https://axelrod.readthedocs.io/en/stable/how-to/calculate_morality_metrics.html>`_.

.. image:: https://github.com/Axelrod-Python/Axelrod-fingerprint/raw/master/assets/Tricky_Defector.png
:height: 300 px
@@ -100,8 +98,7 @@ Examples
--------

- https://github.com/Axelrod-Python/tournament is a tournament pitting all the
strategies in the repository against each other. These results can be easily
viewed at http://axelrod-tournament.readthedocs.org.
strategies in the repository against each other.
- https://github.com/Axelrod-Python/Axelrod-notebooks contains a set of example
Jupyter notebooks.
- https://github.com/Axelrod-Python/Axelrod-fingerprint contains fingerprints
@@ -114,7 +111,7 @@ All contributions are welcome!

You can find helpful instructions about contributing in the
documentation:
https://axelrod.readthedocs.io/en/latest/how-to/contributing/index.html
https://axelrod.readthedocs.io/en/stable/how-to/contributing/index.html

Publications
------------
4 changes: 2 additions & 2 deletions axelrod/deterministic_cache.py
Original file line number Diff line number Diff line change
@@ -14,7 +14,7 @@

import pickle
from collections import UserDict
from typing import List, Tuple
from typing import List, Optional, Tuple

from axelrod import Classifiers

@@ -104,7 +104,7 @@ class DeterministicCache(UserDict):
methods to save/load the cache to/from a file.
"""

def __init__(self, file_name: str = None) -> None:
def __init__(self, file_name: Optional[str] = None) -> None:
"""Initialize a new cache.
Parameters
6 changes: 3 additions & 3 deletions axelrod/ecosystem.py
Original file line number Diff line number Diff line change
@@ -12,7 +12,7 @@
"""

import random
from typing import Callable, List
from typing import Callable, List, Optional

from axelrod.result_set import ResultSet

@@ -29,8 +29,8 @@ class Ecosystem(object):
def __init__(
self,
results: ResultSet,
fitness: Callable[[float], float] = None,
population: List[int] = None,
fitness: Optional[Callable[[float], float]] = None,
population: Optional[List[int]] = None,
) -> None:
"""Create a new ecosystem.
20 changes: 10 additions & 10 deletions axelrod/fingerprint.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import os
from collections import namedtuple
from tempfile import mkstemp
from typing import Any, List, Union
from typing import Any, List, Optional, Union

import dask.dataframe as dd
import matplotlib.pyplot as plt
@@ -280,10 +280,10 @@ def fingerprint(
turns: int = 50,
repetitions: int = 10,
step: float = 0.01,
processes: int = None,
filename: str = None,
processes: Optional[int] = None,
filename: Optional[str] = None,
progress_bar: bool = True,
seed: int = None,
seed: Optional[int] = None,
) -> dict:
"""Build and play the spatial tournament.
@@ -358,7 +358,7 @@ def plot(
self,
cmap: str = "seismic",
interpolation: str = "none",
title: str = None,
title: Optional[str] = None,
colorbar: bool = True,
labels: bool = True,
) -> plt.Figure:
@@ -437,11 +437,11 @@ def fingerprint(
self,
turns: int = 50,
repetitions: int = 1000,
noise: float = None,
processes: int = None,
filename: str = None,
noise: Optional[float] = None,
processes: Optional[int] = None,
filename: Optional[str] = None,
progress_bar: bool = True,
seed: int = None,
seed: Optional[int] = None,
) -> np.ndarray:
"""Creates a spatial tournament to run the necessary matches to obtain
fingerprint data.
@@ -556,7 +556,7 @@ def plot(
self,
cmap: str = "viridis",
interpolation: str = "none",
title: str = None,
title: Optional[str] = None,
colorbar: bool = True,
labels: bool = True,
display_names: bool = False,
3 changes: 2 additions & 1 deletion axelrod/game.py
Original file line number Diff line number Diff line change
@@ -2,6 +2,7 @@
from typing import Tuple, Union

import numpy as np
import numpy.typing as npt

from axelrod import Action

@@ -20,7 +21,7 @@ class AsymmetricGame(object):
"""

# pylint: disable=invalid-name
def __init__(self, A: np.array, B: np.array) -> None:
def __init__(self, A: npt.NDArray, B: npt.NDArray) -> None:
"""
Creates an asymmetric game from two matrices.
10 changes: 9 additions & 1 deletion axelrod/history.py
Original file line number Diff line number Diff line change
@@ -117,8 +117,8 @@ def __init__(self, memory_depth, plays=None, coplays=None):
memory_depth, int:
length of history to retain
"""
super().__init__(plays=plays, coplays=coplays)
self.memory_depth = memory_depth
super().__init__(plays=plays, coplays=coplays)

def flip_plays(self):
"""Creates a flipped plays history for use with DualTransformer."""
@@ -138,3 +138,11 @@ def append(self, play, coplay):
first_play, first_coplay = self._plays.pop(0), self._coplays.pop(0)
self._actions[first_play] -= 1
self._state_distribution[(first_play, first_coplay)] -= 1

def extend(self, new_plays, new_coplays):
"""A function that emulates list.extend, respecting the stated memory depth."""
self._plays.extend(new_plays)
self._coplays.extend(new_coplays)
if len(self._plays) > self.memory_depth:
self._plays = self._plays[-self.memory_depth :]
self._coplays = self._coplays[-self.memory_depth :]
18 changes: 9 additions & 9 deletions axelrod/interaction_utils.py
Original file line number Diff line number Diff line change
@@ -117,7 +117,7 @@ def compute_state_distribution(interactions):

def compute_normalised_state_distribution(interactions):
"""
Returns the normalized count of each state for a set of interactions.
Returns the normalised count of each state for a set of interactions.
Parameters
----------
@@ -127,8 +127,8 @@ def compute_normalised_state_distribution(interactions):
Returns
----------
normalized_count : Counter Object
Dictionary where the keys are the states and the values are a normalized
normalised_count : Counter Object
Dictionary where the keys are the states and the values are a normalised
count of the number of times that state occurs.
"""
if not interactions:
@@ -137,10 +137,10 @@ def compute_normalised_state_distribution(interactions):
interactions_count = Counter(interactions)
total = sum(interactions_count.values(), 0)

normalized_count = Counter(
normalised_count = Counter(
{key: value / total for key, value in interactions_count.items()}
)
return normalized_count
return normalised_count


def compute_state_to_action_distribution(interactions):
@@ -213,14 +213,14 @@ def compute_normalised_state_to_action_distribution(interactions):
-------
normalised_state_to_C_distributions : List of Counter Object
List of Counter objects where the keys are the states and actions and
the values the normalized counts. The first/second Counter corresponds
the values the normalised counts. The first/second Counter corresponds
to the first/second player.
"""
if not interactions:
return None

distribution = compute_state_to_action_distribution(interactions)
normalized_distribution = []
normalised_distribution = []
for player in range(2):
counter = {}
for state in [(C, C), (C, D), (D, C), (D, D)]:
@@ -232,8 +232,8 @@ def compute_normalised_state_to_action_distribution(interactions):
counter[(state, C)] = C_count / (C_count + D_count)
if D_count > 0:
counter[(state, D)] = D_count / (C_count + D_count)
normalized_distribution.append(Counter(counter))
return normalized_distribution
normalised_distribution.append(Counter(counter))
return normalised_distribution


def sparkline(actions, c_symbol="█", d_symbol=" "):
12 changes: 9 additions & 3 deletions axelrod/load_data_.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import pathlib
import pkgutil
from typing import Dict, List, Text, Tuple
from typing import Callable, Dict, List, Optional, Tuple


def axl_filename(path: pathlib.Path) -> pathlib.Path:
@@ -20,12 +20,18 @@ def axl_filename(path: pathlib.Path) -> pathlib.Path:
return axl_path / path


def load_file(filename: str, directory: str) -> List[List[str]]:
def load_file(
filename: str,
directory: str,
get_data: Callable[[str, str], Optional[bytes]] = pkgutil.get_data,
) -> List[List[str]]:
"""Loads a data file stored in the Axelrod library's data subdirectory,
likely for parameters for a strategy."""

path = str(pathlib.Path(directory) / filename)
data_bytes = pkgutil.get_data(__name__, path)
data_bytes = get_data(__name__, path)
if data_bytes is None:
raise FileNotFoundError(f"Some loader issue for path {path}")
data = data_bytes.decode("UTF-8", "replace")

rows = []
Loading