mirror of
https://github.com/peterosterlund2/droidfish.git
synced 2025-02-23 12:37:54 +01:00
DroidFish: Don't send UCI options that an engine doesn't understand.
This commit is contained in:
parent
ac10ab3017
commit
6b04258f95
DroidFish/src/org/petero/droidfish/engine
|
@ -570,6 +570,7 @@ public class DroidComputerPlayer {
|
|||
});
|
||||
engineMonitor.start();
|
||||
|
||||
uciEngine.clearOptions();
|
||||
uciEngine.writeLineToEngine("uci");
|
||||
int nThreads = getNumCPUs();
|
||||
if (nThreads > 8) nThreads = 8;
|
||||
|
@ -615,9 +616,8 @@ public class DroidComputerPlayer {
|
|||
|
||||
switch (engineState.state) {
|
||||
case READ_OPTIONS: {
|
||||
if (readUCIOption(s)) {
|
||||
if (readUCIOption(uci, s)) {
|
||||
uci.initOptions();
|
||||
uci.setOption("Ponder", false);
|
||||
uci.writeLineToEngine("ucinewgame");
|
||||
uci.writeLineToEngine("isready");
|
||||
engineState.state = MainState.WAIT_READY;
|
||||
|
@ -666,7 +666,7 @@ public class DroidComputerPlayer {
|
|||
}
|
||||
|
||||
/** 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);
|
||||
if (tokens[0].equals("uciok"))
|
||||
return true;
|
||||
|
@ -681,15 +681,19 @@ public class DroidComputerPlayer {
|
|||
}
|
||||
listener.notifyEngineName(engineName);
|
||||
}
|
||||
} else if ((tokens.length > 2) && tokens[2].toLowerCase().equals("multipv")) {
|
||||
try {
|
||||
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;
|
||||
} else if (tokens.length > 2) {
|
||||
String optName = tokens[2].toLowerCase();
|
||||
uci.registerOption(optName);
|
||||
if (optName.equals("multipv")) {
|
||||
try {
|
||||
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;
|
||||
}
|
||||
|
@ -882,7 +886,7 @@ public class DroidComputerPlayer {
|
|||
return;
|
||||
lastGUIUpdate = now;
|
||||
|
||||
if (searchRequest == null)
|
||||
if ((searchRequest == null) || (searchRequest.currPos == null))
|
||||
return;
|
||||
|
||||
int id = engineState.searchId;
|
||||
|
|
|
@ -59,4 +59,10 @@ public interface UCIEngine {
|
|||
|
||||
/** Set an engine string option. */
|
||||
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;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
|
||||
import org.petero.droidfish.engine.cuckoochess.CuckooChessEngine;
|
||||
|
||||
|
@ -27,6 +28,8 @@ import android.content.Context;
|
|||
public abstract class UCIEngineBase implements UCIEngine {
|
||||
|
||||
private boolean processAlive;
|
||||
private HashSet<String> allOptions;
|
||||
private HashMap<String, String> currOptions;
|
||||
|
||||
public static UCIEngine getEngine(Context context, String engine, Report report) {
|
||||
if ("stockfish".equals(engine) && (EngineUtil.internalStockFishName() == null))
|
||||
|
@ -41,6 +44,8 @@ public abstract class UCIEngineBase implements UCIEngine {
|
|||
|
||||
protected UCIEngineBase() {
|
||||
processAlive = false;
|
||||
allOptions = new HashSet<String>();
|
||||
currOptions = new HashMap<String, String>();
|
||||
}
|
||||
|
||||
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
|
||||
public void setOption(String name, int value) {
|
||||
setOption(name, String.format("%d", value));
|
||||
|
@ -71,14 +86,15 @@ public abstract class UCIEngineBase implements UCIEngine {
|
|||
setOption(name, value ? "true" : "false");
|
||||
}
|
||||
|
||||
private HashMap<String, String> options = new HashMap<String, String>();
|
||||
|
||||
@Override
|
||||
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))
|
||||
return;
|
||||
writeLineToEngine(String.format("setoption name %s value %s", name, value));
|
||||
options.put(name.toLowerCase(), value);
|
||||
currOptions.put(lcName, value);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user