예제 #1
0
    def test_init_from_resulsetfromfile(self):
        tmp_file = tempfile.NamedTemporaryFile(mode='w', delete=False)
        tournament = axelrod.Tournament(players=[
            axelrod.Cooperator(),
            axelrod.TitForTat(),
            axelrod.Defector()
        ],
                                        turns=2,
                                        repetitions=2)
        tournament.play(filename=tmp_file.name, progress_bar=False)
        tmp_file.close()
        rs = axelrod.ResultSetFromFile(tmp_file.name, progress_bar=False)

        plot = axelrod.Plot(rs)
        self.assertEqual(plot.result_set, rs)
예제 #2
0
    def test_init(self):
        tournament = axelrod.Tournament(
            name=self.test_name,
            players=self.players,
            game=self.game,
            turns=self.test_turns,
            processes=4,
            noise=0.2)
        self.assertEqual(len(tournament.players), len(test_strategies))
        self.assertIsInstance(
            tournament.players[0].match_attributes['game'], axelrod.Game
        )
        self.assertEqual(tournament.game.score(('C', 'C')), (3, 3))
        self.assertEqual(tournament.turns, self.test_turns)
        self.assertEqual(tournament.repetitions, 10)
        self.assertEqual(tournament.name, 'test')
        self.assertEqual(tournament._processes, 4)
        self.assertTrue(tournament._with_morality)
        self.assertIsInstance(tournament._logger, logging.Logger)
        self.assertEqual(tournament.deterministic_cache, {})
        self.assertEqual(tournament.noise, 0.2)
        self.assertEqual(tournament._parallel_repetitions, 10)
        anonymous_tournament = axelrod.Tournament(players=self.players)
        self.assertEqual(anonymous_tournament.name, 'axelrod')

        # Test init when passing a cache:
        cache = axelrod.DeterministicCache()
        tournament = axelrod.Tournament(
            name=self.test_name,
            players=self.players,
            game=self.game,
            turns=self.test_turns,
            processes=4,
            noise=0.2,
            deterministic_cache=cache)
        self.assertEqual(tournament.deterministic_cache, cache)
예제 #3
0
    def test_complete_tournament(self, strategies, turns, repetitions,
                                 noise, seed):
        """
        A test to check that a spatial tournament on the complete multigraph
        gives the same results as the round robin.
        """

        players = [s() for s in strategies]
        # edges
        edges = []
        for i in range(0, len(players)):
            for j in range(i, len(players)):
                edges.append((i, j))

        # create a round robin tournament
        tournament = axelrod.Tournament(players, repetitions=repetitions,
                                        turns=turns, noise=noise)
        # create a complete spatial tournament
        spatial_tournament = axelrod.SpatialTournament(players,
                                                       repetitions=repetitions,
                                                       turns=turns,
                                                       noise=noise,
                                                       edges=edges)

        axelrod.seed(seed)
        results = tournament.play(progress_bar=False)
        axelrod.seed(seed)
        spatial_results = spatial_tournament.play(progress_bar=False)

        self.assertEqual(results.ranked_names, spatial_results.ranked_names)
        self.assertEqual(results.nplayers, spatial_results.nplayers)
        self.assertEqual(results.repetitions, spatial_results.repetitions)
        self.assertEqual(results.payoff_diffs_means,
                         spatial_results.payoff_diffs_means)
        self.assertEqual(results.payoff_matrix, spatial_results.payoff_matrix)
        self.assertEqual(results.payoff_stddevs, spatial_results.payoff_stddevs)
        self.assertEqual(results.payoffs, spatial_results.payoffs)
        self.assertEqual(results.cooperating_rating,
                         spatial_results.cooperating_rating)
        self.assertEqual(results.cooperation, spatial_results.cooperation)
        self.assertEqual(results.normalised_cooperation,
                         spatial_results.normalised_cooperation)
        self.assertEqual(results.normalised_scores,
                         spatial_results.normalised_scores)
        self.assertEqual(results.good_partner_matrix,
                         spatial_results.good_partner_matrix)
        self.assertEqual(results.good_partner_rating,
                         spatial_results.good_partner_rating)
