def test_crossover_dictionaries(self): dict1 = {'1': 1, '2': 2, '3': 3} dict2 = {'1': 'a', '2': 'b', '3': 'c'} axl.seed(0) crossed = crossover_dictionaries(dict1, dict2) self.assertEqual(crossed, {'1': 1, '2': 'b', '3': 'c'}) axl.seed(1) crossed = crossover_dictionaries(dict1, dict2) self.assertEqual(crossed, dict2)
def test_crossover_dictionaries(self): dict1 = {'1': 1, '2': 2, '3': 3} dict2 = {'1': 'a', '2': 'b', '3': 'c'} rng = axl.RandomGenerator(seed=1) crossed = crossover_dictionaries(dict1, dict2, rng) self.assertEqual(crossed, {'1': 1, '2': 'b', '3': 'c'}) rng = axl.RandomGenerator(seed=2) crossed = crossover_dictionaries(dict1, dict2, rng) self.assertEqual(crossed, dict2)
def crossover(self, other): if other.__class__ != self.__class__: raise TypeError( "Crossover must be between the same player classes.") lookup_dict = crossover_dictionaries(self.lookup_dict, other.lookup_dict) return self.create_new(lookup_dict=lookup_dict)