Skip to content

Commit f44489d

Browse files
author
Jay Ng
committed
fix(sdk test.html): output always shown at player 0
1 parent 9e7fee0 commit f44489d

File tree

1 file changed

+18
-3
lines changed
  • runner/src/main/resources/view

1 file changed

+18
-3
lines changed

runner/src/main/resources/view/app.js

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@ function PlayerCtrl ($scope, $timeout, $interval, $element) {
126126
}
127127

128128
function onFrameChange (frame) {
129+
// one frame in this method is one game turn, and contians subframes for each agent's actions
129130
for (let i in ctrl.data.ids) {
130131
$scope.agents[i].stdout = null
131132
$scope.agents[i].stderr = null
@@ -134,7 +135,14 @@ function PlayerCtrl ($scope, $timeout, $interval, $element) {
134135
$scope.referee = {}
135136
const frameData = ctrl.parsedGameInfo.frames[frame]
136137
for (let i in ctrl.data.ids) {
137-
const subframe = frameData.subframes[i]
138+
let subframe
139+
if (frameData.subframes.length > 1) {
140+
subframe = frameData.subframes[i]
141+
} else {
142+
if (frameData.subframes[0].agentId === i) {
143+
subframe = frameData.subframes[0]
144+
}
145+
}
138146
if (subframe) {
139147
if (subframe.stdout) {
140148
$scope.agents[i].stdout = subframe.stdout
@@ -148,9 +156,11 @@ function PlayerCtrl ($scope, $timeout, $interval, $element) {
148156
$scope.referee.stdout = frameData.referee.stdout
149157
$scope.referee.stderr = frameData.referee.stderr
150158
$scope.summary = frameData.gameSummary
159+
console.log(frameData)
151160
}
152161

153162
function convertFrameFormat (data) {
163+
// one frame in this method means one output, if in a single game turn two agents act, the two actions are put in separate frames
154164
const frames = data.views.map(v => {
155165
let f = v.split('\n')
156166
let header = f[0].split(' ')
@@ -168,12 +178,17 @@ function PlayerCtrl ($scope, $timeout, $interval, $element) {
168178
frames[i].referee[newKey] = data[key].referee[i]
169179
}
170180
}
171-
172181
for (let pi in data.ids) {
173182
frames[i].stderr = frames[i].stderr || data.errors[pi][i]
174183
frames[i].stdout = frames[i].stdout || data.outputs[pi][i]
184+
for (let agentId in data.outputs) {
185+
let output = data.outputs[agentId]
186+
// check that at turn i, agent has output not null, so it is agent's turn
187+
if (output[i] != null && agentId !== 'referee') {
188+
frames[i].agentId = agentId
189+
}
190+
}
175191
}
176-
frames[i].agentId = -1
177192
}
178193
const agents = data.agents.map(a => Object.assign(a, { avatarUrl: a.avatar }))
179194
const tooltips = data.tooltips.map(JSON.stringify)

0 commit comments

Comments
 (0)