예제 #4
0
 def test_write_to_csv(self):
     tournament = axelrod.Tournament(name=self.test_name,
                                     players=self.players,
                                     game=self.game,
                                     turns=2,
                                     repetitions=2)
     tournament.play(filename=self.filename, progress_bar=False)
     with open(self.filename, 'r') as f:
         written_data = [[int(r[0]), int(r[1])] + r[2:]
                         for r in csv.reader(f)]
         expected_data = [
             [0, 1, 'Cooperator', 'Tit For Tat', 'CC', 'CC'],
             [0, 1, 'Cooperator', 'Tit For Tat', 'CC', 'CC'],
             [1, 2, 'Tit For Tat', 'Defector', 'CD', 'DD'],
             [1, 2, 'Tit For Tat', 'Defector', 'CD', 'DD'],
             [0, 0, 'Cooperator', 'Cooperator', 'CC', 'CC'],
             [0, 0, 'Cooperator', 'Cooperator', 'CC', 'CC'],
             [3, 3, 'Grudger', 'Grudger', 'CC', 'CC'],
             [3, 3, 'Grudger', 'Grudger', 'CC', 'CC'],
             [2, 2, 'Defector', 'Defector', 'DD', 'DD'],
             [2, 2, 'Defector', 'Defector', 'DD', 'DD'],
             [
                 4, 4, 'Soft Go By Majority', 'Soft Go By Majority', 'CC',
                 'CC'
             ],
             [
                 4, 4, 'Soft Go By Majority', 'Soft Go By Majority', 'CC',
                 'CC'
             ], [1, 4, 'Tit For Tat', 'Soft Go By Majority', 'CC', 'CC'],
             [1, 4, 'Tit For Tat', 'Soft Go By Majority', 'CC', 'CC'],
             [1, 1, 'Tit For Tat', 'Tit For Tat', 'CC', 'CC'],
             [1, 1, 'Tit For Tat', 'Tit For Tat', 'CC', 'CC'],
             [1, 3, 'Tit For Tat', 'Grudger', 'CC', 'CC'],
             [1, 3, 'Tit For Tat', 'Grudger', 'CC', 'CC'],
             [2, 3, 'Defector', 'Grudger', 'DD', 'CD'],
             [2, 3, 'Defector', 'Grudger', 'DD', 'CD'],
             [0, 4, 'Cooperator', 'Soft Go By Majority', 'CC', 'CC'],
             [0, 4, 'Cooperator', 'Soft Go By Majority', 'CC', 'CC'],
             [2, 4, 'Defector', 'Soft Go By Majority', 'DD', 'CD'],
             [2, 4, 'Defector', 'Soft Go By Majority', 'DD', 'CD'],
             [0, 3, 'Cooperator', 'Grudger', 'CC', 'CC'],
             [0, 3, 'Cooperator', 'Grudger', 'CC', 'CC'],
             [3, 4, 'Grudger', 'Soft Go By Majority', 'CC', 'CC'],
             [3, 4, 'Grudger', 'Soft Go By Majority', 'CC', 'CC'],
             [0, 2, 'Cooperator', 'Defector', 'CC', 'DD'],
             [0, 2, 'Cooperator', 'Defector', 'CC', 'DD']
         ]
         self.assertEqual(sorted(written_data), sorted(expected_data))
예제 #5
0
def simulate_tournament_utility(player, opponents, turns=500, repetitions=200):
    """
    Returns the simulated utility of a memory one strategy in a tournament.
    """

    strategies = [axl.MemoryOnePlayer(p)
                  for p in opponents] + [axl.MemoryOnePlayer(player)]
    number_of_players = len(strategies)
    edges = [(i, number_of_players - 1) for i in range(number_of_players - 1)]
    tournament = axl.Tournament(players=strategies,
                                turns=turns,
                                repetitions=repetitions,
                                edges=edges)
    results = tournament.play(progress_bar=False)

    return np.mean(results.normalised_scores[-1])
