diff --git a/src/main/java/featurecat/lizzie/analysis/Leelaz.java b/src/main/java/featurecat/lizzie/analysis/Leelaz.java index 438f9f2fc..f1a0610a6 100644 --- a/src/main/java/featurecat/lizzie/analysis/Leelaz.java +++ b/src/main/java/featurecat/lizzie/analysis/Leelaz.java @@ -9,7 +9,6 @@ import java.io.BufferedInputStream; import java.io.BufferedOutputStream; import java.io.IOException; -import java.util.ArrayDeque; import java.util.ArrayList; import java.util.List; import java.util.Optional; @@ -38,7 +37,6 @@ public class Leelaz { private long maxAnalyzeTimeMillis; // , maxThinkingTimeMillis; private int cmdNumber; private int currentCmdNum; - private ArrayDeque cmdQueue; private boolean isModifyingBoard = false; private Process process; @@ -104,8 +102,7 @@ public Leelaz(String engineCommand) throws JSONException { isPondering = false; startPonderTime = System.currentTimeMillis(); cmdNumber = 1; - currentCmdNum = 0; - cmdQueue = new ArrayDeque<>(); + currentCmdNum = -1; // Move config to member for other method call config = Lizzie.config.config.getJSONObject("leelaz"); @@ -365,8 +362,6 @@ private void parseLine(String line) { String[] params = line.trim().split(" "); currentCmdNum = Integer.parseInt(params[0].substring(1).trim()); - trySendCommandFromQueue(); - if (line.startsWith("?") || params.length == 1) return; if (isSettingHandicap) { @@ -464,56 +459,12 @@ private void read() { } } - /** - * Sends a command to command queue for leelaz to execute - * - * @param command a GTP command containing no newline characters - */ - public void sendCommand(String command) { - synchronized (cmdQueue) { - // For efficiency, delete unnecessary "lz-analyze" that will be stopped immediately - if (!cmdQueue.isEmpty() - && (cmdQueue.peekLast().startsWith("lz-analyze") - || cmdQueue.peekLast().startsWith("kata-analyze"))) { - cmdQueue.removeLast(); - } - cmdQueue.addLast(command); - trySendCommandFromQueue(); - if (Lizzie.frame.isAutoEstimating) { - if (command.startsWith("play") || command.startsWith("undo")) { - Lizzie.frame.zen.sendCommand(command); - Lizzie.frame.zen.countStones(); - } - } - } - } - - /** Sends a command from command queue for leelaz to execute if it is ready */ - private void trySendCommandFromQueue() { - // Defer sending "lz-analyze" if leelaz is not ready yet. - // Though all commands should be deferred theoretically, - // only "lz-analyze" is deferred here for fear of - // possible hang-up by missing response for some reason. - // cmdQueue can be replaced with a mere String variable in this case, - // but it is kept for future change of our mind. - synchronized (cmdQueue) { - if (cmdQueue.isEmpty() - || (cmdQueue.peekFirst().startsWith("lz-analyze") - || cmdQueue.peekFirst().startsWith("kata-analyze")) - && !isResponseUpToDate()) { - return; - } - String command = cmdQueue.removeFirst(); - sendCommandToLeelaz(command); - } - } - /** * Sends a command for leelaz to execute * * @param command a GTP command containing no newline characters */ - private void sendCommandToLeelaz(String command) { + public void sendCommand(String command) { if (command.startsWith("fixed_handicap") || (isKataGo && command.startsWith("place_free_handicap"))) isSettingHandicap = true; if (printCommunication) {