mirror of
https://github.com/peterosterlund2/droidfish.git
synced 2025-12-19 20:22:18 +01:00
DroidFish: Don't send UCI options that an engine doesn't understand.
This commit is contained in:
@@ -570,6 +570,7 @@ public class DroidComputerPlayer {
|
|||||||
});
|
});
|
||||||
engineMonitor.start();
|
engineMonitor.start();
|
||||||
|
|
||||||
|
uciEngine.clearOptions();
|
||||||
uciEngine.writeLineToEngine("uci");
|
uciEngine.writeLineToEngine("uci");
|
||||||
int nThreads = getNumCPUs();
|
int nThreads = getNumCPUs();
|
||||||
if (nThreads > 8) nThreads = 8;
|
if (nThreads > 8) nThreads = 8;
|
||||||
@@ -615,9 +616,8 @@ public class DroidComputerPlayer {
|
|||||||
|
|
||||||
switch (engineState.state) {
|
switch (engineState.state) {
|
||||||
case READ_OPTIONS: {
|
case READ_OPTIONS: {
|
||||||
if (readUCIOption(s)) {
|
if (readUCIOption(uci, s)) {
|
||||||
uci.initOptions();
|
uci.initOptions();
|
||||||
uci.setOption("Ponder", false);
|
|
||||||
uci.writeLineToEngine("ucinewgame");
|
uci.writeLineToEngine("ucinewgame");
|
||||||
uci.writeLineToEngine("isready");
|
uci.writeLineToEngine("isready");
|
||||||
engineState.state = MainState.WAIT_READY;
|
engineState.state = MainState.WAIT_READY;
|
||||||
@@ -666,7 +666,7 @@ public class DroidComputerPlayer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/** Handle reading of UCI options. Return true when finished. */
|
/** Handle reading of UCI options. Return true when finished. */
|
||||||
private final boolean readUCIOption(String s) {
|
private final boolean readUCIOption(UCIEngine uci, String s) {
|
||||||
String[] tokens = tokenize(s);
|
String[] tokens = tokenize(s);
|
||||||
if (tokens[0].equals("uciok"))
|
if (tokens[0].equals("uciok"))
|
||||||
return true;
|
return true;
|
||||||
@@ -681,15 +681,19 @@ public class DroidComputerPlayer {
|
|||||||
}
|
}
|
||||||
listener.notifyEngineName(engineName);
|
listener.notifyEngineName(engineName);
|
||||||
}
|
}
|
||||||
} else if ((tokens.length > 2) && tokens[2].toLowerCase().equals("multipv")) {
|
} else if (tokens.length > 2) {
|
||||||
try {
|
String optName = tokens[2].toLowerCase();
|
||||||
for (int i = 3; i < tokens.length; i++) {
|
uci.registerOption(optName);
|
||||||
if (tokens[i].equals("max") && (i+1 < tokens.length)) {
|
if (optName.equals("multipv")) {
|
||||||
maxPV = Math.max(maxPV, Integer.parseInt(tokens[i+1]));
|
try {
|
||||||
break;
|
for (int i = 3; i < tokens.length; i++) {
|
||||||
|
if (tokens[i].equals("max") && (i+1 < tokens.length)) {
|
||||||
|
maxPV = Math.max(maxPV, Integer.parseInt(tokens[i+1]));
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
} catch (NumberFormatException nfe) { }
|
||||||
} catch (NumberFormatException nfe) { }
|
}
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -882,7 +886,7 @@ public class DroidComputerPlayer {
|
|||||||
return;
|
return;
|
||||||
lastGUIUpdate = now;
|
lastGUIUpdate = now;
|
||||||
|
|
||||||
if (searchRequest == null)
|
if ((searchRequest == null) || (searchRequest.currPos == null))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
int id = engineState.searchId;
|
int id = engineState.searchId;
|
||||||
|
|||||||
@@ -59,4 +59,10 @@ public interface UCIEngine {
|
|||||||
|
|
||||||
/** Set an engine string option. */
|
/** Set an engine string option. */
|
||||||
public void setOption(String name, String value);
|
public void setOption(String name, String value);
|
||||||
|
|
||||||
|
/** Clear list of supported options. */
|
||||||
|
public void clearOptions();
|
||||||
|
|
||||||
|
/** Register an option as supported by the engine. */
|
||||||
|
public void registerOption(String optName);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,6 +19,7 @@
|
|||||||
package org.petero.droidfish.engine;
|
package org.petero.droidfish.engine;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
import java.util.HashSet;
|
||||||
|
|
||||||
import org.petero.droidfish.engine.cuckoochess.CuckooChessEngine;
|
import org.petero.droidfish.engine.cuckoochess.CuckooChessEngine;
|
||||||
|
|
||||||
@@ -27,6 +28,8 @@ import android.content.Context;
|
|||||||
public abstract class UCIEngineBase implements UCIEngine {
|
public abstract class UCIEngineBase implements UCIEngine {
|
||||||
|
|
||||||
private boolean processAlive;
|
private boolean processAlive;
|
||||||
|
private HashSet<String> allOptions;
|
||||||
|
private HashMap<String, String> currOptions;
|
||||||
|
|
||||||
public static UCIEngine getEngine(Context context, String engine, Report report) {
|
public static UCIEngine getEngine(Context context, String engine, Report report) {
|
||||||
if ("stockfish".equals(engine) && (EngineUtil.internalStockFishName() == null))
|
if ("stockfish".equals(engine) && (EngineUtil.internalStockFishName() == null))
|
||||||
@@ -41,6 +44,8 @@ public abstract class UCIEngineBase implements UCIEngine {
|
|||||||
|
|
||||||
protected UCIEngineBase() {
|
protected UCIEngineBase() {
|
||||||
processAlive = false;
|
processAlive = false;
|
||||||
|
allOptions = new HashSet<String>();
|
||||||
|
currOptions = new HashMap<String, String>();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected abstract void startProcess();
|
protected abstract void startProcess();
|
||||||
@@ -61,6 +66,16 @@ public abstract class UCIEngineBase implements UCIEngine {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void clearOptions() {
|
||||||
|
allOptions.clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void registerOption(String optName) {
|
||||||
|
allOptions.add(optName);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setOption(String name, int value) {
|
public void setOption(String name, int value) {
|
||||||
setOption(name, String.format("%d", value));
|
setOption(name, String.format("%d", value));
|
||||||
@@ -71,14 +86,15 @@ public abstract class UCIEngineBase implements UCIEngine {
|
|||||||
setOption(name, value ? "true" : "false");
|
setOption(name, value ? "true" : "false");
|
||||||
}
|
}
|
||||||
|
|
||||||
private HashMap<String, String> options = new HashMap<String, String>();
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setOption(String name, String value) {
|
public void setOption(String name, String value) {
|
||||||
String currVal = options.get(name.toLowerCase());
|
String lcName = name.toLowerCase();
|
||||||
|
if (!allOptions.contains(lcName))
|
||||||
|
return;
|
||||||
|
String currVal = currOptions.get(lcName);
|
||||||
if (value.equals(currVal))
|
if (value.equals(currVal))
|
||||||
return;
|
return;
|
||||||
writeLineToEngine(String.format("setoption name %s value %s", name, value));
|
writeLineToEngine(String.format("setoption name %s value %s", name, value));
|
||||||
options.put(name.toLowerCase(), value);
|
currOptions.put(lcName, value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user