Spaces:
Sleeping
Sleeping
adityaverma977 commited on
Commit ·
da20490
1
Parent(s): 86358db
Update simulation chat personality and celebration messages
Browse files- app/simulation.py +32 -17
app/simulation.py
CHANGED
|
@@ -34,31 +34,43 @@ class SimulationEngine:
|
|
| 34 |
def __init__(self, state: SimulationState) -> None:
|
| 35 |
self.state = state
|
| 36 |
|
| 37 |
-
def _pick_message(self, action: str) -> str:
|
|
|
|
| 38 |
options = {
|
| 39 |
"search_water": [
|
| 40 |
-
"Scanning for the nearest well.",
|
| 41 |
-
"Heading
|
| 42 |
-
"Tracking a water source now.",
|
| 43 |
-
"
|
|
|
|
| 44 |
],
|
| 45 |
"collect_water": [
|
| 46 |
-
"
|
| 47 |
-
"Got water.
|
| 48 |
-
"
|
|
|
|
| 49 |
],
|
| 50 |
"extinguish_fire": [
|
| 51 |
-
"Pouring
|
| 52 |
-
"Holding position and dousing flames.",
|
| 53 |
-
"Suppressing
|
|
|
|
| 54 |
],
|
| 55 |
"escape": [
|
| 56 |
-
"
|
| 57 |
-
"Repositioning away from the flames.",
|
| 58 |
-
"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 59 |
],
|
| 60 |
}
|
| 61 |
-
|
|
|
|
| 62 |
|
| 63 |
def _move_toward(self, agent: AgentModel, target_x: float, target_y: float, stop_distance: float = 0) -> None:
|
| 64 |
dx = target_x - agent.x
|
|
@@ -239,7 +251,7 @@ class SimulationEngine:
|
|
| 239 |
dist_to_fire = math.dist((agent.x, agent.y), (fire.x, fire.y))
|
| 240 |
target_dist = max(fire.radius + FIRE_SAFE_BUFFER, 0)
|
| 241 |
self._move_toward(agent, fire.x, fire.y, stop_distance=target_dist)
|
| 242 |
-
message = self._pick_message("extinguish_fire")
|
| 243 |
else:
|
| 244 |
agent.status = "searching"
|
| 245 |
message = "Need water before I can extinguish."
|
|
@@ -287,6 +299,7 @@ class SimulationEngine:
|
|
| 287 |
agents_with_water.append(agent)
|
| 288 |
|
| 289 |
if agents_with_water:
|
|
|
|
| 290 |
living_count = len([a for a in agents if a.alive]) or 1
|
| 291 |
scale = max(0.5, min(2.0, 2.0 / living_count))
|
| 292 |
per_agent_rate = BASE_EXTINGUISH_RATE * scale
|
|
@@ -300,7 +313,9 @@ class SimulationEngine:
|
|
| 300 |
events.append(FireExtinguishedEvent(extinguished_by=extinguisher_names, fire_intensity=fire.intensity))
|
| 301 |
for agent in agents_with_water:
|
| 302 |
agent.extinguish_score += per_agent_rate
|
| 303 |
-
events.append(MessageEvent(model=agent.model_name, content=
|
|
|
|
|
|
|
| 304 |
agent.water_collected = False
|
| 305 |
|
| 306 |
return events
|
|
|
|
| 34 |
def __init__(self, state: SimulationState) -> None:
|
| 35 |
self.state = state
|
| 36 |
|
| 37 |
+
def _pick_message(self, action: str, current_fire_intensity: float | None = None) -> str:
|
| 38 |
+
fire_pct = f"{max(0.0, current_fire_intensity or 0.0):.0f}%"
|
| 39 |
options = {
|
| 40 |
"search_water": [
|
| 41 |
+
"Scanning for the nearest well. No pressure, just a giant fire.",
|
| 42 |
+
"Heading to water before this turns into a barbecue episode.",
|
| 43 |
+
"Tracking a water source now. Team hydration, then heroics.",
|
| 44 |
+
"On water duty. Someone queue victory music.",
|
| 45 |
+
"I see a well. Sprinting like my GPU is on turbo mode.",
|
| 46 |
],
|
| 47 |
"collect_water": [
|
| 48 |
+
"Bucket secured. Fireline, here I come.",
|
| 49 |
+
"Got water. Time to humble these flames.",
|
| 50 |
+
"Water collected. Deploying splash protocol.",
|
| 51 |
+
"Locked and loaded with water. Let's cook the fire instead.",
|
| 52 |
],
|
| 53 |
"extinguish_fire": [
|
| 54 |
+
"Pouring at the edge. Flames, meet your uninstall button.",
|
| 55 |
+
"Holding position and dousing flames. Nice and steady.",
|
| 56 |
+
"Suppressing fire now. Keep the pressure on.",
|
| 57 |
+
"Splashing hard. Current fire level: " + fire_pct + ".",
|
| 58 |
],
|
| 59 |
"escape": [
|
| 60 |
+
"Tactical retreat. I prefer crispy code, not crispy me.",
|
| 61 |
+
"Repositioning away from the flames. Living agents win games.",
|
| 62 |
+
"Backing off from the fire front. Bravery includes not exploding.",
|
| 63 |
+
],
|
| 64 |
+
"celebrate_extinguish": [
|
| 65 |
+
"Yes! Fire down to {fire_pct}. Keep pouring!",
|
| 66 |
+
"Let's go! We shaved it to {fire_pct}.",
|
| 67 |
+
"Big splash energy. Fire now at {fire_pct}.",
|
| 68 |
+
"Progress! Fire dropped to {fire_pct}. Team is cooking.",
|
| 69 |
+
"Huge play. Flames at {fire_pct} and falling.",
|
| 70 |
],
|
| 71 |
}
|
| 72 |
+
template = random.choice(options.get(action, ["Moving strategically and staying optimistic."]))
|
| 73 |
+
return template.format(fire_pct=fire_pct)
|
| 74 |
|
| 75 |
def _move_toward(self, agent: AgentModel, target_x: float, target_y: float, stop_distance: float = 0) -> None:
|
| 76 |
dx = target_x - agent.x
|
|
|
|
| 251 |
dist_to_fire = math.dist((agent.x, agent.y), (fire.x, fire.y))
|
| 252 |
target_dist = max(fire.radius + FIRE_SAFE_BUFFER, 0)
|
| 253 |
self._move_toward(agent, fire.x, fire.y, stop_distance=target_dist)
|
| 254 |
+
message = self._pick_message("extinguish_fire", current_fire_intensity=fire.intensity)
|
| 255 |
else:
|
| 256 |
agent.status = "searching"
|
| 257 |
message = "Need water before I can extinguish."
|
|
|
|
| 299 |
agents_with_water.append(agent)
|
| 300 |
|
| 301 |
if agents_with_water:
|
| 302 |
+
before_intensity = fire.intensity
|
| 303 |
living_count = len([a for a in agents if a.alive]) or 1
|
| 304 |
scale = max(0.5, min(2.0, 2.0 / living_count))
|
| 305 |
per_agent_rate = BASE_EXTINGUISH_RATE * scale
|
|
|
|
| 313 |
events.append(FireExtinguishedEvent(extinguished_by=extinguisher_names, fire_intensity=fire.intensity))
|
| 314 |
for agent in agents_with_water:
|
| 315 |
agent.extinguish_score += per_agent_rate
|
| 316 |
+
events.append(MessageEvent(model=agent.model_name, content=self._pick_message("celebrate_extinguish", current_fire_intensity=fire.intensity)))
|
| 317 |
+
if before_intensity - fire.intensity >= 10:
|
| 318 |
+
events.append(MessageEvent(model=agent.model_name, content="That's a big drop! Keep the chain going!"))
|
| 319 |
agent.water_collected = False
|
| 320 |
|
| 321 |
return events
|