Skip to content

Commit a61de8a

Browse files
Merge branch 'fix-sdk-output-always-shown-at-player-0-bug24' into 'master'
fix(sdk test.html): output always shown at player 0 | bug #24 See merge request codingame/game-engine!251
2 parents 9e7fee0 + 7149c64 commit a61de8a

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

playground/misc/misc-3-release-notes.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ The CodinGame SDK is regularly updated and improved. This document lets you know
1111
### 🐞 Bug fix
1212

1313
- Report malformed JSON error instead of crashing when there are invalid JSON files in assets folder
14+
- Fixed game replay where output always shown at player 0 for games in which not all players act each turn
1415

1516
## 3.9.0
1617

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

Lines changed: 12 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 contains 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,7 @@ 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+
const subframe = frameData.subframes.find(subframe => subframe.agentId === i)
138139
if (subframe) {
139140
if (subframe.stdout) {
140141
$scope.agents[i].stdout = subframe.stdout
@@ -148,9 +149,11 @@ function PlayerCtrl ($scope, $timeout, $interval, $element) {
148149
$scope.referee.stdout = frameData.referee.stdout
149150
$scope.referee.stderr = frameData.referee.stderr
150151
$scope.summary = frameData.gameSummary
152+
console.log(frameData)
151153
}
152154

153155
function convertFrameFormat (data) {
156+
// 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
154157
const frames = data.views.map(v => {
155158
let f = v.split('\n')
156159
let header = f[0].split(' ')
@@ -168,12 +171,18 @@ function PlayerCtrl ($scope, $timeout, $interval, $element) {
168171
frames[i].referee[newKey] = data[key].referee[i]
169172
}
170173
}
171-
172174
for (let pi in data.ids) {
173175
frames[i].stderr = frames[i].stderr || data.errors[pi][i]
174176
frames[i].stdout = frames[i].stdout || data.outputs[pi][i]
177+
for (let agentId in data.outputs) {
178+
let output = data.outputs[agentId]
179+
// check that at turn i, agent has output not null, so it is agent's turn
180+
if (output[i] != null && agentId !== 'referee') {
181+
frames[i].agentId = agentId
182+
break
183+
}
184+
}
175185
}
176-
frames[i].agentId = -1
177186
}
178187
const agents = data.agents.map(a => Object.assign(a, { avatarUrl: a.avatar }))
179188
const tooltips = data.tooltips.map(JSON.stringify)

0 commit comments

Comments
 (0)