Skip to content

add soft-timeout#78

Open
eulerscheZahl wants to merge 3 commits intoCodinGame:masterfrom
eulerscheZahl:master
Open

add soft-timeout#78
eulerscheZahl wants to merge 3 commits intoCodinGame:masterfrom
eulerscheZahl:master

Conversation

@eulerscheZahl
Copy link
Copy Markdown
Contributor

@eulerscheZahl eulerscheZahl commented Mar 24, 2026

In the recent contest we saw a high timeout rate, especially when the servers were busy on league opening, in the last hours of the contest and and the final rerun. This affected a lot of players even at the top of legend, so it seems to be a platform issue rather than players suddenly forgetting how to measure time. The contestant programs just get a random delay, sometimes 20 milliseconds long - and they lose the game because of it.
image
image
image

I understand that it's hard to prevent the server from doing any other tasks that affect program performance for contestants.
This commit is one suggestion to at least reduce the consequences of such a random delay by modifying the existing behaviour and introducing a new one.

Turn-based timing with 3-strikes rule

It lets each program run for an extra 50 milliseconds, but also checks if those extra 50ms were necessary. If they weren't, all is fine. Otherwise it counts as one strike, violating the time limit. If a bot exceeds the limit 3 times in the same match, it gets eliminated with a regular timeout exception. If even the additional 50ms don't help, the player can also get eliminated immediately.
Test link: https://www.codingame.com/ide/demo/1455013cb304fa9512c0f8525f73702f6e4a0c4

Timebank

Instead of setting a limit for each turn, the players get a time limit for the whole game. They can freely choose to use more time in one turn and less in another. This way a random delay won't be as punishing.
Test link: https://www.codingame.com/ide/demo/1455539e9339ee30ac7742e9204900bb7877948
note the changed input protocol, the remaining timebank is the first turn input, before powerSourceCount

Usage of those features

The game creator decides, if they want to use the classic per-turn way or the new timebank.
For the classic way no changes to the referee are needed, it will just work. For the timebank there has to be a call to setTimebank, e.g. gameManager.setTimebank(10000);. When setting the timebank, it's not allowed to also call setTurnMaxTime.

@eulerscheZahl eulerscheZahl marked this pull request as draft March 24, 2026 19:25
@eulerscheZahl
Copy link
Copy Markdown
Contributor Author

Back to draft, discussing with others first.
Checking the time even when successfully reading from bot stdout certainly isn't ideal:

long current = System.nanoTime();
if ((current - t0) > (timeout * 1_000_000l)) {
break;
}

And https://github.com/CodinGame/codingame-game-engine/blob/51a875604e5b736608666d49f6dde81ec191b033/runner/src/main/java/com/codingame/gameengine/runner/Agent.java#L124C21-L124C46
can be 0, even if input exists

available() is not reliable for piped input. It checks if there is data in the current process' input buffer. It has no way to check if preceding (pipe-wise) process is about to send some data.

@eulerscheZahl eulerscheZahl marked this pull request as ready for review March 27, 2026 09:41
@eulerscheZahl
Copy link
Copy Markdown
Contributor Author

Back to review. DomiKo's changes affect another component (the runner), while this PR focuses on gameengine.core, so they can be separate PRs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant