Files changed (1) hide show
  1. static/index.html +691 -689
static/index.html CHANGED
@@ -1,689 +1,691 @@
1
- <!DOCTYPE html>
2
- <html lang="en">
3
- <head>
4
- <meta charset="UTF-8" />
5
- <meta name="viewport" content="width=device-width, initial-scale=1.0" />
6
- <title>🔥 Wildfire ICS — OpenEnv</title>
7
- <style>
8
- * { box-sizing: border-box; margin: 0; padding: 0; }
9
- body {
10
- font-family: 'Segoe UI', system-ui, sans-serif;
11
- background: #0f0f0f;
12
- color: #e8e8e8;
13
- min-height: 100vh;
14
- display: flex;
15
- flex-direction: column;
16
- }
17
-
18
- /* ── Header ── */
19
- header {
20
- background: linear-gradient(135deg, #1a0a00, #3a1000);
21
- border-bottom: 2px solid #ff4500;
22
- padding: 14px 24px;
23
- display: flex;
24
- align-items: center;
25
- gap: 14px;
26
- }
27
- header h1 { font-size: 1.3rem; font-weight: 700; color: #ff6a00; }
28
- header span { font-size: 0.8rem; color: #999; margin-left: auto; }
29
- .badge {
30
- background: #ff4500;
31
- color: #fff;
32
- font-size: 0.7rem;
33
- font-weight: 700;
34
- padding: 2px 8px;
35
- border-radius: 99px;
36
- letter-spacing: 0.05em;
37
- }
38
-
39
- /* ── Layout ── */
40
- main {
41
- display: grid;
42
- grid-template-columns: 260px 1fr 280px;
43
- gap: 0;
44
- flex: 1;
45
- height: calc(100vh - 57px);
46
- overflow: hidden;
47
- }
48
-
49
- /* ── Panels ── */
50
- .panel {
51
- padding: 16px;
52
- overflow-y: auto;
53
- border-right: 1px solid #222;
54
- }
55
- .panel:last-child { border-right: none; }
56
- .panel h2 {
57
- font-size: 0.75rem;
58
- font-weight: 700;
59
- text-transform: uppercase;
60
- letter-spacing: 0.1em;
61
- color: #888;
62
- margin-bottom: 12px;
63
- }
64
-
65
- /* ── Controls ── */
66
- .control-group { margin-bottom: 16px; }
67
- label { font-size: 0.78rem; color: #aaa; display: block; margin-bottom: 4px; }
68
- select, input {
69
- width: 100%;
70
- background: #1c1c1c;
71
- border: 1px solid #333;
72
- color: #e8e8e8;
73
- padding: 7px 10px;
74
- border-radius: 6px;
75
- font-size: 0.85rem;
76
- }
77
- select:focus, input:focus { outline: none; border-color: #ff4500; }
78
-
79
- .btn {
80
- width: 100%;
81
- padding: 9px;
82
- border-radius: 6px;
83
- border: none;
84
- font-size: 0.85rem;
85
- font-weight: 600;
86
- cursor: pointer;
87
- margin-bottom: 8px;
88
- transition: opacity 0.15s;
89
- }
90
- .btn:hover { opacity: 0.85; }
91
- .btn:active { opacity: 0.7; }
92
- .btn-primary { background: #ff4500; color: #fff; }
93
- .btn-secondary { background: #2a2a2a; color: #ccc; border: 1px solid #444; }
94
- .btn-success { background: #1a5c2a; color: #7dff9a; border: 1px solid #2e8c45; }
95
- .btn-danger { background: #5c1a1a; color: #ff9a7d; border: 1px solid #8c2e2e; }
96
- .btn-sm {
97
- width: auto;
98
- padding: 5px 12px;
99
- font-size: 0.78rem;
100
- margin-bottom: 0;
101
- }
102
-
103
- /* ── Stats ── */
104
- .stat-row {
105
- display: flex;
106
- justify-content: space-between;
107
- align-items: center;
108
- padding: 6px 0;
109
- border-bottom: 1px solid #1e1e1e;
110
- font-size: 0.82rem;
111
- }
112
- .stat-row:last-child { border-bottom: none; }
113
- .stat-label { color: #888; }
114
- .stat-value { font-weight: 700; color: #ff9955; font-variant-numeric: tabular-nums; }
115
- .stat-value.good { color: #7dff9a; }
116
- .stat-value.bad { color: #ff5555; }
117
-
118
- /* ── Grid ── */
119
- .grid-panel {
120
- display: flex;
121
- flex-direction: column;
122
- align-items: center;
123
- justify-content: center;
124
- background: #111;
125
- padding: 16px;
126
- gap: 12px;
127
- }
128
- #fire-grid {
129
- display: grid;
130
- grid-template-columns: repeat(20, 1fr);
131
- gap: 1px;
132
- background: #1a1a1a;
133
- border: 1px solid #333;
134
- border-radius: 4px;
135
- overflow: hidden;
136
- width: min(560px, calc(100vw - 600px));
137
- height: min(560px, calc(100vw - 600px));
138
- }
139
- .cell {
140
- aspect-ratio: 1;
141
- transition: background 0.2s;
142
- cursor: pointer;
143
- position: relative;
144
- }
145
- .cell-0 { background: #1a2a1a; }
146
- .cell-1 { background: #ff4500; }
147
- .cell-1.anim { animation: flicker 0.5s infinite alternate; }
148
- .cell-2 { background: #2a2a2a; }
149
- .cell-3 { background: #6b4226; }
150
- .cell-asset { outline: 2px solid #ffd700; outline-offset: -2px; }
151
- .cell-crew { outline: 2px solid #00cfff; outline-offset: -2px; }
152
- @keyframes flicker {
153
- from { background: #ff4500; }
154
- to { background: #ff8c00; }
155
- }
156
-
157
- /* division boundary overlay */
158
- .div-A-border-r { border-right: 2px solid rgba(255,255,255,0.25); }
159
- .div-B-border-b { border-bottom: 2px solid rgba(255,255,255,0.25); }
160
-
161
- /* Legend */
162
- .legend {
163
- display: flex;
164
- gap: 14px;
165
- flex-wrap: wrap;
166
- justify-content: center;
167
- font-size: 0.73rem;
168
- color: #888;
169
- }
170
- .legend-item { display: flex; align-items: center; gap: 5px; }
171
- .legend-dot {
172
- width: 12px; height: 12px;
173
- border-radius: 2px;
174
- flex-shrink: 0;
175
- }
176
-
177
- /* Division labels */
178
- .div-labels {
179
- display: grid;
180
- grid-template-columns: 1fr 1fr;
181
- width: min(560px, calc(100vw - 600px));
182
- font-size: 0.7rem;
183
- color: #555;
184
- text-align: center;
185
- gap: 2px;
186
- }
187
-
188
- /* ── Action builder ── */
189
- .action-grid {
190
- display: grid;
191
- grid-template-columns: 1fr 1fr;
192
- gap: 6px;
193
- margin-bottom: 8px;
194
- }
195
- .action-btn {
196
- padding: 8px;
197
- border-radius: 6px;
198
- border: 1px solid #333;
199
- background: #1e1e1e;
200
- color: #ccc;
201
- cursor: pointer;
202
- font-size: 0.78rem;
203
- font-weight: 600;
204
- transition: all 0.15s;
205
- text-align: center;
206
- }
207
- .action-btn:hover { border-color: #ff4500; color: #ff9955; }
208
- .action-btn.selected { background: #3a1000; border-color: #ff4500; color: #ff6a00; }
209
-
210
- /* ── Log ── */
211
- #step-log {
212
- background: #111;
213
- border: 1px solid #222;
214
- border-radius: 6px;
215
- padding: 10px;
216
- font-size: 0.73rem;
217
- font-family: monospace;
218
- color: #888;
219
- height: 140px;
220
- overflow-y: auto;
221
- margin-top: 12px;
222
- }
223
- #step-log .log-entry { margin-bottom: 3px; }
224
- #step-log .log-entry.ok { color: #7dff9a; }
225
- #step-log .log-entry.err { color: #ff5555; }
226
- #step-log .log-entry.info { color: #ffcc55; }
227
-
228
- /* ── Score badges ── */
229
- .score-grid {
230
- display: grid;
231
- grid-template-columns: 1fr 1fr 1fr;
232
- gap: 6px;
233
- margin-bottom: 14px;
234
- }
235
- .score-card {
236
- background: #1a1a1a;
237
- border: 1px solid #2a2a2a;
238
- border-radius: 8px;
239
- padding: 10px 6px;
240
- text-align: center;
241
- }
242
- .score-card .sc-label { font-size: 0.65rem; color: #666; margin-bottom: 4px; }
243
- .score-card .sc-value { font-size: 1.2rem; font-weight: 800; color: #ff9955; }
244
-
245
- /* ── Crew list ── */
246
- .crew-item {
247
- display: flex;
248
- align-items: center;
249
- gap: 8px;
250
- padding: 5px 0;
251
- border-bottom: 1px solid #1a1a1a;
252
- font-size: 0.78rem;
253
- }
254
- .crew-dot { width: 8px; height: 8px; border-radius: 50%; background: #00cfff; flex-shrink: 0; }
255
- .crew-div { color: #888; margin-left: auto; font-size: 0.7rem; }
256
-
257
- /* ── Assets ── */
258
- .asset-item {
259
- display: flex;
260
- align-items: center;
261
- gap: 6px;
262
- padding: 5px 0;
263
- font-size: 0.78rem;
264
- border-bottom: 1px solid #1a1a1a;
265
- }
266
- .asset-status { margin-left: auto; font-size: 0.7rem; font-weight: 700; }
267
- .asset-status.safe { color: #7dff9a; }
268
- .asset-status.burned { color: #ff5555; }
269
-
270
- /* ── Containment bar ── */
271
- .bar-wrap {
272
- background: #1a1a1a;
273
- border-radius: 99px;
274
- height: 8px;
275
- overflow: hidden;
276
- margin-top: 4px;
277
- margin-bottom: 14px;
278
- }
279
- .bar-fill {
280
- height: 100%;
281
- border-radius: 99px;
282
- background: linear-gradient(90deg, #ff4500, #ffcc00);
283
- transition: width 0.4s ease;
284
- }
285
-
286
- .section-divider {
287
- border: none;
288
- border-top: 1px solid #222;
289
- margin: 12px 0;
290
- }
291
- </style>
292
- </head>
293
- <body>
294
-
295
- <header>
296
- <span style="font-size:1.5rem">🔥</span>
297
- <h1>Wildfire Incident Command</h1>
298
- <span class="badge">OpenEnv</span>
299
- <span>Meta Hackathon 2026</span>
300
- </header>
301
-
302
- <main>
303
-
304
- <!-- ── LEFT PANEL: Controls ── -->
305
- <div class="panel">
306
- <h2>Mission Control</h2>
307
-
308
- <div class="control-group">
309
- <label>Task</label>
310
- <select id="task-select">
311
- <option value="1">Task 1 — Single Front [Easy]</option>
312
- <option value="2">Task 2 — Asset Protection [Medium]</option>
313
- <option value="3">Task 3 — Multi-Front [Hard]</option>
314
- </select>
315
- </div>
316
-
317
- <button class="btn btn-primary" onclick="resetEnv()">🔄 Reset Environment</button>
318
- <button class="btn btn-secondary" onclick="runBaseline()">🤖 Run Baseline Agent</button>
319
- <button class="btn btn-secondary" onclick="fetchGrader()">📊 Get Scores</button>
320
-
321
- <hr class="section-divider">
322
- <h2>Action Builder</h2>
323
-
324
- <div class="control-group">
325
- <label>Division</label>
326
- <select id="act-division">
327
- <option value="0">Division A (top-left)</option>
328
- <option value="1">Division B (top-right)</option>
329
- <option value="2">Division C (bottom-left)</option>
330
- <option value="3">Division D (bottom-right)</option>
331
- </select>
332
- </div>
333
-
334
- <div class="control-group">
335
- <label>Crew Boss</label>
336
- <select id="act-crew">
337
- <option value="0">Crew 0</option>
338
- <option value="1">Crew 1</option>
339
- </select>
340
- </div>
341
-
342
- <div class="control-group">
343
- <label>Action Type</label>
344
- <div class="action-grid">
345
- <div class="action-btn selected" onclick="selectAction('SUPPRESS', this)">🔥 Suppress</div>
346
- <div class="action-btn" onclick="selectAction('FIREBREAK', this)">🟫 Firebreak</div>
347
- <div class="action-btn" onclick="selectAction('MOVE', this)">🚶 Move</div>
348
- <div class="action-btn" onclick="selectAction('HOLD', this)">✋ Hold</div>
349
- </div>
350
- </div>
351
-
352
- <div class="control-group">
353
- <label>Target Cell (click grid or enter manually)</label>
354
- <div style="display:flex;gap:6px">
355
- <input type="number" id="act-row" placeholder="Row 0-19" min="0" max="19" value="3" />
356
- <input type="number" id="act-col" placeholder="Col 0-19" min="0" max="19" value="3" />
357
- </div>
358
- </div>
359
-
360
- <button class="btn btn-danger" onclick="sendStep()">⚡ Send Action</button>
361
- <button class="btn btn-success" onclick="autoPlay()" id="auto-btn">▶ Auto-Play (Baseline)</button>
362
-
363
- <div id="step-log"><div class="log-entry info">Ready. Reset to start.</div></div>
364
- </div>
365
-
366
- <!-- ── CENTER: Grid ── -->
367
- <div class="grid-panel">
368
- <div class="div-labels">
369
- <div>Division A</div><div>Division B</div>
370
- <div>Division C</div><div>Division D</div>
371
- </div>
372
- <div id="fire-grid"></div>
373
- <div class="legend">
374
- <div class="legend-item"><div class="legend-dot" style="background:#1a2a1a"></div>Clear</div>
375
- <div class="legend-item"><div class="legend-dot" style="background:#ff4500"></div>Burning</div>
376
- <div class="legend-item"><div class="legend-dot" style="background:#2a2a2a"></div>Burnt</div>
377
- <div class="legend-item"><div class="legend-dot" style="background:#6b4226"></div>Firebreak</div>
378
- <div class="legend-item"><div class="legend-dot" style="background:#1a2a1a;outline:2px solid #ffd700;outline-offset:-1px"></div>Asset</div>
379
- <div class="legend-item"><div class="legend-dot" style="background:#1a2a1a;outline:2px solid #00cfff;outline-offset:-1px"></div>Crew</div>
380
- </div>
381
- </div>
382
-
383
- <!-- ── RIGHT PANEL: State ── -->
384
- <div class="panel">
385
- <h2>Episode State</h2>
386
-
387
- <div class="stat-row">
388
- <span class="stat-label">Timestep</span>
389
- <span class="stat-value" id="s-timestep">—</span>
390
- </div>
391
- <div class="stat-row">
392
- <span class="stat-label">Containment</span>
393
- <span class="stat-value" id="s-containment">—</span>
394
- </div>
395
- <div class="bar-wrap"><div class="bar-fill" id="containment-bar" style="width:0%"></div></div>
396
-
397
- <div class="stat-row">
398
- <span class="stat-label">Wind</span>
399
- <span class="stat-value" id="s-wind">—</span>
400
- </div>
401
- <div class="stat-row">
402
- <span class="stat-label">Last Reward</span>
403
- <span class="stat-value" id="s-reward">—</span>
404
- </div>
405
- <div class="stat-row">
406
- <span class="stat-label">Episode Done</span>
407
- <span class="stat-value" id="s-done">—</span>
408
- </div>
409
-
410
- <hr class="section-divider">
411
- <h2>Task Scores</h2>
412
- <div class="score-grid">
413
- <div class="score-card"><div class="sc-label">Task 1</div><div class="sc-value" id="sc-1">—</div></div>
414
- <div class="score-card"><div class="sc-label">Task 2</div><div class="sc-value" id="sc-2">—</div></div>
415
- <div class="score-card"><div class="sc-label">Task 3</div><div class="sc-value" id="sc-3">—</div></div>
416
- </div>
417
-
418
- <hr class="section-divider">
419
- <h2>Assets at Risk</h2>
420
- <div id="asset-list"><div style="color:#555;font-size:0.78rem">No assets in this task.</div></div>
421
-
422
- <hr class="section-divider">
423
- <h2>Crew Positions</h2>
424
- <div id="crew-list"></div>
425
- </div>
426
-
427
- </main>
428
-
429
- <script>
430
- const BASE = '';
431
- let selectedAction = 'SUPPRESS';
432
- let autoInterval = null;
433
- let isPlaying = false;
434
- let lastObs = null;
435
-
436
- // ── Action selection ──
437
- function selectAction(type, el) {
438
- selectedAction = type;
439
- document.querySelectorAll('.action-btn').forEach(b => b.classList.remove('selected'));
440
- el.classList.add('selected');
441
- }
442
-
443
- // ── Logging ──
444
- function log(msg, type = 'ok') {
445
- const log = document.getElementById('step-log');
446
- const entry = document.createElement('div');
447
- entry.className = `log-entry ${type}`;
448
- entry.textContent = `[${new Date().toLocaleTimeString()}] ${msg}`;
449
- log.appendChild(entry);
450
- log.scrollTop = log.scrollHeight;
451
- }
452
-
453
- // ── Reset ──
454
- async function resetEnv() {
455
- stopAuto();
456
- const task = parseInt(document.getElementById('task-select').value);
457
- try {
458
- const res = await fetch(`${BASE}/reset`, {
459
- method: 'POST',
460
- headers: { 'Content-Type': 'application/json' },
461
- body: JSON.stringify({ task })
462
- });
463
- const data = await res.json();
464
- lastObs = data.observation;
465
- renderState(data.observation, null);
466
- log(`Reset → Task ${task}`, 'info');
467
- await fetchGrader();
468
- } catch (e) {
469
- log(`Reset failed: ${e.message}`, 'err');
470
- }
471
- }
472
-
473
- // ── Step ──
474
- async function sendStep() {
475
- const action = {
476
- division_id: parseInt(document.getElementById('act-division').value),
477
- crew_id: parseInt(document.getElementById('act-crew').value),
478
- action_type: selectedAction,
479
- target_cell: [
480
- parseInt(document.getElementById('act-row').value),
481
- parseInt(document.getElementById('act-col').value)
482
- ]
483
- };
484
-
485
- try {
486
- const res = await fetch(`${BASE}/step`, {
487
- method: 'POST',
488
- headers: { 'Content-Type': 'application/json' },
489
- body: JSON.stringify(action)
490
- });
491
- const data = await res.json();
492
- lastObs = data.observation;
493
- renderState(data.observation, data.reward);
494
- log(`Step t=${data.observation.timestep} | ${action.action_type} [${action.target_cell}] | reward=${data.reward.toFixed(4)} | done=${data.done}`, data.done ? 'info' : 'ok');
495
- if (data.done) {
496
- log('Episode complete!', 'info');
497
- stopAuto();
498
- await fetchGrader();
499
- }
500
- if (data.info?.error) log(`⚠ ${data.info.error}`, 'err');
501
- } catch (e) {
502
- log(`Step failed: ${e.message}`, 'err');
503
- }
504
- }
505
-
506
- // ── Baseline ──
507
- async function runBaseline() {
508
- stopAuto();
509
- log('Running baseline agent...', 'info');
510
- try {
511
- const res = await fetch(`${BASE}/baseline`);
512
- const data = await res.json();
513
- log(`Baseline done. Steps=${data.steps_taken} Reward=${data.total_reward.toFixed(4)}`, 'info');
514
- updateScores(data.task_scores);
515
- await refreshState();
516
- } catch (e) {
517
- log(`Baseline failed: ${e.message}`, 'err');
518
- }
519
- }
520
-
521
- // ── Grader ──
522
- async function fetchGrader() {
523
- try {
524
- const res = await fetch(`${BASE}/grader`);
525
- const data = await res.json();
526
- updateScores(data.task_scores);
527
- } catch (e) {}
528
- }
529
-
530
- function updateScores(scores) {
531
- document.getElementById('sc-1').textContent = scores.task_1?.toFixed(2) ?? '—';
532
- document.getElementById('sc-2').textContent = scores.task_2?.toFixed(2) ?? '—';
533
- document.getElementById('sc-3').textContent = scores.task_3?.toFixed(2) ?? '—';
534
- }
535
-
536
- // ── Auto-play ──
537
- async function autoPlay() {
538
- if (isPlaying) { stopAuto(); return; }
539
- isPlaying = true;
540
- document.getElementById('auto-btn').textContent = '⏹ Stop Auto-Play';
541
- autoInterval = setInterval(async () => {
542
- if (!lastObs) { stopAuto(); return; }
543
- const obs = lastObs;
544
- const grid = obs.grid;
545
-
546
- // Simple greedy: find busiest division, suppress nearest burning cell
547
- let bestDiv = 0, bestCount = -1;
548
- const divBounds = [
549
- {rows:[0,9],cols:[0,9]}, {rows:[0,9],cols:[10,19]},
550
- {rows:[10,19],cols:[0,9]}, {rows:[10,19],cols:[10,19]}
551
- ];
552
- divBounds.forEach((b, i) => {
553
- let cnt = 0;
554
- for (let r = b.rows[0]; r <= b.rows[1]; r++)
555
- for (let c = b.cols[0]; c <= b.cols[1]; c++)
556
- if (grid[r][c] === 1) cnt++;
557
- if (cnt > bestCount) { bestCount = cnt; bestDiv = i; }
558
- });
559
-
560
- let targetCell = [5, 5];
561
- const b = divBounds[bestDiv];
562
- outer: for (let r = b.rows[0]; r <= b.rows[1]; r++)
563
- for (let c = b.cols[0]; c <= b.cols[1]; c++)
564
- if (grid[r][c] === 1) { targetCell = [r, c]; break outer; }
565
-
566
- const action = {
567
- division_id: bestDiv,
568
- crew_id: obs.timestep % 2,
569
- action_type: bestCount > 0 ? 'SUPPRESS' : 'HOLD',
570
- target_cell: targetCell
571
- };
572
-
573
- try {
574
- const res = await fetch(`${BASE}/step`, {
575
- method: 'POST',
576
- headers: { 'Content-Type': 'application/json' },
577
- body: JSON.stringify(action)
578
- });
579
- const data = await res.json();
580
- lastObs = data.observation;
581
- renderState(data.observation, data.reward);
582
- if (data.done) { stopAuto(); log('Auto-play done.', 'info'); await fetchGrader(); }
583
- } catch (e) { stopAuto(); }
584
- }, 300);
585
- }
586
-
587
- function stopAuto() {
588
- if (autoInterval) clearInterval(autoInterval);
589
- autoInterval = null;
590
- isPlaying = false;
591
- document.getElementById('auto-btn').textContent = '▶ Auto-Play (Baseline)';
592
- }
593
-
594
- // ── Refresh state ──
595
- async function refreshState() {
596
- try {
597
- const res = await fetch(`${BASE}/state`);
598
- const data = await res.json();
599
- // Reconstruct a minimal obs from state
600
- const s = data.state;
601
- lastObs = { grid: s.grid, wind: s.wind, timestep: s.timestep, containment_pct: s.containment_pct, assets_at_risk: s.assets, crew_positions: s.crews, division_zones: [] };
602
- renderState(lastObs, null);
603
- } catch (e) {}
604
- }
605
-
606
- // ── Render ──
607
- function renderState(obs, reward) {
608
- renderGrid(obs);
609
- renderStats(obs, reward);
610
- renderAssets(obs.assets_at_risk || []);
611
- renderCrews(obs.crew_positions || []);
612
- }
613
-
614
- function renderGrid(obs) {
615
- const grid = obs.grid;
616
- const assets = obs.assets_at_risk || [];
617
- const crews = obs.crew_positions || [];
618
-
619
- const assetCells = new Set(assets.map(a => `${a.cell[0]},${a.cell[1]}`));
620
- const crewCells = new Set(crews.map(c => `${c.cell[0]},${c.cell[1]}`));
621
-
622
- const container = document.getElementById('fire-grid');
623
- container.innerHTML = '';
624
-
625
- for (let r = 0; r < 20; r++) {
626
- for (let c = 0; c < 20; c++) {
627
- const val = grid[r][c];
628
- const cell = document.createElement('div');
629
- cell.className = `cell cell-${val}`;
630
- if (val === 1) cell.classList.add('anim');
631
- if (assetCells.has(`${r},${c}`)) cell.classList.add('cell-asset');
632
- if (crewCells.has(`${r},${c}`)) cell.classList.add('cell-crew');
633
- cell.title = `(${r},${c}) = ${['Clear','Burning','Burnt','Firebreak'][val]}`;
634
- cell.addEventListener('click', () => {
635
- document.getElementById('act-row').value = r;
636
- document.getElementById('act-col').value = c;
637
- });
638
- container.appendChild(cell);
639
- }
640
- }
641
- }
642
-
643
- function renderStats(obs, reward) {
644
- document.getElementById('s-timestep').textContent = obs.timestep ?? '—';
645
- const pct = ((obs.containment_pct || 0) * 100).toFixed(1);
646
- document.getElementById('s-containment').textContent = `${pct}%`;
647
- document.getElementById('containment-bar').style.width = `${pct}%`;
648
- document.getElementById('s-wind').textContent =
649
- obs.wind ? `${obs.wind.direction} · ${obs.wind.speed}` : '—';
650
- if (reward !== null) {
651
- const rEl = document.getElementById('s-reward');
652
- rEl.textContent = reward.toFixed(4);
653
- rEl.className = 'stat-value ' + (reward >= 0 ? 'good' : 'bad');
654
- }
655
- document.getElementById('s-done').textContent = obs.done ? '✅ Yes' : '🔄 No';
656
- }
657
-
658
- function renderAssets(assets) {
659
- const el = document.getElementById('asset-list');
660
- if (!assets.length) {
661
- el.innerHTML = '<div style="color:#555;font-size:0.78rem">No assets in this task.</div>';
662
- return;
663
- }
664
- el.innerHTML = assets.map(a => `
665
- <div class="asset-item">
666
- <span>🏠 ${a.name}</span>
667
- <span class="asset-status ${a.status}">${a.status === 'safe' ? '✓ Safe' : '✗ Burned'}</span>
668
- </div>
669
- `).join('');
670
- }
671
-
672
- function renderCrews(crews) {
673
- const el = document.getElementById('crew-list');
674
- const divLabels = ['A','B','C','D'];
675
- el.innerHTML = crews.map(c => `
676
- <div class="crew-item">
677
- <div class="crew-dot"></div>
678
- <span>Crew ${c.id}</span>
679
- <span>[${c.cell[0]},${c.cell[1]}]</span>
680
- <span class="crew-div">Div ${divLabels[c.division] || c.division}</span>
681
- </div>
682
- `).join('');
683
- }
684
-
685
- // ── Boot ──
686
- resetEnv();
687
- </script>
688
- </body>
689
- </html>
 
 
 
1
+ <!DOCTYPE html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="UTF-8" />
5
+ <meta name="viewport" content="width=device-width, initial-scale=1.0" />
6
+ <title>🔥 Wildfire ICS — OpenEnv</title>
7
+ <style>
8
+ * { box-sizing: border-box; margin: 0; padding: 0; }
9
+ body {
10
+ font-family: 'Segoe UI', system-ui, sans-serif;
11
+ background: #0f0f0f;
12
+ color: #e8e8e8;
13
+ min-height: 100vh;
14
+ display: flex;
15
+ flex-direction: column;
16
+ }
17
+
18
+ /* ── Header ── */
19
+ header {
20
+ background: linear-gradient(135deg, #1a0a00, #3a1000);
21
+ border-bottom: 2px solid #ff4500;
22
+ padding: 14px 24px;
23
+ display: flex;
24
+ align-items: center;
25
+ gap: 14px;
26
+ }
27
+ header h1 { font-size: 1.3rem; font-weight: 700; color: #ff6a00; }
28
+ header span { font-size: 0.8rem; color: #999; margin-left: auto; }
29
+ .badge {
30
+ background: #ff4500;
31
+ color: #fff;
32
+ font-size: 0.7rem;
33
+ font-weight: 700;
34
+ padding: 2px 8px;
35
+ border-radius: 99px;
36
+ letter-spacing: 0.05em;
37
+ }
38
+
39
+ /* ── Layout ── */
40
+ main {
41
+ display: grid;
42
+ grid-template-columns: 260px 1fr 280px;
43
+ gap: 0;
44
+ flex: 1;
45
+ height: calc(100vh - 57px);
46
+ overflow: hidden;
47
+ }
48
+
49
+ /* ── Panels ── */
50
+ .panel {
51
+ padding: 16px;
52
+ overflow-y: auto;
53
+ border-right: 1px solid #222;
54
+ }
55
+ .panel:last-child { border-right: none; }
56
+ .panel h2 {
57
+ font-size: 0.75rem;
58
+ font-weight: 700;
59
+ text-transform: uppercase;
60
+ letter-spacing: 0.1em;
61
+ color: #888;
62
+ margin-bottom: 12px;
63
+ }
64
+
65
+ /* ── Controls ── */
66
+ .control-group { margin-bottom: 16px; }
67
+ label { font-size: 0.78rem; color: #aaa; display: block; margin-bottom: 4px; }
68
+ select, input {
69
+ width: 100%;
70
+ background: #1c1c1c;
71
+ border: 1px solid #333;
72
+ color: #e8e8e8;
73
+ padding: 7px 10px;
74
+ border-radius: 6px;
75
+ font-size: 0.85rem;
76
+ }
77
+ select:focus, input:focus { outline: none; border-color: #ff4500; }
78
+
79
+ .btn {
80
+ width: 100%;
81
+ padding: 9px;
82
+ border-radius: 6px;
83
+ border: none;
84
+ font-size: 0.85rem;
85
+ font-weight: 600;
86
+ cursor: pointer;
87
+ margin-bottom: 8px;
88
+ transition: opacity 0.15s;
89
+ }
90
+ .btn:hover { opacity: 0.85; }
91
+ .btn:active { opacity: 0.7; }
92
+ .btn-primary { background: #ff4500; color: #fff; }
93
+ .btn-secondary { background: #2a2a2a; color: #ccc; border: 1px solid #444; }
94
+ .btn-success { background: #1a5c2a; color: #7dff9a; border: 1px solid #2e8c45; }
95
+ .btn-danger { background: #5c1a1a; color: #ff9a7d; border: 1px solid #8c2e2e; }
96
+ .btn-sm {
97
+ width: auto;
98
+ padding: 5px 12px;
99
+ font-size: 0.78rem;
100
+ margin-bottom: 0;
101
+ }
102
+
103
+ /* ── Stats ── */
104
+ .stat-row {
105
+ display: flex;
106
+ justify-content: space-between;
107
+ align-items: center;
108
+ padding: 6px 0;
109
+ border-bottom: 1px solid #1e1e1e;
110
+ font-size: 0.82rem;
111
+ }
112
+ .stat-row:last-child { border-bottom: none; }
113
+ .stat-label { color: #888; }
114
+ .stat-value { font-weight: 700; color: #ff9955; font-variant-numeric: tabular-nums; }
115
+ .stat-value.good { color: #7dff9a; }
116
+ .stat-value.bad { color: #ff5555; }
117
+
118
+ /* ── Grid ── */
119
+ .grid-panel {
120
+ display: flex;
121
+ flex-direction: column;
122
+ align-items: center;
123
+ justify-content: center;
124
+ background: #111;
125
+ padding: 16px;
126
+ gap: 12px;
127
+ }
128
+ #fire-grid {
129
+ display: grid;
130
+ grid-template-columns: repeat(20, 1fr);
131
+ gap: 1px;
132
+ background: #1a1a1a;
133
+ border: 1px solid #333;
134
+ border-radius: 4px;
135
+ overflow: hidden;
136
+ width: min(560px, calc(100vw - 600px));
137
+ height: min(560px, calc(100vw - 600px));
138
+ }
139
+ .cell {
140
+ aspect-ratio: 1;
141
+ transition: background 0.2s;
142
+ cursor: pointer;
143
+ position: relative;
144
+ }
145
+ .cell-0 { background: #1a2a1a; }
146
+ .cell-1 { background: #ff4500; }
147
+ .cell-1.anim { animation: flicker 0.5s infinite alternate; }
148
+ .cell-2 { background: #2a2a2a; }
149
+ .cell-3 { background: #6b4226; }
150
+ .cell-asset { outline: 2px solid #ffd700; outline-offset: -2px; }
151
+ .cell-crew { outline: 2px solid #00cfff; outline-offset: -2px; }
152
+ @keyframes flicker {
153
+ from { background: #ff4500; }
154
+ to { background: #ff8c00; }
155
+ }
156
+
157
+ /* division boundary overlay */
158
+ .div-A-border-r { border-right: 2px solid rgba(255,255,255,0.25); }
159
+ .div-B-border-b { border-bottom: 2px solid rgba(255,255,255,0.25); }
160
+
161
+ /* Legend */
162
+ .legend {
163
+ display: flex;
164
+ gap: 14px;
165
+ flex-wrap: wrap;
166
+ justify-content: center;
167
+ font-size: 0.73rem;
168
+ color: #888;
169
+ }
170
+ .legend-item { display: flex; align-items: center; gap: 5px; }
171
+ .legend-dot {
172
+ width: 12px; height: 12px;
173
+ border-radius: 2px;
174
+ flex-shrink: 0;
175
+ }
176
+
177
+ /* Division labels */
178
+ .div-labels {
179
+ display: grid;
180
+ grid-template-columns: 1fr 1fr;
181
+ width: min(560px, calc(100vw - 600px));
182
+ font-size: 0.7rem;
183
+ color: #555;
184
+ text-align: center;
185
+ gap: 2px;
186
+ }
187
+
188
+ /* ── Action builder ── */
189
+ .action-grid {
190
+ display: grid;
191
+ grid-template-columns: 1fr 1fr;
192
+ gap: 6px;
193
+ margin-bottom: 8px;
194
+ }
195
+ .action-btn {
196
+ padding: 8px;
197
+ border-radius: 6px;
198
+ border: 1px solid #333;
199
+ background: #1e1e1e;
200
+ color: #ccc;
201
+ cursor: pointer;
202
+ font-size: 0.78rem;
203
+ font-weight: 600;
204
+ transition: all 0.15s;
205
+ text-align: center;
206
+ }
207
+ .action-btn:hover { border-color: #ff4500; color: #ff9955; }
208
+ .action-btn.selected { background: #3a1000; border-color: #ff4500; color: #ff6a00; }
209
+
210
+ /* ── Log ── */
211
+ #step-log {
212
+ background: #111;
213
+ border: 1px solid #222;
214
+ border-radius: 6px;
215
+ padding: 10px;
216
+ font-size: 0.73rem;
217
+ font-family: monospace;
218
+ color: #888;
219
+ height: 140px;
220
+ overflow-y: auto;
221
+ margin-top: 12px;
222
+ }
223
+ #step-log .log-entry { margin-bottom: 3px; }
224
+ #step-log .log-entry.ok { color: #7dff9a; }
225
+ #step-log .log-entry.err { color: #ff5555; }
226
+ #step-log .log-entry.info { color: #ffcc55; }
227
+
228
+ /* ── Score badges ── */
229
+ .score-grid {
230
+ display: grid;
231
+ grid-template-columns: 1fr 1fr 1fr;
232
+ gap: 6px;
233
+ margin-bottom: 14px;
234
+ }
235
+ .score-card {
236
+ background: #1a1a1a;
237
+ border: 1px solid #2a2a2a;
238
+ border-radius: 8px;
239
+ padding: 10px 6px;
240
+ text-align: center;
241
+ }
242
+ .score-card .sc-label { font-size: 0.65rem; color: #666; margin-bottom: 4px; }
243
+ .score-card .sc-value { font-size: 1.2rem; font-weight: 800; color: #ff9955; }
244
+
245
+ /* ── Crew list ── */
246
+ .crew-item {
247
+ display: flex;
248
+ align-items: center;
249
+ gap: 8px;
250
+ padding: 5px 0;
251
+ border-bottom: 1px solid #1a1a1a;
252
+ font-size: 0.78rem;
253
+ }
254
+ .crew-dot { width: 8px; height: 8px; border-radius: 50%; background: #00cfff; flex-shrink: 0; }
255
+ .crew-div { color: #888; margin-left: auto; font-size: 0.7rem; }
256
+
257
+ /* ── Assets ── */
258
+ .asset-item {
259
+ display: flex;
260
+ align-items: center;
261
+ gap: 6px;
262
+ padding: 5px 0;
263
+ font-size: 0.78rem;
264
+ border-bottom: 1px solid #1a1a1a;
265
+ }
266
+ .asset-status { margin-left: auto; font-size: 0.7rem; font-weight: 700; }
267
+ .asset-status.safe { color: #7dff9a; }
268
+ .asset-status.burned { color: #ff5555; }
269
+
270
+ /* ── Containment bar ── */
271
+ .bar-wrap {
272
+ background: #1a1a1a;
273
+ border-radius: 99px;
274
+ height: 8px;
275
+ overflow: hidden;
276
+ margin-top: 4px;
277
+ margin-bottom: 14px;
278
+ }
279
+ .bar-fill {
280
+ height: 100%;
281
+ border-radius: 99px;
282
+ background: linear-gradient(90deg, #ff4500, #ffcc00);
283
+ transition: width 0.4s ease;
284
+ }
285
+
286
+ .section-divider {
287
+ border: none;
288
+ border-top: 1px solid #222;
289
+ margin: 12px 0;
290
+ }
291
+ </style>
292
+ </head>
293
+ <body>
294
+
295
+ <header>
296
+ <span style="font-size:1.5rem">🔥</span>
297
+ <h1>Wildfire Incident Command</h1>
298
+ <span class="badge">OpenEnv</span>
299
+ <span>Meta Hackathon 2026</span>
300
+ </header>
301
+
302
+ <main>
303
+
304
+ <!-- ── LEFT PANEL: Controls ── -->
305
+ <div class="panel">
306
+ <h2>Mission Control</h2>
307
+
308
+ <div class="control-group">
309
+ <label>Task</label>
310
+ <select id="task-select">
311
+ <option value="1">Task 1 — Single Front [Easy]</option>
312
+ <option value="2">Task 2 — Asset Protection [Medium]</option>
313
+ <option value="3">Task 3 — Multi-Front [Hard]</option>
314
+ </select>
315
+ </div>
316
+
317
+ <button class="btn btn-primary" onclick="resetEnv()">🔄 Reset Environment</button>
318
+ <button class="btn btn-secondary" onclick="runBaseline()">🤖 Run Baseline Agent</button>
319
+ <button class="btn btn-secondary" onclick="fetchGrader()">📊 Get Scores</button>
320
+
321
+ <hr class="section-divider">
322
+ <h2>Action Builder</h2>
323
+
324
+ <div class="control-group">
325
+ <label>Division</label>
326
+ <select id="act-division">
327
+ <option value="0">Division A (top-left)</option>
328
+ <option value="1">Division B (top-right)</option>
329
+ <option value="2">Division C (bottom-left)</option>
330
+ <option value="3">Division D (bottom-right)</option>
331
+ </select>
332
+ </div>
333
+
334
+ <div class="control-group">
335
+ <label>Crew Boss</label>
336
+ <select id="act-crew">
337
+ <option value="0">Crew 0</option>
338
+ <option value="1">Crew 1</option>
339
+ </select>
340
+ </div>
341
+
342
+ <div class="control-group">
343
+ <label>Action Type</label>
344
+ <div class="action-grid">
345
+ <div class="action-btn selected" onclick="selectAction('SUPPRESS', this)">🔥 Suppress</div>
346
+ <div class="action-btn" onclick="selectAction('FIREBREAK', this)">🟫 Firebreak</div>
347
+ <div class="action-btn" onclick="selectAction('MOVE', this)">🚶 Move</div>
348
+ <div class="action-btn" onclick="selectAction('HOLD', this)">✋ Hold</div>
349
+ </div>
350
+ </div>
351
+
352
+ <div class="control-group">
353
+ <label>Target Cell (click grid or enter manually)</label>
354
+ <div style="display:flex;gap:6px">
355
+ <input type="number" id="act-row" placeholder="Row 0-19" min="0" max="19" value="3" />
356
+ <input type="number" id="act-col" placeholder="Col 0-19" min="0" max="19" value="3" />
357
+ </div>
358
+ </div>
359
+
360
+ <button class="btn btn-danger" onclick="sendStep()">⚡ Send Action</button>
361
+ <button class="btn btn-success" onclick="autoPlay()" id="auto-btn">▶ Auto-Play (Baseline)</button>
362
+
363
+ <div id="step-log"><div class="log-entry info">Ready. Reset to start.</div></div>
364
+ </div>
365
+
366
+ <!-- ── CENTER: Grid ── -->
367
+ <div class="grid-panel">
368
+ <div class="div-labels">
369
+ <div>Division A</div><div>Division B</div>
370
+ <div>Division C</div><div>Division D</div>
371
+ </div>
372
+ <div id="fire-grid"></div>
373
+ <div class="legend">
374
+ <div class="legend-item"><div class="legend-dot" style="background:#1a2a1a"></div>Clear</div>
375
+ <div class="legend-item"><div class="legend-dot" style="background:#ff4500"></div>Burning</div>
376
+ <div class="legend-item"><div class="legend-dot" style="background:#2a2a2a"></div>Burnt</div>
377
+ <div class="legend-item"><div class="legend-dot" style="background:#6b4226"></div>Firebreak</div>
378
+ <div class="legend-item"><div class="legend-dot" style="background:#1a2a1a;outline:2px solid #ffd700;outline-offset:-1px"></div>Asset</div>
379
+ <div class="legend-item"><div class="legend-dot" style="background:#1a2a1a;outline:2px solid #00cfff;outline-offset:-1px"></div>Crew</div>
380
+ </div>
381
+ </div>
382
+
383
+ <!-- ── RIGHT PANEL: State ── -->
384
+ <div class="panel">
385
+ <h2>Episode State</h2>
386
+
387
+ <div class="stat-row">
388
+ <span class="stat-label">Timestep</span>
389
+ <span class="stat-value" id="s-timestep">—</span>
390
+ </div>
391
+ <div class="stat-row">
392
+ <span class="stat-label">Containment</span>
393
+ <span class="stat-value" id="s-containment">—</span>
394
+ </div>
395
+ <div class="bar-wrap"><div class="bar-fill" id="containment-bar" style="width:0%"></div></div>
396
+
397
+ <div class="stat-row">
398
+ <span class="stat-label">Wind</span>
399
+ <span class="stat-value" id="s-wind">—</span>
400
+ </div>
401
+ <div class="stat-row">
402
+ <span class="stat-label">Last Reward</span>
403
+ <span class="stat-value" id="s-reward">—</span>
404
+ </div>
405
+ <div class="stat-row">
406
+ <span class="stat-label">Episode Done</span>
407
+ <span class="stat-value" id="s-done">—</span>
408
+ </div>
409
+
410
+ <hr class="section-divider">
411
+ <h2>Task Scores</h2>
412
+ <div class="score-grid">
413
+ <div class="score-card"><div class="sc-label">Task 1</div><div class="sc-value" id="sc-1">—</div></div>
414
+ <div class="score-card"><div class="sc-label">Task 2</div><div class="sc-value" id="sc-2">—</div></div>
415
+ <div class="score-card"><div class="sc-label">Task 3</div><div class="sc-value" id="sc-3">—</div></div>
416
+ </div>
417
+
418
+ <hr class="section-divider">
419
+ <h2>Assets at Risk</h2>
420
+ <div id="asset-list"><div style="color:#555;font-size:0.78rem">No assets in this task.</div></div>
421
+
422
+ <hr class="section-divider">
423
+ <h2>Crew Positions</h2>
424
+ <div id="crew-list"></div>
425
+ </div>
426
+
427
+ </main>
428
+
429
+ <script>
430
+ const BASE = 'window.location.origin';
431
+ let selectedAction = 'SUPPRESS';
432
+ let autoInterval = null;
433
+ let isPlaying = false;
434
+ let lastObs = null;
435
+
436
+ // ── Action selection ──
437
+ function selectAction(type, el) {
438
+ selectedAction = type;
439
+ document.querySelectorAll('.action-btn').forEach(b => b.classList.remove('selected'));
440
+ el.classList.add('selected');
441
+ }
442
+
443
+ // ── Logging ──
444
+ function log(msg, type = 'ok') {
445
+ const log = document.getElementById('step-log');
446
+ const entry = document.createElement('div');
447
+ entry.className = `log-entry ${type}`;
448
+ entry.textContent = `[${new Date().toLocaleTimeString()}] ${msg}`;
449
+ log.appendChild(entry);
450
+ log.scrollTop = log.scrollHeight;
451
+ }
452
+
453
+ // ── Reset ──
454
+ async function resetEnv() {
455
+ stopAuto();
456
+ const task = parseInt(document.getElementById('task-select').value);
457
+ try {
458
+ const res = await fetch(`${BASE}/reset`, {
459
+ method: 'POST',
460
+ headers: { 'Content-Type': 'application/json' },
461
+ body: JSON.stringify({ task })
462
+ });
463
+ const data = await res.json();
464
+ lastObs = data.observation;
465
+ renderState(data.observation, null);
466
+ log(`Reset → Task ${task}`, 'info');
467
+ await fetchGrader();
468
+ } catch (e) {
469
+ log(`Reset failed: ${e.message}`, 'err');
470
+ }
471
+ }
472
+
473
+ // ── Step ──
474
+ async function sendStep() {
475
+ const action = {
476
+ division_id: parseInt(document.getElementById('act-division').value),
477
+ crew_id: parseInt(document.getElementById('act-crew').value),
478
+ action_type: selectedAction,
479
+ target_cell: [
480
+ parseInt(document.getElementById('act-row').value),
481
+ parseInt(document.getElementById('act-col').value)
482
+ ]
483
+ };
484
+
485
+ try {
486
+ const res = await fetch(`${BASE}/step`, {
487
+ method: 'POST',
488
+ headers: { 'Content-Type': 'application/json' },
489
+ body: JSON.stringify(action)
490
+ });
491
+ const data = await res.json();
492
+ lastObs = data.observation;
493
+ renderState(data.observation, data.reward);
494
+ log(`Step t=${data.observation.timestep} | ${action.action_type} [${action.target_cell}] | reward=${data.reward.toFixed(4)} | done=${data.done}`, data.done ? 'info' : 'ok');
495
+ if (data.done) {
496
+ log('Episode complete!', 'info');
497
+ stopAuto();
498
+ await fetchGrader();
499
+ }
500
+ if (data.info?.error) log(`⚠ ${data.info.error}`, 'err');
501
+ } catch (e) {
502
+ log(`Step failed: ${e.message}`, 'err');
503
+ }
504
+ }
505
+
506
+ // ── Baseline ──
507
+ async function runBaseline() {
508
+ stopAuto();
509
+ log('Running baseline agent...', 'info');
510
+ try {
511
+ const res = await fetch(`${BASE}/baseline`);
512
+ const data = await res.json();
513
+ log(`Baseline done. Steps=${data.steps_taken} Reward=${data.total_reward.toFixed(4)}`, 'info');
514
+ updateScores(data.task_scores);
515
+ await refreshState();
516
+ } catch (e) {
517
+ log(`Baseline failed: ${e.message}`, 'err');
518
+ }
519
+ }
520
+
521
+ // ── Grader ──
522
+ async function fetchGrader() {
523
+ try {
524
+ const res = await fetch(`${BASE}/grader`);
525
+ const data = await res.json();
526
+ updateScores(data.task_scores);
527
+ } catch (e) {
528
+ log(`Grader failed:${e.message}`,'err')
529
+ }
530
+ }
531
+
532
+ function updateScores(scores) {
533
+ document.getElementById('sc-1').textContent = scores.task_1?.toFixed(2) ?? '—';
534
+ document.getElementById('sc-2').textContent = scores.task_2?.toFixed(2) ?? '—';
535
+ document.getElementById('sc-3').textContent = scores.task_3?.toFixed(2) ?? '—';
536
+ }
537
+
538
+ // ── Auto-play ──
539
+ async function autoPlay() {
540
+ if (isPlaying) { stopAuto(); return; }
541
+ isPlaying = true;
542
+ document.getElementById('auto-btn').textContent = '⏹ Stop Auto-Play';
543
+ autoInterval = setInterval(async () => {
544
+ if (!lastObs) { stopAuto(); return; }
545
+ const obs = lastObs;
546
+ const grid = obs.grid;
547
+
548
+ // Simple greedy: find busiest division, suppress nearest burning cell
549
+ let bestDiv = 0, bestCount = -1;
550
+ const divBounds = [
551
+ {rows:[0,9],cols:[0,9]}, {rows:[0,9],cols:[10,19]},
552
+ {rows:[10,19],cols:[0,9]}, {rows:[10,19],cols:[10,19]}
553
+ ];
554
+ divBounds.forEach((b, i) => {
555
+ let cnt = 0;
556
+ for (let r = b.rows[0]; r <= b.rows[1]; r++)
557
+ for (let c = b.cols[0]; c <= b.cols[1]; c++)
558
+ if (grid[r][c] === 1) cnt++;
559
+ if (cnt > bestCount) { bestCount = cnt; bestDiv = i; }
560
+ });
561
+
562
+ let targetCell = [5, 5];
563
+ const b = divBounds[bestDiv];
564
+ outer: for (let r = b.rows[0]; r <= b.rows[1]; r++)
565
+ for (let c = b.cols[0]; c <= b.cols[1]; c++)
566
+ if (grid[r][c] === 1) { targetCell = [r, c]; break outer; }
567
+
568
+ const action = {
569
+ division_id: bestDiv,
570
+ crew_id: obs.timestep % 2,
571
+ action_type: bestCount > 0 ? 'SUPPRESS' : 'HOLD',
572
+ target_cell: targetCell
573
+ };
574
+
575
+ try {
576
+ const res = await fetch(`${BASE}/step`, {
577
+ method: 'POST',
578
+ headers: { 'Content-Type': 'application/json' },
579
+ body: JSON.stringify(action)
580
+ });
581
+ const data = await res.json();
582
+ lastObs = data.observation;
583
+ renderState(data.observation, data.reward);
584
+ if (data.done) { stopAuto(); log('Auto-play done.', 'info'); await fetchGrader(); }
585
+ } catch (e) { stopAuto(); }
586
+ }, 300);
587
+ }
588
+
589
+ function stopAuto() {
590
+ if (autoInterval) clearInterval(autoInterval);
591
+ autoInterval = null;
592
+ isPlaying = false;
593
+ document.getElementById('auto-btn').textContent = '▶ Auto-Play (Baseline)';
594
+ }
595
+
596
+ // ── Refresh state ──
597
+ async function refreshState() {
598
+ try {
599
+ const res = await fetch(`${BASE}/state`);
600
+ const data = await res.json();
601
+ // Reconstruct a minimal obs from state
602
+ const s = data.state;
603
+ lastObs = { grid: s.grid, wind: s.wind, timestep: s.timestep, containment_pct: s.containment_pct, assets_at_risk: s.assets, crew_positions: s.crews, division_zones: [] };
604
+ renderState(lastObs, null);
605
+ } catch (e) {}
606
+ }
607
+
608
+ // ── Render ──
609
+ function renderState(obs, reward) {
610
+ renderGrid(obs);
611
+ renderStats(obs, reward);
612
+ renderAssets(obs.assets_at_risk || []);
613
+ renderCrews(obs.crew_positions || []);
614
+ }
615
+
616
+ function renderGrid(obs) {
617
+ const grid = obs.grid;
618
+ const assets = obs.assets_at_risk || [];
619
+ const crews = obs.crew_positions || [];
620
+
621
+ const assetCells = new Set(assets.map(a => `${a.cell[0]},${a.cell[1]}`));
622
+ const crewCells = new Set(crews.map(c => `${c.cell[0]},${c.cell[1]}`));
623
+
624
+ const container = document.getElementById('fire-grid');
625
+ container.innerHTML = '';
626
+
627
+ for (let r = 0; r < 20; r++) {
628
+ for (let c = 0; c < 20; c++) {
629
+ const val = grid[r][c];
630
+ const cell = document.createElement('div');
631
+ cell.className = `cell cell-${val}`;
632
+ if (val === 1) cell.classList.add('anim');
633
+ if (assetCells.has(`${r},${c}`)) cell.classList.add('cell-asset');
634
+ if (crewCells.has(`${r},${c}`)) cell.classList.add('cell-crew');
635
+ cell.title = `(${r},${c}) = ${['Clear','Burning','Burnt','Firebreak'][val]}`;
636
+ cell.addEventListener('click', () => {
637
+ document.getElementById('act-row').value = r;
638
+ document.getElementById('act-col').value = c;
639
+ });
640
+ container.appendChild(cell);
641
+ }
642
+ }
643
+ }
644
+
645
+ function renderStats(obs, reward) {
646
+ document.getElementById('s-timestep').textContent = obs.timestep ?? '—';
647
+ const pct = ((obs.containment_pct || 0) * 100).toFixed(1);
648
+ document.getElementById('s-containment').textContent = `${pct}%`;
649
+ document.getElementById('containment-bar').style.width = `${pct}%`;
650
+ document.getElementById('s-wind').textContent =
651
+ obs.wind ? `${obs.wind.direction} · ${obs.wind.speed}` : '—';
652
+ if (reward !== null) {
653
+ const rEl = document.getElementById('s-reward');
654
+ rEl.textContent = reward.toFixed(4);
655
+ rEl.className = 'stat-value ' + (reward >= 0 ? 'good' : 'bad');
656
+ }
657
+ document.getElementById('s-done').textContent = obs.done ? '✅ Yes' : '🔄 No';
658
+ }
659
+
660
+ function renderAssets(assets) {
661
+ const el = document.getElementById('asset-list');
662
+ if (!assets.length) {
663
+ el.innerHTML = '<div style="color:#555;font-size:0.78rem">No assets in this task.</div>';
664
+ return;
665
+ }
666
+ el.innerHTML = assets.map(a => `
667
+ <div class="asset-item">
668
+ <span>🏠 ${a.name}</span>
669
+ <span class="asset-status ${a.status}">${a.status === 'safe' ? '✓ Safe' : '✗ Burned'}</span>
670
+ </div>
671
+ `).join('');
672
+ }
673
+
674
+ function renderCrews(crews) {
675
+ const el = document.getElementById('crew-list');
676
+ const divLabels = ['A','B','C','D'];
677
+ el.innerHTML = crews.map(c => `
678
+ <div class="crew-item">
679
+ <div class="crew-dot"></div>
680
+ <span>Crew ${c.id}</span>
681
+ <span>[${c.cell[0]},${c.cell[1]}]</span>
682
+ <span class="crew-div">Div ${divLabels[c.division] || c.division}</span>
683
+ </div>
684
+ `).join('');
685
+ }
686
+
687
+ // ── Boot ──
688
+ resetEnv();
689
+ </script>
690
+ </body>
691
+ </html>