Exemplo n.º 1
0
 def sample_entity(self,
                   world: World,
                   last_entity,
                   combinations=None,
                   location_range: Dict = None):
     if last_entity == -1:
         self.provoke_collision = random() < self.provoke_collision_rate
     elif last_entity is not None:
         self.provoke_collision = random() < self.provoke_collision_rate
     if location_range is not None:
         center = world.random_location(
             provoke_collision=self.provoke_collision, **location_range)
     else:
         center = world.random_location(
             provoke_collision=self.provoke_collision)
     if combinations is None:
         return Entity.random_instance(
             center=center,
             rotation=self.rotation,
             size_range=self.size_range,
             distortion_range=self.distortion_range,
             shade_range=self.shade_range,
             shapes=self.shapes,
             colors=self.colors,
             textures=self.textures)
     else:
         return Entity.random_instance(
             center=center,
             rotation=self.rotation,
             size_range=self.size_range,
             distortion_range=self.distortion_range,
             shade_range=self.shade_range,
             combinations=combinations)
Exemplo n.º 2
0
 def generate_validation_world(self):
     world = World(self.world_size, self.world_color, self.noise_range)
     n_entity = choice(self.validation_entity_counts)
     if n_entity == 0:
         return world
     shapes = GenericGenerator.choose(self.validation_shapes,
                                      self.shapes_range)
     colors = GenericGenerator.choose(self.validation_colors,
                                      self.colors_range)
     textures = GenericGenerator.choose(self.validation_textures,
                                        self.textures_range)
     if self.validation_combinations:
         for _ in range(GenericGenerator.MAX_ATTEMPTS):
             entity = Entity.random_instance(
                 center=world.random_location(),
                 rotation=self.rotation,
                 size_range=self.size_range,
                 distortion_range=self.distortion_range,
                 shade_range=self.shade_range,
                 combinations=self.validation_combinations)
             if world.add_entity(
                     entity,
                     boundary_tolerance=self.boundary_tolerance,
                     collision_tolerance=self.collision_tolerance):
                 break
         else:
             return None
         n = 1
     else:
         n = 0
     for _ in range(n_entity * GenericGenerator.MAX_ATTEMPTS):
         entity = Entity.random_instance(
             center=world.random_location(),
             shapes=shapes,
             size_range=self.size_range,
             distortion_range=self.distortion_range,
             rotation=self.rotation,
             colors=colors,
             shade_range=self.shade_range,
             textures=textures)
         n += world.add_entity(entity,
                               boundary_tolerance=self.boundary_tolerance,
                               collision_tolerance=self.collision_tolerance)
         if n >= n_entity:
             break
     else:
         return None
     if self.collision_tolerance:
         world.sort_entities()
     return world
Exemplo n.º 3
0
 def generate_test_world(self):
     world = World(self.world_size, self.world_color)
     if self.num_entities == 0:
         return world
     if self.test_combinations:
         provoke_collision = random() < self.provoke_collision_rate
         while True:
             center = world.random_location(
                 provoke_collision=provoke_collision)
             entity = Entity.random_instance(
                 center=center,
                 rotation=self.rotation,
                 size_range=self.size_range,
                 distortion_range=self.distortion_range,
                 shade_range=self.shade_range,
                 combinations=self.test_combinations)
             if world.add_entity(
                     entity,
                     boundary_tolerance=self.boundary_tolerance,
                     collision_tolerance=self.collision_tolerance):
                 break
         n = 1
     else:
         n = 0
     provoke_collision = random() < self.provoke_collision_rate
     for _ in range(self.num_entities * self.__class__.MAX_ATTEMPTS):
         center = world.random_location(provoke_collision=provoke_collision)
         entity = Entity.random_instance(
             center=center,
             shapes=self.selected_shapes,
             size_range=self.size_range,
             distortion_range=self.distortion_range,
             rotation=self.rotation,
             colors=self.selected_colors,
             shade_range=self.shade_range,
             textures=self.selected_textures)
         if world.add_entity(entity,
                             boundary_tolerance=self.boundary_tolerance,
                             collision_tolerance=self.collision_tolerance):
             n += 1
             provoke_collision = random() < self.provoke_collision_rate
         if n == self.num_entities:
             break
     else:
         return None
     if self.collision_tolerance:
         world.sort_entities()
     return world