예제 #6
0
 def test_run_parallel_repetitions(self):
     outcome = {'payoff': [], 'cooperation': []}
     tournament = axelrod.Tournament(
         name=self.test_name,
         players=self.players,
         game=self.game,
         turns=200,
         repetitions=self.test_repetitions,
         processes=2)
     tournament._run_parallel_repetitions(outcome)
     self.assertEqual(len(outcome['payoff']), self.test_repetitions)
     self.assertEqual(len(outcome['cooperation']), self.test_repetitions)
     for r in range(self.test_repetitions):
         self.assertEqual(outcome['payoff'][r], self.expected_payoff)
         self.assertEqual(
             outcome['cooperation'][r], self.expected_cooperation)
예제 #7
0
    def test_property_serial_play(self, s, turns, repetitions, rm):
        """Test serial play using hypothesis"""
        # Test that we get an instance of ResultSet
        players = [strat() for strat in s]

        tournament = axelrod.Tournament(
            name=self.test_name,
            players=players,
            game=self.game,
            turns=turns,
            repetitions=repetitions)
        results = tournament.play()
        self.assertIsInstance(results, axelrod.ResultSet)
        self.assertEqual(len(results.cooperation), len(players))
        self.assertEqual(results.nplayers, len(players))
        self.assertEqual(results.players, players)
예제 #8
0
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')
예제 #9
0
 def test_read_interactions_from_file(self):
     tmp_file = tempfile.NamedTemporaryFile(mode='w', delete=False)
     players = [axelrod.Cooperator(),
                axelrod.Defector()]
     tournament = axelrod.Tournament(players=players, turns=2, repetitions=3)
     tournament.play(filename=tmp_file.name)
     tmp_file.close()
     expected_interactions = {(0, 0): [[('C', 'C'), ('C', 'C')] for _ in
                                       range(3)],
                              (0, 1): [[('C', 'D'), ('C', 'D')] for _ in
                                       range(3)],
                              (1, 1): [[('D', 'D'), ('D', 'D')] for _ in
                                       range(3)]}
     interactions = iu.read_interactions_from_file(tmp_file.name,
                                                   progress_bar=False)
     self.assertEqual(expected_interactions, interactions)
예제 #10
0
 def test_matches_have_different_length(self):
     """
     A match between two players should have variable length across the
     repetitions
     """
     p1 = axl.Cooperator()
     p2 = axl.Cooperator()
     p3 = axl.Cooperator()
     players = [p1, p2, p3]
     tournament = axl.Tournament(players,
                                 prob_end=0.5,
                                 repetitions=2,
                                 seed=3)
     results = tournament.play(progress_bar=False)
     # Check that match length are different across the repetitions
     self.assertNotEqual(results.match_lengths[0], results.match_lengths[1])
예제 #11
0
    def test_no_build_result_set(self):
        tournament = axelrod.Tournament(name=self.test_name,
                                        players=self.players,
                                        game=self.game,
                                        turns=200,
                                        repetitions=self.test_repetitions)

        tmp_file = tempfile.NamedTemporaryFile(mode='w', delete=False)
        results = tournament.play(build_results=False,
                                  filename=tmp_file.name,
                                  progress_bar=False)
        self.assertIsNone(results)

        # Checking that results were written properly
        results = axelrod.ResultSetFromFile(tmp_file.name)
        self.assertIsInstance(results, axelrod.ResultSet)
예제 #12
0
    def test_run_serial(self):
        tournament = axl.Tournament(
            name=self.test_name,
            players=self.players,
            game=self.game,
            turns=axl.DEFAULT_TURNS,
            repetitions=self.test_repetitions,
        )
        tournament._write_interactions_to_file = MagicMock(
            name="_write_interactions_to_file"
        )
        self.assertTrue(tournament._run_serial())

        # Get the calls made to write_interactions
        calls = tournament._write_interactions_to_file.call_args_list
        self.assertEqual(len(calls), 15)
