How to use the axelrod.Tournament function in Axelrod

To help you get started, we’ve selected a few Axelrod examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github Axelrod-Python / tournament / test_utils.py View on Github external
Tests for the utils.py file
"""
import axelrod as axl
import unittest
import utils
import tempfile
import csv

class TestUtils(unittest.TestCase):
    """
    Simple tests for the utils
    """

    axl.seed(0)
    players = [s() for s in axl.demo_strategies]
    tournament = axl.Tournament(players)
    results = tournament.play()

    def test_label(self):
        label = utils.label("Test", self.results)
        expected_label = "{} - turns: {}, repetitions: {}, strategies: {}.  ".format("Test",
                    self.tournament.turns, self.tournament.repetitions,
                    len(self.tournament.players))

    def test_obtain_assets(self):
        """Just test that this runs without crashing"""
        self.assertEqual(utils.obtain_assets(self.results, assets_dir="/tmp"), None)
github Axelrod-Python / Axelrod / axelrod / fingerprint.py View on Github external
A numpy array containing the mean cooperation rate against each
            opponent in each turn. The ith row corresponds to the ith opponent
            and the jth column the jth turn.
        """

        if isinstance(self.strategy, axl.Player):
            players = [self.strategy] + self.opponents
        else:
            players = [self.strategy()] + self.opponents

        temp_file_descriptor = None
        if filename is None:
            temp_file_descriptor, filename = mkstemp()  # type: ignore

        edges = [(0, k + 1) for k in range(len(self.opponents))]
        tournament = axl.Tournament(
            players=players,
            edges=edges,
            turns=turns,
            noise=noise,
            repetitions=repetitions,
        )
        tournament.play(
            filename=filename,
            build_results=False,
            progress_bar=progress_bar,
            processes=processes,
        )

        self.data = self.analyse_cooperation_ratio(filename)

        if temp_file_descriptor is not None:
github Axelrod-Python / tournament / run_noisy.py View on Github external
def main(players=players):
    # Deleting the file if it exists
    try:
        os.remove(filename)
    except OSError:
        pass

    axl.seed(seed)  # Setting a seed

    tournament = axl.Tournament(players, turns=turns, repetitions=repetitions,
                                noise=noise)

    results = tournament.play(filename=filename, processes=processes)
    utils.obtain_assets(results, "strategies", "noisy")
    results.write_summary('assets/noisy_summary.csv')
github Axelrod-Python / Axelrod / docs / tutorials / getting_started / _static / running_axelrods_first_tournament / main.py View on Github external
"""
Script to obtain plots for the running axelrod tournament tutorial.
"""

import axelrod as axl
import matplotlib.pyplot as plt

first_tournament_participants_ordered_by_reported_rank = [
    s() for s in axl.axelrod_first_strategies
]
number_of_strategies = len(
    first_tournament_participants_ordered_by_reported_rank
)
axl.seed(0)
tournament = axl.Tournament(
    players=first_tournament_participants_ordered_by_reported_rank,
    turns=200,
    repetitions=5,
)
results = tournament.play()

plt.figure(figsize=(15, 6))
plt.plot((0, 15), (0, 15), color="grey", linestyle="--")
for original_rank, strategy in enumerate(
    first_tournament_participants_ordered_by_reported_rank
):
    rank = results.ranked_names.index(str(strategy))
    if rank == original_rank:
        symbol = "+"
        plt.plot((rank, rank), (rank, 0), color="grey")
    else:
github Axelrod-Python / tournament / run_std.py View on Github external
def main(players=players):
    # Deleting the file if it exists
    try:
        os.remove(filename)
    except OSError:
        pass

    axl.seed(seed)  # Setting a seed

    tournament = axl.Tournament(players, turns=turns, repetitions=repetitions)

    results = tournament.play(filename=filename, processes=processes)
    utils.obtain_assets(results, "strategies", "std")
    results.write_summary('assets/std_summary.csv')
github Axelrod-Python / Axelrod / axelrod / fingerprint.py View on Github external
----------
        self.data : dict
            A dictionary where the keys are coordinates of the form (x, y) and
            the values are the mean score for the corresponding interactions.
        """

        temp_file_descriptor = None
        if filename is None:
            temp_file_descriptor, filename = mkstemp()  # type: ignore

        edges, tourn_players = self._construct_tournament_elements(
            step, progress_bar=progress_bar
        )

        self.step = step
        self.spatial_tournament = axl.Tournament(
            tourn_players, turns=turns, repetitions=repetitions, edges=edges
        )
        self.spatial_tournament.play(
            build_results=False,
            filename=filename,
            processes=processes,
            progress_bar=progress_bar,
        )

        self.interactions = read_interactions_from_file(
            filename, progress_bar=progress_bar
        )

        if temp_file_descriptor is not None:
            assert filename is not None
            os.close(temp_file_descriptor)
github Axelrod-Python / tournament / run_probend.py View on Github external
def main(players=players):
    # Deleting the file if it exists
    try:
        os.remove(filename)
    except OSError:
        pass

    axl.seed(seed)  # Setting a seed

    tournament = axl.Tournament(players, prob_end=prob_end,
                                repetitions=repetitions)

    results = tournament.play(filename=filename, processes=processes)
    utils.obtain_assets(results, "strategies", "probend", lengthplot=True)
    results.write_summary('assets/probend_summary.csv')