Skip to content

Commit

Permalink
Show "Engine is down." in trouble instead of "Engine is loading..."
Browse files Browse the repository at this point in the history
  • Loading branch information
Hiraoka committed Sep 26, 2020
1 parent 5571603 commit 9ed6b84
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 11 deletions.
27 changes: 17 additions & 10 deletions src/main/java/featurecat/lizzie/analysis/Leelaz.java
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ public class Leelaz {
private int currentEngineN = -1;
private ScheduledExecutorService executor;
private boolean isQuittingNormally = false;
private boolean isDown = false;

// dynamic komi and opponent komi as reported by dynamic-komi version of leelaz
private float dynamicKomi = Float.NaN;
Expand Down Expand Up @@ -138,6 +139,7 @@ public void startEngine() throws IOException {
isLoaded = false;
isKataGo = false;
isQuittingNormally = false;
isDown = false;
bestMoves = new ArrayList<>();
Lizzie.board.getData().tryToClearBestMoves();

Expand Down Expand Up @@ -183,10 +185,8 @@ public void startEngine() throws IOException {
String err = e.getLocalizedMessage();
String message =
String.format(
"Failed to start the engine.\n\nError: %s\nEngine command: %s",
(err == null) ? "(No message)" : err, engineCommand);
JOptionPane.showMessageDialog(
Lizzie.frame, message, "Lizzie - Error!", JOptionPane.ERROR_MESSAGE);
"Failed to start the engine.\n\nError: %s", (err == null) ? "(No message)" : err);
alertEngineDown(message);
throw e;
}

Expand Down Expand Up @@ -229,6 +229,13 @@ public void restartEngine() throws IOException {
togglePonder();
}

private void alertEngineDown(String message) {
isDown = true;
String displayedMessage = String.format("%s\n\nEngine command: %s", message, engineCommand);
JOptionPane.showMessageDialog(
Lizzie.frame, displayedMessage, "Lizzie - Error!", JOptionPane.ERROR_MESSAGE);
}

public void normalQuit() {
isQuittingNormally = true;
sendCommand("quit");
Expand Down Expand Up @@ -469,12 +476,8 @@ private void read() {
// this line will be reached when Leelaz shuts down
System.out.println("Engine process ended.");
if (!isQuittingNormally) {
String message =
String.format(
"Engine process ended unintentionally for some reason.\n\nEngine command: %s",
engineCommand);
JOptionPane.showMessageDialog(
Lizzie.frame, message, "Lizzie - Error!", JOptionPane.ERROR_MESSAGE);
alertEngineDown(
"Engine process ended unintentionally for some reason.\nYou may find more information in GTP console.");
}

shutdown();
Expand Down Expand Up @@ -952,6 +955,10 @@ public boolean isLoaded() {
return isLoaded;
}

public boolean isDown() {
return isDown;
}

public boolean supportScoremean() {
return isKataGo || supportScoremean;
}
Expand Down
5 changes: 4 additions & 1 deletion src/main/java/featurecat/lizzie/gui/LizzieFrame.java
Original file line number Diff line number Diff line change
Expand Up @@ -667,7 +667,10 @@ public void paintMainPanel(Graphics g0) {
}
}
} else if (Lizzie.config.showStatus) {
String loadingText = resourceBundle.getString("LizzieFrame.display.loading");
String loadingText =
(Lizzie.leelaz != null) && Lizzie.leelaz.isDown()
? "Engine is down."
: resourceBundle.getString("LizzieFrame.display.loading");
drawPonderingState(g, loadingText, loadingX, loadingY, loadingSize);
}

Expand Down

0 comments on commit 9ed6b84

Please sign in to comment.