Skip to content

Commit

Permalink
revert c71ad4f 526c9f7 69dedf4 (command queue) for featurecat#752 (Fo…
Browse files Browse the repository at this point in the history
…x SGF)
  • Loading branch information
Hiraoka committed Sep 20, 2020
1 parent aa7a276 commit bbb910a
Showing 1 changed file with 2 additions and 51 deletions.
53 changes: 2 additions & 51 deletions src/main/java/featurecat/lizzie/analysis/Leelaz.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -38,7 +37,6 @@ public class Leelaz {
private long maxAnalyzeTimeMillis; // , maxThinkingTimeMillis;
private int cmdNumber;
private int currentCmdNum;
private ArrayDeque<String> cmdQueue;
private boolean isModifyingBoard = false;

private Process process;
Expand Down Expand Up @@ -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");
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit bbb910a

Please sign in to comment.