How to use the axelrod.seed 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 / axelrod-dojo / tests / unit / test_utils.py View on Github external
def test_score(self):
        axl.seed(0)
        opponents_information = [utils.PlayerInfo(s, {})
                                 for s in axl.demo_strategies]
        objective = utils.prepare_objective()
        params = DummyParams()
        score = utils.score_params(params,
                                   objective=objective,
                                   opponents_information=opponents_information)
        expected_score = 2.0949
        self.assertEqual(score, expected_score)
github Axelrod-Python / axelrod-dojo / tests / integration / test_hmm.py View on Github external
turns=turns,
                                           noise=noise,
                                           repetitions=repetitions)

        population = dojo.Population(params_class=dojo.HMMParams,
                                     params_kwargs={"num_states": num_states},
                                     size=size,
                                     objective=objective,
                                     output_filename=self.temporary_file.name,
                                     opponents=opponents,
                                     bottleneck=2,
                                     mutation_probability = .01,
                                     processes=0)

        generations = 4
        axl.seed(0)
        population.run(generations, print_output=False)
        self.assertEqual(population.generation, 4)
github Axelrod-Python / axelrod-dojo / tests / archetypes / test_cycler.py View on Github external
def test_creation_seqLen(self):
        axl.seed(0)
        test_length = 10
        self.instance = CyclerParams(sequence_length=test_length)
        self.assertEqual(self.instance.sequence, [C, D, D, C, D, D, D, D, D, D])
        self.assertEqual(self.instance.sequence_length, test_length)
        self.assertEqual(len(self.instance.sequence), test_length)
github Axelrod-Python / axelrod-dojo / tests / integration / test_fsm.py View on Github external
population = dojo.Population(params_class=dojo.FSMParams,
                                     params_kwargs={"num_states": num_states,
                                                    "mutation_probability": .5},
                                     size=size,
                                     objective=objective,
                                     output_filename=self.temporary_file.name,
                                     opponents=opponents,
                                     bottleneck=2,
                                     mutation_probability = .01,
                                     processes=1)

        for p in population.population:
            self.assertEqual(p.mutation_probability, .5)
        generations = 1
        axl.seed(0)
        population.run(generations, print_output=False)
        self.assertEqual(population.generation, 1)
github Axelrod-Python / axelrod-dojo / tests / integration / test_hmm.py View on Github external
noise=noise,
                                           repetitions=repetitions)

        population = dojo.Population(params_class=dojo.HMMParams,
                                     params_kwargs={"num_states": num_states},
                                     size=size,
                                     objective=objective,
                                     output_filename=self.temporary_file.name,
                                     opponents=opponents,
                                     sample_count=2,  # Randomly sample 2 opponents at each step
                                     bottleneck=2,
                                     mutation_probability = .01,
                                     processes=1)

        generations = 4
        axl.seed(0)
        population.run(generations, print_output=False)
        self.assertEqual(population.generation, 4)

        # Manually read from temp file to find best strategy
        best_score, best_params = 0, None
        with open(self.temporary_file.name, "r") as f:
            reader = csv.reader(f)
            for row in reader:
                _, mean_score, sd_score, max_score, arg_max = row
                if float(max_score) > best_score:
                    best_score = float(max_score)
                    best_params = arg_max

        # Test the load params function
        for num in range(1, 4 + 1):
            best = dojo.load_params(params_class=dojo.HMMParams,
github Axelrod-Python / axelrod-dojo / tests / integration / test_hmm.py View on Github external
population = dojo.Population(params_class=dojo.HMMParams,
                                     params_kwargs={"num_states": num_states,
                                                    "mutation_probability": .5},
                                     size=size,
                                     objective=objective,
                                     output_filename=self.temporary_file.name,
                                     opponents=opponents,
                                     bottleneck=2,
                                     mutation_probability = .01,
                                     processes=1)

        for p in population.population:
            self.assertEqual(p.mutation_probability, .5)
        generations = 1
        axl.seed(0)
        population.run(generations, print_output=False)
        self.assertEqual(population.generation, 1)
github Axelrod-Python / axelrod-dojo / tests / integration / test_fsm.py View on Github external
noise=noise,
                                           repetitions=repetitions)

        population = dojo.Population(params_class=dojo.FSMParams,
                                     params_kwargs={"num_states": num_states},
                                     size=size,
                                     objective=objective,
                                     output_filename=self.temporary_file.name,
                                     opponents=opponents,
                                     sample_count=2,  # Randomly sample 2 opponents at each step
                                     bottleneck=2,
                                     mutation_probability = .01,
                                     processes=1)

        generations = 4
        axl.seed(0)
        population.run(generations, print_output=False)
        self.assertEqual(population.generation, 4)

        # Manually read from tempo file to find best strategy
        best_score, best_params = 0, None
        with open(self.temporary_file.name, "r") as f:
            reader = csv.reader(f)
            for row in reader:
                _, mean_score, sd_score, max_score, arg_max = row
                if float(max_score) > best_score:
                    best_score = float(max_score)
                    best_params = arg_max

        # Test the load params function
        for num in range(1, 4 + 1):
            best = dojo.load_params(params_class=dojo.FSMParams,
github Axelrod-Python / axelrod-dojo / tests / archetypes / test_hmm.py View on Github external
def test_init_without_defaults(self):
        """
        Check that by default have random rows.
        """
        num_states = 2
        transitions_Cs, transitions_Ds = [], []
        for seed in range(2):
            axl.seed(seed)
            hmm_params = HMMParams(num_states=num_states)
            transitions_Cs.append(hmm_params.transitions_C)
            transitions_Ds.append(hmm_params.transitions_D)
        self.assertNotEqual(*transitions_Cs)
        self.assertNotEqual(*transitions_Ds)
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')