Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,14 @@ public static class TimeoutException extends Exception {
private List<String> inputs = new ArrayList<>();
private List<String> outputs;
private boolean timeout;
private int timelimit;
private int score;
private boolean hasBeenExecuted;
private boolean hasNeverBeenExecuted = true;
private long lastExecutionTimeMs = -1;
private int timelimitsExceeded = 0;
private boolean timelimitExceededLastTurn = false;
private final int MAX_SOFT_TIMELIMIT_EXCEEDS = 2;

/**
* Returns a string that will be converted into the real nickname by the viewer.
Expand Down Expand Up @@ -79,6 +83,10 @@ void setScore(int score) {
this.score = score;
}

void setTimelimit(int timelimit) {
this.timelimit = timelimit;
}

/**
* Adds a new line to the input to send to the player on execute.
*
Expand All @@ -102,6 +110,9 @@ public final void execute() {
gameManagerProvider.get().execute(this);
this.hasBeenExecuted = true;
this.hasNeverBeenExecuted = false;
this.timelimitExceededLastTurn = getLastExectionTimeMs() > this.timelimit;
if (this.timelimitExceededLastTurn) this.timelimitsExceeded++;
if (this.timelimitsExceeded > MAX_SOFT_TIMELIMIT_EXCEEDS) this.timeout = true;
}

/**
Expand Down Expand Up @@ -183,4 +194,12 @@ final public void setLastExecutionTimeMs(long ms) {
public long getLastExectionTimeMs() {
return lastExecutionTimeMs;
}

public int getTimelimitsExceeded() {
return timelimitsExceeded;
}

public boolean hasTimelimitExceededLastTurn() {
return timelimitExceededLastTurn;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ abstract public class GameManager<T extends AbstractPlayer> {
private static final int GAME_DURATION_SOFT_QUOTA = 25_000;
private static final int MAX_TURN_TIME = GAME_DURATION_SOFT_QUOTA;
private static final int MIN_TURN_TIME = 50;
private static final int SOFT_TIMELIMIT_EXTRA = 50;

protected List<T> players;
private int maxTurns = 200;
Expand Down Expand Up @@ -196,7 +197,9 @@ protected void execute(T player, int nbrOutputLines) {
if (nbrOutputLines > 0) {
addTurnTime();
}
dumpNextPlayerInfos(player.getIndex(), nbrOutputLines, player.hasNeverBeenExecuted() ? firstTurnMaxTime : turnMaxTime);
int timelimit = player.hasNeverBeenExecuted() ? firstTurnMaxTime : turnMaxTime;
player.setTimelimit(timelimit);
dumpNextPlayerInfos(player.getIndex(), nbrOutputLines, timelimit + SOFT_TIMELIMIT_EXTRA);

// READ PLAYER OUTPUTS
iCmd = InputCommand.parse(s.nextLine());
Expand Down