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
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
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__()
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
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
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
def fund(self, scenario, fund: float, setup): self.life.add_hotspot( Point(unit(Point.random()) * 10000 * self.life.noise)) return Hotspot.cost
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)