Skip to content

Commit 064f187

Browse files
committed
feat(sdk): creating a frame by default at the end of each gameTurn
1 parent e1349d0 commit 064f187

File tree

1 file changed

+21
-2
lines changed

1 file changed

+21
-2
lines changed

engine/core/src/main/java/com/codingame/gameengine/core/GameManager.java

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,13 @@ void start(InputStream is, PrintStream out) {
122122
referee.gameTurn(turn);
123123
registeredModules.forEach(Module::onAfterGameTurn);
124124

125+
// Create a frame if no player has been executed
126+
if (players.stream().noneMatch(p -> p.hasBeenExecuted())) {
127+
for (T player : players) {
128+
execute(player, 0);
129+
}
130+
}
131+
125132
// reset players' outputs
126133
for (AbstractPlayer player : players) {
127134
player.resetOutputs();
@@ -163,8 +170,10 @@ void start(InputStream is, PrintStream out) {
163170
*
164171
* @param player
165172
* Player to execute.
173+
* @param nbrOutputLines
174+
* The amount of expected output lines from the player.
166175
*/
167-
void execute(T player) {
176+
protected void execute(T player, int nbrOutputLines) {
168177
if (!this.initDone) {
169178
throw new RuntimeException("Impossible to execute a player during init phase.");
170179
}
@@ -180,7 +189,7 @@ void execute(T player) {
180189
dumpView();
181190
dumpInfos();
182191
dumpNextPlayerInput(player.getInputs().toArray(new String[0]));
183-
if (player.getExpectedOutputLines() > 0) {
192+
if (nbrOutputLines > 0) {
184193
addTurnTime();
185194
}
186195
dumpNextPlayerInfos(player.getIndex(), player.getExpectedOutputLines(), player.hasNeverBeenExecuted() ? firstTurnMaxTime : turnMaxTime);
@@ -203,6 +212,16 @@ void execute(T player) {
203212
newTurn = false;
204213
}
205214

215+
/**
216+
* Executes a player for a maximum of turnMaxTime milliseconds and store the output. Used by player.execute().
217+
*
218+
* @param player
219+
* Player to execute.
220+
*/
221+
void execute(T player) {
222+
execute(player, player.getExpectedOutputLines());
223+
}
224+
206225
/**
207226
* Swap game summary and view.
208227
*

0 commit comments

Comments
 (0)