Skip to content

Commit

Permalink
Fixes game resumed after a time forfeit froze
Browse files Browse the repository at this point in the history
  • Loading branch information
fathzer committed Dec 6, 2024
1 parent 416830c commit 3a67a64
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 6 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ If you specify a value for the `gameCount` system property while starting the ap


# Known bugs
- When no time control is set, some engines never replies
- When a game is continued after a time forfeit, its PGN still mention the initial time control.
- When a engine that is used in player settings hangs, it leaves settings in a wrong state with no possibility to fix it; The application should be restarted.

Expand Down
1 change: 1 addition & 0 deletions src/main/java/com/fathzer/games/game/Game.java
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ public void run() {
}

private void requestMove(Color color) {
log.debug("Game {} request move from {} player", id, color);
getPlayer(color).requestMove(this, m -> this.addEvent(new MoveEvent<>(m)));
}

Expand Down
6 changes: 5 additions & 1 deletion src/main/java/com/fathzer/games/game/GameManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@ private void endOfGame(final Status status) {
// Replace game by the same one returned (for instance, the same game without clock)
this.game = resumed.get();
log.debug("Continue ended with another game at same position, state: {}", getState());
onNewGame(this.game);
setState(State.RUNNING);
} else {
log.debug("End of game, state: {}", getState());
Expand All @@ -184,8 +185,11 @@ private void endOfGame(final Status status) {
}
}

/** Gets a new game to start just after a game just ended.
* <br>A typical use of this method is to allow a game lost by time forfeit to be resumed without a clock.
* @return an empty option if the game should not be resumed or the game to resume.
*/
protected Optional<Game<M,B>> getResumedGame() {
//TODO comment
return Optional.empty();
}

Expand Down
7 changes: 2 additions & 5 deletions src/main/java/com/fathzer/jchess/bot/EnginePlayer.java
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public synchronized void requestMove(Game<Move, Board<Move>> game, Consumer<Move
currentSearch.set(null);
}
} catch (Exception e) {
log.error("An error occurred while searching for move, declare the engine dead");
log.error("An error occurred while searching for move, declare the engine dead", e);
callBack.accept(null);
return null;
}
Expand Down Expand Up @@ -115,10 +115,7 @@ private Optional<Move> getMove(Game<Move, Board<Move>> game) throws IOException
final int movesToGo = clock.getRemainingMovesBeforeNext(clock.getPlaying());
params = new CountDownState(remainingTime, increment, movesToGo);
}
if (params==null) {
System.out.println("We are fucked"); //TODO
}
if (params.getRemainingMs()<0) {
if (params!=null && params.getRemainingMs()<0) {
return Optional.empty();
}
return Optional.of(JChessUCIEngine.toMove(history.getBoard(), UCIMove.from(engine.getMove(params))));
Expand Down

0 comments on commit 3a67a64

Please sign in to comment.