예제 #13
0
 def test_write_to_csv_without_results(self):
     tournament = axl.Tournament(
         name=self.test_name,
         players=self.players,
         game=self.game,
         turns=2,
         repetitions=2,
     )
     tournament.play(filename=self.filename,
                     progress_bar=False,
                     build_results=False)
     df = pd.read_csv(self.filename)
     path = pathlib.Path(
         "test_outputs/expected_test_tournament_no_results.csv")
     expected_df = pd.read_csv(axl_filename(path))
     self.assertTrue(df.equals(expected_df))
예제 #14
0
 def test_process_done_queue(self):
     workers = 2
     done_queue = Queue()
     matches = []
     tournament = axelrod.Tournament(
         name=self.test_name,
         players=self.players,
         game=self.game,
         turns=200,
         repetitions=self.test_repetitions)
     for r in range(self.test_repetitions):
         done_queue.put({})
     for w in range(workers):
         done_queue.put('STOP')
     tournament._process_done_queue(workers, done_queue, matches)
     self.assertEqual(len(matches), self.test_repetitions)
예제 #15
0
    def test_specific_set_of_results(self):
        """
        This tests specific reported results as discussed in
        https://github.com/Axelrod-Python/Axelrod/issues/1294

        The results there used a version of mistrust with a bug that corresponds
        to a memory one player that start by defecting and only cooperates if
        both players cooperated in the previous round.
        """
        mistrust_with_bug = axl.MemoryOnePlayer(
            initial=D,
            four_vector=(1, 0, 0, 0),
        )
        players = [
            self.player(),
            axl.TitForTat(),
            axl.GoByMajority(),
            axl.Grudger(),
            axl.WinStayLoseShift(),
            axl.Prober(),
            axl.Defector(),
            mistrust_with_bug,
            axl.Cooperator(),
            axl.CyclerCCD(),
            axl.CyclerDDC(),
        ]
        axl.seed(1)
        tournament = axl.Tournament(players, turns=1000, repetitions=1)
        results = tournament.play(progress_bar=False)
        scores = [
            round(average_score_per_turn * 1000, 1)
            for average_score_per_turn in results.payoff_matrix[0]
        ]
        expected_scores = [
            3000.0,
            3000.0,
            3000.0,
            3000.0,
            3000.0,
            2999.0,
            983.0,
            983.0,
            3000.0,
            3596.0,
            2302.0,
        ]
        self.assertEqual(scores, expected_scores)
예제 #16
0
파일: Game.py 프로젝트: lijiyao919/IPD-RL
def playWithHete(TD, DP, MC):
    ccPercent = [[0], [0], [0]]
    ccCnt = 0
    players = [TD, DP]
    match = axl.Match(players, turns=10000)
    result = match.play()
    # print result
    for i in range(1, 10000):
        if result[i] == ('C', 'C'):
            ccCnt += 1
        ccPercent[0].append(ccCnt / i)

    ccCnt = 0
    players = [TD, MC]
    match = axl.Match(players, turns=10000)
    result = match.play()
    # print result
    for i in range(1, 10000):
        if result[i] == ('C', 'C'):
            ccCnt += 1
        ccPercent[1].append(ccCnt / i)

    ccCnt = 0
    players = [DP, MC]
    match = axl.Match(players, turns=10000)
    result = match.play()
    # print result
    for i in range(1, 10000):
        if result[i] == ('C', 'C'):
            ccCnt += 1
        ccPercent[2].append(ccCnt / i)

    print ccPercent[0]
    print len(ccPercent[0])
    print ccPercent[1]
    print len(ccPercent[1])
    print ccPercent[2]
    print len(ccPercent[2])
    drawCCPercent(ccPercent, False)

    # heat graph
    players = [TD, DP, MC]
    tournament = axl.Tournament(players, turns=10000)
    results = tournament.play()
    plot = axl.Plot(results)
    p = plot.payoff()
    p.savefig("heat graph")
