Example #1
0
 def add_hotspot(self, spot: Point = None):
     if spot is None:
         spot = Point(self.city.infrastructure.most_used_road().a)
     hotspot = Hotspot(spot, Point(0, 0))
     self.hotspots.append(hotspot)
     self.cache_closest_intersection()
     self.dissipate([hotspot])
     return hotspot
Example #2
0
    def reproduce(self, life: 'Life'):
        child = life.add_hotspot(self.pos +
                                 unit(Point.random()) * 100 * life.noise)

        child.visit_count_on_last_growth = self.visit_count_on_last_growth

        self.mass /= 2
        child.mass = self.mass

        child.vel = unit(Point.random()) * mag(self.vel) * random.random()
        self.vel -= child.vel
Example #3
0
    def __init__(self, w=1280, h=720):
        self.w = w
        self.h = h
        self.img = self.reset_window()
        self.frame_hud_count = 0

        self.focus = Point(0, 0)
        self.scale = 5
        super().__init__()
Example #4
0
 def dissipate(self, hotspots: List[Hotspot] = None):
     hotspots = hotspots or self.hotspots
     for a_i, a in enumerate(hotspots):
         a.force *= 0
         for b_i, b in enumerate(self.hotspots):
             if a_i != b_i:
                 diff = a.pos - b.pos
                 mag_diff = mag(diff)
                 if mag_diff > 10:
                     a.force += a.mass * b.mass * diff / mag_diff**3
         a.vel += (a.force + Point.random() * self.noise) / a.mass
         a_speed = mag(a.vel)
         a.vel *= max(0, (1 - self.friction - self.drag *
                          a_speed)) * a.mass / (a.mass + self.growth)
         # a.mass += self.growth
         a.pos += a.vel / a.mass
Example #5
0
 def reset(self, pos: Point, orientation: int, goal: 'Goal'):
     self.initial_pos = pos
     self.pos = Point(pos)
     self.direction = AgentState.normalize_direction(orientation)
     self.goal = goal
     self.health = None
Example #6
0
 def pos_from_seed(self, seed: int):
     n_x, n_y = self.tiles_shape
     return (Point(seed % n_x, int(seed / n_x)) - self.tiles_shape / 2) / (
         self.tiles_shape / 2) + self.cache.corner_offset
Example #7
0
 def fund(self, scenario, fund: float, setup):
     self.life.add_hotspot(
         Point(unit(Point.random()) * 10000 * self.life.noise))
     return Hotspot.cost
Example #8
0
 def _window_transform_point(self, point: Point):
     return Point(self.w / 2 + (point[0] - self.focus[0]) * self.scale,
                  self.h / 2 - (point[1] - self.focus[1]) * self.scale)