Esempio n. 1
0
 def threaded_load(self):
     ''' Loads the saved data from file '''
     file_path = easygui.fileopenbox('Load a generations file',
                                     default='./data/generations/')
     if file_path is None:
         return
     data = load_generations(file_path)
     self.serializable_creatures = data['creatures']
     self.generations = data['generations']
     self.builder.get_object(
         'details')['text'] = f'Generation #{len(self.generations)+1}'
     self.creatures = []
     for i, creature_id in enumerate(self.generations[-1]):
         creature_data = self.serializable_creatures[creature_id]
         creature = Creature(**creature_data,
                             view_port=self.scroll_frame.view_port)
         self.create_creature(creature, i)
     set_entry(self.builder, 'save_as',
               os.path.basename(os.path.splitext(file_path)[0]))
     self.builder.get_object('create')['state'] = 'disabled'
     self.builder.get_object('train')['state'] = 'active'
     self.builder.get_object('find_fitness')['state'] = 'disabled'
     self.builder.get_object('find_fitness_no_gui')['state'] = 'disabled'
     self.builder.get_object('sort')['state'] = 'disabled'
     self.builder.get_object('do_selection')['state'] = 'active'
     self.builder.get_object('reproduce')['state'] = 'disabled'
Esempio n. 2
0
    def threaded_load(self):
        ''' Loads the saved data from file '''
        data = load_generations(self.load_path)
        self.serializable_creatures = data['creatures']
        self.generations = data['generations']

        self.creatures = []
        for creature_id in self.generations[-1]:
            creature_data = self.serializable_creatures[creature_id]
            creature = Creature(**creature_data)
            self.creatures.append(creature)
Esempio n. 3
0
    def test_simulate(self):
        ''' Tests the simulate function '''
        data = load_generations('test_data/default.pickle')
        creatures = []

        for creature in data['generations'][-1]:
            creature = data['creatures'][creature]
            creature = Creature(**creature)
            creatures.append(creature)
        simulation = Simulation()
        print(timeit(lambda: print(simulation.simulate(creatures)), number=1))
Esempio n. 4
0
    def test_reproduction(self):
        ''' Tests the reproduction of a creature '''
        data = load_generations('test_data/default.pickle')
        creatures = []

        for creature in data['generations'][-1]:
            creature = data['creatures'][creature]
            creature = Creature(**creature)
            creatures.append(creature)

        for creature in creatures:
            creature.draw_creature()
            offspring = reproduce(creature, data['creatures'])
            offspring.draw_creature()
Esempio n. 5
0
 def test_creature_creation(self):
     ''' Tests the creation of some creatures '''
     data = load_generations('test_data/default.pickle')
     show_analytics('Test', data['generations'], data['creatures'])