Skip to content

Commit e5c6b16

Browse files
author
Builder
committed
Merge branch 'fix-quota' into 'master'
[SDK][FIX] reduce game summary quota to acceptable level See merge request codingame/game-engine!127
2 parents 1799be0 + 0018730 commit e5c6b16

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

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

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,10 @@ abstract public class GameManager<T extends AbstractPlayer> {
2929
@Inject private Gson gson;
3030
protected static Log log = LogFactory.getLog(GameManager.class);
3131

32-
private static final int VIEW_DATA_SOFT_QUOTA = 512 * 1024;
33-
private static final int VIEW_DATA_HARD_QUOTA = 1024 * 1024;
34-
private static final int GAME_SUMMARY_HARD_QUOTA = 512 * 1024;
32+
private static final int VIEW_DATA_TOTAL_SOFT_QUOTA = 512 * 1024;
33+
private static final int VIEW_DATA_TOTAL_HARD_QUOTA = 1024 * 1024;
34+
private static final int GAME_SUMMARY_TOTAL_HARD_QUOTA = 512 * 1024;
35+
private static final int GAME_SUMMARY_PER_TURN_HARD_QUOTA = 800;
3536
private static final int GAME_TURN_SOFT_QUOTA = 200;
3637

3738
protected List<T> players;
@@ -65,6 +66,7 @@ abstract public class GameManager<T extends AbstractPlayer> {
6566
private boolean initDone = false;
6667
private boolean outputsRead = false;
6768
private int totalViewDataBytesSent = 0;
69+
private int totalGameSummaryBytes = 0;
6870

6971
/**
7072
* GameManager main loop.
@@ -237,9 +239,9 @@ private void dumpView() {
237239
String viewData = data.toString();
238240

239241
totalViewDataBytesSent += viewData.length();
240-
if (totalViewDataBytesSent > VIEW_DATA_HARD_QUOTA) {
242+
if (totalViewDataBytesSent > VIEW_DATA_TOTAL_HARD_QUOTA) {
241243
throw new RuntimeException("The amount of data sent to the viewer is too big!");
242-
} else if (totalViewDataBytesSent > VIEW_DATA_SOFT_QUOTA) {
244+
} else if (totalViewDataBytesSent > VIEW_DATA_TOTAL_SOFT_QUOTA) {
243245
log.warn("Warning: the amount of data sent to the viewer is too big.\nPlease try to optimize your code to send less data (try replacing some commitEntityStates by a commitWorldState).");
244246
}
245247

@@ -365,7 +367,7 @@ public boolean isGameEnd() {
365367
public void setMaxTurns(int maxTurns) throws IllegalArgumentException {
366368
if (maxTurns <= 0) {
367369
throw new IllegalArgumentException("Invalid maximum number of turns");
368-
}else if (maxTurns > GAME_TURN_SOFT_QUOTA) {
370+
} else if (maxTurns > GAME_TURN_SOFT_QUOTA) {
369371
log.warn("The maximum number of turns is very high, please try to stay under 200 turns.");
370372
}
371373
this.maxTurns = maxTurns;
@@ -473,8 +475,10 @@ public void addToGameSummary(String summary) {
473475
int total = this.currentGameSummary.stream()
474476
.mapToInt(String::length)
475477
.sum();
476-
if (total < GAME_SUMMARY_HARD_QUOTA) {
478+
479+
if (total < GAME_SUMMARY_PER_TURN_HARD_QUOTA && total + totalGameSummaryBytes < GAME_SUMMARY_TOTAL_HARD_QUOTA) {
477480
this.currentGameSummary.add(summary);
481+
totalGameSummaryBytes += total;
478482
} else {
479483
log.warn("Warning: the game summary is full. Please try to send less data.");
480484
}

0 commit comments

Comments
 (0)