예제 #17
0
파일: property.py 프로젝트: DPros/Axelrod
def prob_end_tournaments(
    draw,
    strategies=axl.short_run_time_strategies,
    min_size=1,
    max_size=10,
    min_prob_end=0,
    max_prob_end=1,
    min_noise=0,
    max_noise=1,
    min_repetitions=1,
    max_repetitions=20,
):
    """
    A hypothesis decorator to return a tournament,

    Parameters
    ----------
    min_size : integer
        The minimum number of strategies to include
    max_size : integer
        The maximum number of strategies to include
    min_prob_end : float
        The minimum probability of a match ending
    max_prob_end : float
        The maximum probability of a match ending
    min_noise : float
        The minimum noise value
    max_noise : float
        The maximum noise value
    min_repetitions : integer
        The minimum number of repetitions
    max_repetitions : integer
        The maximum number of repetitions
    """
    strategies = draw(
        strategy_lists(strategies=strategies, min_size=min_size, max_size=max_size)
    )
    players = [s() for s in strategies]
    prob_end = draw(floats(min_value=min_prob_end, max_value=max_prob_end))
    repetitions = draw(integers(min_value=min_repetitions, max_value=max_repetitions))
    noise = draw(floats(min_value=min_noise, max_value=max_noise))

    tournament = axl.Tournament(
        players, prob_end=prob_end, repetitions=repetitions, noise=noise
    )
    return tournament
예제 #18
0
 def test_one_turn_tournament(self, tournament, seed):
     """
     Tests that gives same result as the corresponding spatial round robin
     spatial tournament
     """
     prob_end_tour = axelrod.Tournament(tournament.players,
                                        prob_end=1,
                                        edges=tournament.edges,
                                        repetitions=tournament.repetitions)
     axelrod.seed(seed)
     prob_end_results = prob_end_tour.play(progress_bar=False)
     axelrod.seed(seed)
     one_turn_results = tournament.play(progress_bar=False)
     self.assertEqual(prob_end_results.scores, one_turn_results.scores)
     self.assertEqual(prob_end_results.wins, one_turn_results.wins)
     self.assertEqual(prob_end_results.cooperation,
                      one_turn_results.cooperation)
예제 #19
0
    def test_no_build_result_set(self):
        tournament = axelrod.Tournament(name=self.test_name,
                                        players=self.players,
                                        game=self.game,
                                        turns=axelrod.DEFAULT_TURNS,
                                        repetitions=self.test_repetitions)

        tournament._calculate_results = MagicMock(name='_calculate_results')
        # Mocking this as it is called by play
        self.assertIsNone(
            tournament.play(filename=self.filename,
                            progress_bar=False,
                            build_results=False))

        # Get the calls made to write_interactions
        calls = tournament._calculate_results.call_args_list
        self.assertEqual(len(calls), 0)
예제 #20
0
    def test_write_interactions(self):
        tournament = axelrod.Tournament(name=self.test_name,
                                        players=self.players,
                                        game=self.game,
                                        turns=2,
                                        repetitions=2)
        tournament._write_interactions_to_file = MagicMock(
            name='_write_interactions_to_file')
        # Mocking this as it is called by play
        self.assertIsNone(
            tournament.play(filename=self.filename,
                            progress_bar=False,
                            build_results=False))

        # Get the calls made to write_interactions
        calls = tournament._write_interactions_to_file.call_args_list
        self.assertEqual(len(calls), 15)
예제 #21
0
 def test_init(self):
     tournament = axelrod.Tournament(name=self.test_name,
                                     players=self.players,
                                     game=self.game,
                                     prob_end=self.test_prob_end,
                                     edges=self.test_edges,
                                     noise=0.2)
     self.assertEqual(tournament.match_generator.edges, tournament.edges)
     self.assertEqual(len(tournament.players), len(test_strategies))
     self.assertEqual(tournament.game.score((C, C)), (3, 3))
     self.assertIsNone(tournament.turns)
     self.assertEqual(tournament.repetitions, 10)
     self.assertEqual(tournament.name, 'test')
     self.assertIsInstance(tournament._logger, logging.Logger)
     self.assertEqual(tournament.noise, 0.2)
     self.assertEqual(tournament.match_generator.noise, 0.2)
     self.assertEqual(tournament.prob_end, self.test_prob_end)
