adityaverma977 commited on
Commit
98e2ee8
·
1 Parent(s): bc3902d

Compute report from tick events and store full tick messages

Browse files
Files changed (1) hide show
  1. frontend/app/page.tsx +38 -23
frontend/app/page.tsx CHANGED
@@ -16,11 +16,13 @@ export default function Page() {
16
  if (!history || history.length === 0) return null
17
  const rounds = history.length
18
  const last = history[history.length - 1]
19
- const models = (last.agents || []).map((a: any) => ({ id: a.model_name, display_name: a.display_name || a.model_name }))
 
20
 
21
  const per = models.map((m: any) => {
22
  const positions = history.map(h => {
23
- const a = (h.agents || []).find((x: any) => x.model_name === m.id)
 
24
  return a ? { x: a.x, y: a.y, water: a.water_collected, status: a.status, extinguish_score: a.extinguish_score || 0, last_message: a.last_message } : null
25
  }).filter(Boolean)
26
 
@@ -38,22 +40,34 @@ export default function Page() {
38
  let logical_checks = 0
39
  const messages: Record<string, number> = {}
40
 
41
- for (let i = 0; i < positions.length; i++) {
42
- const cur = positions[i]
43
- if (cur.last_message) messages[cur.last_message] = (messages[cur.last_message]||0)+1
44
- if (i>0) {
45
- const prev = positions[i-1]
46
- if (!prev.water && cur.water) water_picks++
47
- // logical check: when searching, distance to nearest water should decrease
48
- if (cur.status === 'searching') {
49
- // compute nearest water in this tick
50
- const h = history[i]
51
- const ws = h.water_sources || []
52
- if (ws.length>0) {
53
- const distPrev = Math.min(...ws.map((w: any)=> Math.hypot(prev.x - w.x, prev.y - w.y)))
54
- const distCur = Math.min(...ws.map((w: any)=> Math.hypot(cur.x - w.x, cur.y - w.y)))
55
- logical_checks++
56
- if (distCur <= distPrev) logical_moves++
 
 
 
 
 
 
 
 
 
 
 
 
57
  }
58
  }
59
  }
@@ -80,7 +94,8 @@ export default function Page() {
80
  const tracks: Record<string, { x: number; y: number }[]> = {}
81
  if (!history || history.length === 0) return tracks
82
  for (const h of history) {
83
- for (const a of h.agents || []) {
 
84
  if (!tracks[a.model_name]) tracks[a.model_name] = []
85
  tracks[a.model_name].push({ x: a.x, y: a.y })
86
  }
@@ -137,9 +152,9 @@ export default function Page() {
137
 
138
  const ws = createSimulationSocket(
139
  simState.simulation_id,
140
- (msg) => {
141
- // store each tick state snapshot for post-game analysis
142
- if (msg.state) setTickHistory(prev => [...prev, msg.state])
143
  if (msg.type === "finished") {
144
  if (msg.state) {
145
  setSimState(msg.state)
@@ -172,7 +187,7 @@ export default function Page() {
172
  setWinnerLabel(msg.state.winner_model || null)
173
  setAppState("gameover")
174
  // prepare report
175
- const report = buildReport([...tickHistory, msg.state])
176
  setReportData(report)
177
  }
178
  },
 
16
  if (!history || history.length === 0) return null
17
  const rounds = history.length
18
  const last = history[history.length - 1]
19
+ const lastState = last.state || last
20
+ const models = (lastState.agents || []).map((a: any) => ({ id: a.model_name, display_name: a.display_name || a.model_name }))
21
 
22
  const per = models.map((m: any) => {
23
  const positions = history.map(h => {
24
+ const state = h.state || h
25
+ const a = (state.agents || []).find((x: any) => x.model_name === m.id)
26
  return a ? { x: a.x, y: a.y, water: a.water_collected, status: a.status, extinguish_score: a.extinguish_score || 0, last_message: a.last_message } : null
27
  }).filter(Boolean)
28
 
 
40
  let logical_checks = 0
41
  const messages: Record<string, number> = {}
42
 
43
+ // Count events (decisions/messages, water pickups) across ticks
44
+ for (let i = 0; i < history.length; i++) {
45
+ const tick = history[i]
46
+ const events = tick.events || []
47
+ for (const ev of events) {
48
+ if (ev.type === 'message' && ev.model === m.id) {
49
+ messages[ev.content] = (messages[ev.content] || 0) + 1
50
+ }
51
+ if (ev.type === 'water_collected' && ev.model === m.id) {
52
+ water_picks++
53
+ }
54
+ }
55
+
56
+ // logical move checks based on consecutive positions
57
+ if (i > 0) {
58
+ const prevState = history[i-1].state || history[i-1]
59
+ const curState = history[i].state || history[i]
60
+ const prevA = (prevState.agents || []).find((x: any) => x.model_name === m.id)
61
+ const curA = (curState.agents || []).find((x: any) => x.model_name === m.id)
62
+ if (prevA && curA) {
63
+ if (curA.status === 'searching') {
64
+ const ws = curState.water_sources || []
65
+ if (ws.length > 0) {
66
+ const distPrev = Math.min(...ws.map((w: any)=> Math.hypot(prevA.x - w.x, prevA.y - w.y)))
67
+ const distCur = Math.min(...ws.map((w: any)=> Math.hypot(curA.x - w.x, curA.y - w.y)))
68
+ logical_checks++
69
+ if (distCur <= distPrev) logical_moves++
70
+ }
71
  }
72
  }
73
  }
 
94
  const tracks: Record<string, { x: number; y: number }[]> = {}
95
  if (!history || history.length === 0) return tracks
96
  for (const h of history) {
97
+ const state = h.state || h
98
+ for (const a of state.agents || []) {
99
  if (!tracks[a.model_name]) tracks[a.model_name] = []
100
  tracks[a.model_name].push({ x: a.x, y: a.y })
101
  }
 
152
 
153
  const ws = createSimulationSocket(
154
  simState.simulation_id,
155
+ (msg) => {
156
+ // store the full tick message (state + events) for richer analysis
157
+ setTickHistory(prev => [...prev, msg])
158
  if (msg.type === "finished") {
159
  if (msg.state) {
160
  setSimState(msg.state)
 
187
  setWinnerLabel(msg.state.winner_model || null)
188
  setAppState("gameover")
189
  // prepare report
190
+ const report = buildReport([...tickHistory, msg])
191
  setReportData(report)
192
  }
193
  },