예제 #22
0
    def get_test_outcome(cls, outcome, turns=10):
        # Extract the name of players from the outcome tuples,
        # and initiate the players by getting the classes from axelrod.
        names = [out[0] for out in outcome]
        players = [getattr(axl, n)() for n in names]

        # Play the tournament and build the actual outcome tuples.
        tournament = axl.Tournament(players=players,
                                    game=cls.game,
                                    turns=turns,
                                    repetitions=1)
        results = tournament.play(progress_bar=False)
        scores = [score[0] for score in results.scores]
        outcome = zip(names, scores)

        # Return the outcome sorted by score
        return sorted(outcome, key=lambda k: k[1])
예제 #23
0
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')
예제 #24
0
파일: Game.py 프로젝트: lijiyao919/IPD-RL
def playWithFixed(TD, DP, MC):
    C = axl.Cooperator()
    D = axl.Defector()
    TFT = axl.TitForTat()
    BUL = axl.Bully()
    PAV = Pavlov()
    APAV = axl.APavlov2011()

    for learner in [TD,DP,MC]:
        players = [C, D, TFT, BUL, PAV, APAV, learner]
        tournament = axl.Tournament(players, turns=10000)
        results = tournament.play()

        title = learner.name + " VS Fixed Strategy Players"
        plot = axl.Plot(results)
        p = plot.boxplot(title)
        p.savefig(learner.name)
예제 #25
0
 def test_repeat_tournament_stochastic(self):
     """
     A test to check that tournament gives same results when setting seed.
     """
     files = []
     for _ in range(2):
         axelrod.seed(0)
         stochastic_players = [s() for s in axelrod.strategies
                               if s().classifier['stochastic']]
         tournament = axelrod.Tournament(name='test',
                                         players=stochastic_players,
                                         game=self.game, turns=2,
                                         repetitions=2)
         files.append("test_outputs/stochastic_tournament_{}.csv".format(_))
         tournament.play(progress_bar=False, filename=files[-1],
                         build_results=False)
     self.assertTrue(filecmp.cmp(files[0], files[1]))
예제 #26
0
    def test_write_interactions(self):
        tmp_file = tempfile.NamedTemporaryFile(mode='w', delete=False)
        tournament = axelrod.Tournament(name=self.test_name,
                                        players=self.players,
                                        game=self.game,
                                        turns=2,
                                        repetitions=2)
        tournament._write_interactions = MagicMock(name='_write_interactions')
        tournament._build_result_set = MagicMock(
            name='_build_result_set')  # Mocking this as it is called by play
        self.assertTrue(
            tournament.play(filename=tmp_file.name, progress_bar=False))
        tournament.outputfile.close(
        )  # This is normally closed by `build_result_set`

        # Get the calls made to write_interactions
        calls = tournament._write_interactions.call_args_list
        self.assertEqual(len(calls), 15)
예제 #27
0
 def test_init(self):
     tournament = axelrod.ProbEndTournament(name=self.test_name,
                                            players=self.players,
                                            game=self.game,
                                            prob_end=self.test_prob_end,
                                            noise=0.2)
     self.assertEqual(tournament.match_generator.prob_end,
                      tournament.prob_end)
     self.assertEqual(len(tournament.players), len(test_strategies))
     self.assertEqual(tournament.game.score(('C', 'C')), (3, 3))
     self.assertEqual(tournament.turns, float("inf"))
     self.assertEqual(tournament.repetitions, 10)
     self.assertEqual(tournament.name, 'test')
     self.assertTrue(tournament._with_morality)
     self.assertIsInstance(tournament._logger, logging.Logger)
     self.assertEqual(tournament.noise, 0.2)
     anonymous_tournament = axelrod.Tournament(players=self.players)
     self.assertEqual(anonymous_tournament.name, 'axelrod')
예제 #28
0
파일: property.py 프로젝트: DPros/Axelrod
def tournaments(
    draw,
    strategies=axl.short_run_time_strategies,
    min_size=1,
    max_size=10,
    min_turns=1,
    max_turns=200,
    min_noise=0,
    max_noise=1,
    min_repetitions=1,
    max_repetitions=20,
):
    """
    A hypothesis decorator to return a tournament.

    Parameters
    ----------
    min_size : integer
        The minimum number of strategies to include
    max_size : integer
        The maximum number of strategies to include
    min_turns : integer
        The minimum number of turns
    max_turns : integer
        The maximum number of turns
    min_noise : float
        The minimum noise value
    min_noise : float
        The maximum noise value
    min_repetitions : integer
        The minimum number of repetitions
    max_repetitions : integer
        The maximum number of repetitions
    """
    strategies = draw(
        strategy_lists(strategies=strategies, min_size=min_size, max_size=max_size)
    )
    players = [s() for s in strategies]
    turns = draw(integers(min_value=min_turns, max_value=max_turns))
    repetitions = draw(integers(min_value=min_repetitions, max_value=max_repetitions))
    noise = draw(floats(min_value=min_noise, max_value=max_noise))

    tournament = axl.Tournament(players, turns=turns, repetitions=repetitions, noise=noise)
    return tournament
예제 #29
0
    def test_build_cache_required(self):
        # Noisy, no prebuilt cache, empty deterministic cache
        tournament = axelrod.Tournament(name=self.test_name,
                                        players=self.players,
                                        game=self.game,
                                        processes=4,
                                        noise=0.2,
                                        prebuilt_cache=False)
        self.assertFalse(tournament._build_cache_required())

        # Noisy, with prebuilt cache, empty deterministic cache
        tournament = axelrod.Tournament(name=self.test_name,
                                        players=self.players,
                                        processes=4,
                                        noise=0.2,
                                        prebuilt_cache=True)
        self.assertFalse(tournament._build_cache_required())

        # Not noisy, with prebuilt cache, deterministic cache has content
        tournament = axelrod.Tournament(name=self.test_name,
                                        players=self.players,
                                        game=self.game,
                                        processes=4,
                                        prebuilt_cache=True)
        tournament.deterministic_cache = {'test': 100}
        self.assertFalse(tournament._build_cache_required())

        # Not noisy, no prebuilt cache, deterministic cache has content
        tournament = axelrod.Tournament(name=self.test_name,
                                        players=self.players,
                                        game=self.game,
                                        processes=4,
                                        prebuilt_cache=False)
        tournament.deterministic_cache = {'test': 100}
        self.assertTrue(tournament._build_cache_required())

        # Not noisy, with prebuilt cache, empty deterministic cache
        tournament = axelrod.Tournament(name=self.test_name,
                                        players=self.players,
                                        game=self.game,
                                        processes=4,
                                        prebuilt_cache=True)
        self.assertTrue(tournament._build_cache_required())

        # Not noisy, no prebuilt cache, empty deterministic cache
        tournament = axelrod.Tournament(name=self.test_name,
                                        players=self.players,
                                        game=self.game,
                                        processes=4,
                                        prebuilt_cache=False)
        self.assertTrue(tournament._build_cache_required())
예제 #30
0
 def test_repeat_tournament_deterministic(self):
     """A test to check that tournament gives same results."""
     deterministic_players = [
         s()
         for s in axelrod.short_run_time_strategies
         if not s().classifier["stochastic"]
     ]
     files = []
     for _ in range(2):
         tournament = axelrod.Tournament(
             name="test",
             players=deterministic_players,
             game=self.game,
             turns=2,
             repetitions=2,
         )
         files.append("test_outputs/stochastic_tournament_{}.csv".format(_))
         tournament.play(progress_bar=False, filename=files[-1], build_results=False)
     self.assertTrue(filecmp.cmp(files[0], files[1]))