mirror of
https://github.com/peterosterlund2/droidfish.git
synced 2025-12-13 09:32:39 +01:00
DroidFish: Removed GUI special handling of number of search threads. It
is now handled as a normal UCI option instead.
This commit is contained in:
@@ -21,17 +21,6 @@
|
|||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
|
|
||||||
/*
|
|
||||||
* Class: org_petero_droidfish_engine_EngineUtil
|
|
||||||
* Method: getNPhysicalProcessors
|
|
||||||
* Signature: ()I
|
|
||||||
*/
|
|
||||||
extern "C" JNIEXPORT jint JNICALL Java_org_petero_droidfish_engine_EngineUtil_getNPhysicalProcessors
|
|
||||||
(JNIEnv *, jclass)
|
|
||||||
{
|
|
||||||
return sysconf(_SC_NPROCESSORS_ONLN);
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Class: org_petero_droidfish_engine_EngineUtil
|
* Class: org_petero_droidfish_engine_EngineUtil
|
||||||
* Method: chmod
|
* Method: chmod
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<resources>
|
<resources>
|
||||||
<string name="app_name">DroidFish</string>
|
<string name="app_name">DroidFish</string>
|
||||||
<string name="engine_threads_default">1</string>
|
|
||||||
<string name="engine_hash_default">16</string>
|
<string name="engine_hash_default">16</string>
|
||||||
<string name="moves_per_session_default">60</string>
|
<string name="moves_per_session_default">60</string>
|
||||||
<string name="time_control_default">120000</string>
|
<string name="time_control_default">120000</string>
|
||||||
@@ -262,8 +261,6 @@ you are not actively using the program.\
|
|||||||
<string name="prefs_strength_summary">Only supported by internal engines. Analysis mode always uses full strength.</string>
|
<string name="prefs_strength_summary">Only supported by internal engines. Analysis mode always uses full strength.</string>
|
||||||
<string name="prefs_ponderMode_title">Pondering</string>
|
<string name="prefs_ponderMode_title">Pondering</string>
|
||||||
<string name="prefs_ponderMode_summary">Let engine think while waiting for opponent\'s move. Supported by most engines.</string>
|
<string name="prefs_ponderMode_summary">Let engine think while waiting for opponent\'s move. Supported by most engines.</string>
|
||||||
<string name="prefs_threads_title">Threads</string>
|
|
||||||
<string name="prefs_threads_summary">Number of engine threads (CPU cores) to use. Not supported by all engines.</string>
|
|
||||||
<string name="prefs_hash_title">Hash Table</string>
|
<string name="prefs_hash_title">Hash Table</string>
|
||||||
<string name="prefs_hash_summary">Hash table size in megabytes</string>
|
<string name="prefs_hash_summary">Hash table size in megabytes</string>
|
||||||
<string name="prefs_time_control">Time Control</string>
|
<string name="prefs_time_control">Time Control</string>
|
||||||
@@ -422,26 +419,6 @@ you are not actively using the program.\
|
|||||||
<string name="buttonDesc_mode">Mode button</string>
|
<string name="buttonDesc_mode">Mode button</string>
|
||||||
<string name="buttonDesc_back">Backward button</string>
|
<string name="buttonDesc_back">Backward button</string>
|
||||||
<string name="buttonDesc_forward">Forward button</string>
|
<string name="buttonDesc_forward">Forward button</string>
|
||||||
<string-array name="engine_threads_texts">
|
|
||||||
<item>Automatic</item>
|
|
||||||
<item>1</item>
|
|
||||||
<item>2</item>
|
|
||||||
<item>3</item>
|
|
||||||
<item>4</item>
|
|
||||||
<item>6</item>
|
|
||||||
<item>8</item>
|
|
||||||
<item>16</item>
|
|
||||||
</string-array>
|
|
||||||
<string-array name="engine_threads_values">
|
|
||||||
<item>0</item>
|
|
||||||
<item>1</item>
|
|
||||||
<item>2</item>
|
|
||||||
<item>3</item>
|
|
||||||
<item>4</item>
|
|
||||||
<item>6</item>
|
|
||||||
<item>8</item>
|
|
||||||
<item>16</item>
|
|
||||||
</string-array>
|
|
||||||
<string-array name="viewPieceType_texts">
|
<string-array name="viewPieceType_texts">
|
||||||
<item>English letters</item>
|
<item>English letters</item>
|
||||||
<item>Local language letters</item>
|
<item>Local language letters</item>
|
||||||
|
|||||||
@@ -42,14 +42,6 @@
|
|||||||
android:summary="@string/prefs_ponderMode_summary"
|
android:summary="@string/prefs_ponderMode_summary"
|
||||||
android:defaultValue="false">
|
android:defaultValue="false">
|
||||||
</CheckBoxPreference>
|
</CheckBoxPreference>
|
||||||
<ListPreference
|
|
||||||
android:key="threads"
|
|
||||||
android:title="@string/prefs_threads_title"
|
|
||||||
android:summary="@string/prefs_threads_summary"
|
|
||||||
android:entryValues="@array/engine_threads_values"
|
|
||||||
android:entries="@array/engine_threads_texts"
|
|
||||||
android:defaultValue="@string/engine_threads_default">
|
|
||||||
</ListPreference>
|
|
||||||
<ListPreference
|
<ListPreference
|
||||||
android:key="hashMB"
|
android:key="hashMB"
|
||||||
android:title="@string/prefs_hash_title"
|
android:title="@string/prefs_hash_title"
|
||||||
|
|||||||
@@ -177,7 +177,6 @@ public class DroidFish extends Activity implements GUIInterface {
|
|||||||
private int timeControl;
|
private int timeControl;
|
||||||
private int movesPerSession;
|
private int movesPerSession;
|
||||||
private int timeIncrement;
|
private int timeIncrement;
|
||||||
private int mEngineThreads;
|
|
||||||
private String playerName;
|
private String playerName;
|
||||||
private boolean boardFlipped;
|
private boolean boardFlipped;
|
||||||
private boolean autoSwapSides;
|
private boolean autoSwapSides;
|
||||||
@@ -980,8 +979,6 @@ public class DroidFish extends Activity implements GUIInterface {
|
|||||||
maxNumArrows = getIntSetting("thinkingArrows", 2);
|
maxNumArrows = getIntSetting("thinkingArrows", 2);
|
||||||
mShowBookHints = settings.getBoolean("bookHints", false);
|
mShowBookHints = settings.getBoolean("bookHints", false);
|
||||||
|
|
||||||
mEngineThreads = getIntSetting("threads", 1);
|
|
||||||
|
|
||||||
String engine = settings.getString("engine", "stockfish");
|
String engine = settings.getString("engine", "stockfish");
|
||||||
int strength = settings.getInt("strength", 1000);
|
int strength = settings.getInt("strength", 1000);
|
||||||
setEngineStrength(engine, strength);
|
setEngineStrength(engine, strength);
|
||||||
@@ -1663,11 +1660,6 @@ public class DroidFish extends Activity implements GUIInterface {
|
|||||||
return mPonderMode;
|
return mPonderMode;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public int engineThreads() {
|
|
||||||
return mEngineThreads;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Context getContext() {
|
public Context getContext() {
|
||||||
return this;
|
return this;
|
||||||
|
|||||||
@@ -95,9 +95,6 @@ public interface GUIInterface {
|
|||||||
/** Return true if pondering (permanent brain) is enabled. */
|
/** Return true if pondering (permanent brain) is enabled. */
|
||||||
public boolean ponderMode();
|
public boolean ponderMode();
|
||||||
|
|
||||||
/** Return the number of engine threads to use. */
|
|
||||||
int engineThreads();
|
|
||||||
|
|
||||||
/** Return application context. */
|
/** Return application context. */
|
||||||
public Context getContext();
|
public Context getContext();
|
||||||
|
|
||||||
|
|||||||
@@ -59,7 +59,6 @@ public class DroidComputerPlayer {
|
|||||||
|
|
||||||
/** >1 if multiPV mode is supported. */
|
/** >1 if multiPV mode is supported. */
|
||||||
private int maxPV = 1;
|
private int maxPV = 1;
|
||||||
private int numCPUs = 1;
|
|
||||||
private String engineName = "Computer";
|
private String engineName = "Computer";
|
||||||
|
|
||||||
/** Engine state. */
|
/** Engine state. */
|
||||||
@@ -118,7 +117,6 @@ public class DroidComputerPlayer {
|
|||||||
int movesToGo; // Number of moves to next time control
|
int movesToGo; // Number of moves to next time control
|
||||||
|
|
||||||
String engine; // Engine name (identifier)
|
String engine; // Engine name (identifier)
|
||||||
int engineThreads; // Number of engine threads to use
|
|
||||||
int strength; // Engine strength setting (0 - 1000)
|
int strength; // Engine strength setting (0 - 1000)
|
||||||
int numPV; // Number of PV lines to compute
|
int numPV; // Number of PV lines to compute
|
||||||
|
|
||||||
@@ -156,7 +154,6 @@ public class DroidComputerPlayer {
|
|||||||
* @param ponderEnabled True if pondering is enabled in the GUI. Can affect time management.
|
* @param ponderEnabled True if pondering is enabled in the GUI. Can affect time management.
|
||||||
* @param ponderMove Move to ponder, or null for non-ponder search.
|
* @param ponderMove Move to ponder, or null for non-ponder search.
|
||||||
* @param engine Chess engine to use for searching.
|
* @param engine Chess engine to use for searching.
|
||||||
* @param engineThreads Number of engine threads to use, if supported by engine.
|
|
||||||
* @param strength Engine strength setting.
|
* @param strength Engine strength setting.
|
||||||
*/
|
*/
|
||||||
public static SearchRequest searchRequest(int id, long now,
|
public static SearchRequest searchRequest(int id, long now,
|
||||||
@@ -164,8 +161,7 @@ public class DroidComputerPlayer {
|
|||||||
Position currPos, boolean drawOffer,
|
Position currPos, boolean drawOffer,
|
||||||
int wTime, int bTime, int wInc, int bInc, int movesToGo,
|
int wTime, int bTime, int wInc, int bInc, int movesToGo,
|
||||||
boolean ponderEnabled, Move ponderMove,
|
boolean ponderEnabled, Move ponderMove,
|
||||||
String engine, int engineThreads,
|
String engine, int strength) {
|
||||||
int strength) {
|
|
||||||
SearchRequest sr = new SearchRequest();
|
SearchRequest sr = new SearchRequest();
|
||||||
sr.searchId = id;
|
sr.searchId = id;
|
||||||
sr.startTime = now;
|
sr.startTime = now;
|
||||||
@@ -181,7 +177,6 @@ public class DroidComputerPlayer {
|
|||||||
sr.bInc = bInc;
|
sr.bInc = bInc;
|
||||||
sr.movesToGo = movesToGo;
|
sr.movesToGo = movesToGo;
|
||||||
sr.engine = engine;
|
sr.engine = engine;
|
||||||
sr.engineThreads = engineThreads;
|
|
||||||
sr.strength = strength;
|
sr.strength = strength;
|
||||||
sr.numPV = 1;
|
sr.numPV = 1;
|
||||||
sr.ponderEnabled = ponderEnabled;
|
sr.ponderEnabled = ponderEnabled;
|
||||||
@@ -199,7 +194,6 @@ public class DroidComputerPlayer {
|
|||||||
* @param currPos Position to analyze.
|
* @param currPos Position to analyze.
|
||||||
* @param drawOffer True if other side have offered draw.
|
* @param drawOffer True if other side have offered draw.
|
||||||
* @param engine Chess engine to use for searching
|
* @param engine Chess engine to use for searching
|
||||||
* @param engineThreads Number of threads to use, or 0 for default value.
|
|
||||||
* @param numPV Multi-PV mode.
|
* @param numPV Multi-PV mode.
|
||||||
*/
|
*/
|
||||||
public static SearchRequest analyzeRequest(int id, Position prevPos,
|
public static SearchRequest analyzeRequest(int id, Position prevPos,
|
||||||
@@ -207,7 +201,6 @@ public class DroidComputerPlayer {
|
|||||||
Position currPos,
|
Position currPos,
|
||||||
boolean drawOffer,
|
boolean drawOffer,
|
||||||
String engine,
|
String engine,
|
||||||
int engineThreads,
|
|
||||||
int numPV) {
|
int numPV) {
|
||||||
SearchRequest sr = new SearchRequest();
|
SearchRequest sr = new SearchRequest();
|
||||||
sr.searchId = id;
|
sr.searchId = id;
|
||||||
@@ -220,7 +213,6 @@ public class DroidComputerPlayer {
|
|||||||
sr.isAnalyze = true;
|
sr.isAnalyze = true;
|
||||||
sr.wTime = sr.bTime = sr.wInc = sr.bInc = sr.movesToGo = 0;
|
sr.wTime = sr.bTime = sr.wInc = sr.bInc = sr.movesToGo = 0;
|
||||||
sr.engine = engine;
|
sr.engine = engine;
|
||||||
sr.engineThreads = engineThreads;
|
|
||||||
sr.strength = 1000;
|
sr.strength = 1000;
|
||||||
sr.numPV = numPV;
|
sr.numPV = numPV;
|
||||||
sr.ponderEnabled = false;
|
sr.ponderEnabled = false;
|
||||||
@@ -574,7 +566,6 @@ public class DroidComputerPlayer {
|
|||||||
}
|
}
|
||||||
uciEngine.setOption("Ponder", sr.ponderEnabled);
|
uciEngine.setOption("Ponder", sr.ponderEnabled);
|
||||||
uciEngine.setOption("UCI_AnalyseMode", false);
|
uciEngine.setOption("UCI_AnalyseMode", false);
|
||||||
uciEngine.setNThreads(sr.engineThreads > 0 ? sr.engineThreads : numCPUs);
|
|
||||||
uciEngine.writeLineToEngine(posStr.toString());
|
uciEngine.writeLineToEngine(posStr.toString());
|
||||||
if (sr.wTime < 1) sr.wTime = 1;
|
if (sr.wTime < 1) sr.wTime = 1;
|
||||||
if (sr.bTime < 1) sr.bTime = 1;
|
if (sr.bTime < 1) sr.bTime = 1;
|
||||||
@@ -611,7 +602,6 @@ public class DroidComputerPlayer {
|
|||||||
}
|
}
|
||||||
uciEngine.writeLineToEngine(posStr.toString());
|
uciEngine.writeLineToEngine(posStr.toString());
|
||||||
uciEngine.setOption("UCI_AnalyseMode", true);
|
uciEngine.setOption("UCI_AnalyseMode", true);
|
||||||
uciEngine.setNThreads(sr.engineThreads > 0 ? sr.engineThreads : numCPUs);
|
|
||||||
StringBuilder goStr = new StringBuilder(96);
|
StringBuilder goStr = new StringBuilder(96);
|
||||||
goStr.append("go infinite");
|
goStr.append("go infinite");
|
||||||
if (sr.searchMoves != null) {
|
if (sr.searchMoves != null) {
|
||||||
@@ -655,9 +645,6 @@ public class DroidComputerPlayer {
|
|||||||
|
|
||||||
uciEngine.clearOptions();
|
uciEngine.clearOptions();
|
||||||
uciEngine.writeLineToEngine("uci");
|
uciEngine.writeLineToEngine("uci");
|
||||||
int nThreads = getNumCPUs();
|
|
||||||
if (nThreads > 8) nThreads = 8;
|
|
||||||
numCPUs = nThreads;
|
|
||||||
maxPV = 1;
|
maxPV = 1;
|
||||||
engineState.engine = searchRequest.engine;
|
engineState.engine = searchRequest.engine;
|
||||||
engineState.setState(MainState.READ_OPTIONS);
|
engineState.setState(MainState.READ_OPTIONS);
|
||||||
@@ -1022,46 +1009,6 @@ public class DroidComputerPlayer {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Try to find out how many CPU cores are present. */
|
|
||||||
private static final int getNumCPUs() {
|
|
||||||
int nCPUsFromProc = getNumCPUsFromProc();
|
|
||||||
int nCPUsFromSys = getNumCPUsFromSys();
|
|
||||||
int nCPUsFromOS = EngineUtil.getNPhysicalProcessors();
|
|
||||||
return Math.max(Math.max(nCPUsFromProc, nCPUsFromSys), nCPUsFromOS);
|
|
||||||
}
|
|
||||||
|
|
||||||
private static final int getNumCPUsFromProc() {
|
|
||||||
int nCPUsFromProc = 1;
|
|
||||||
try {
|
|
||||||
FileReader fr = new FileReader("/proc/stat");
|
|
||||||
BufferedReader inBuf = new BufferedReader(fr, 8192);
|
|
||||||
String line;
|
|
||||||
int nCPUs = 0;
|
|
||||||
while ((line = inBuf.readLine()) != null) {
|
|
||||||
if ((line.length() >= 4) && line.startsWith("cpu") && Character.isDigit(line.charAt(3)))
|
|
||||||
nCPUs++;
|
|
||||||
}
|
|
||||||
inBuf.close();
|
|
||||||
if (nCPUs > 1)
|
|
||||||
nCPUsFromProc = nCPUs;
|
|
||||||
} catch (IOException e) {
|
|
||||||
}
|
|
||||||
return nCPUsFromProc;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static final int getNumCPUsFromSys() {
|
|
||||||
File dir = new File("/sys/devices/system/cpu");
|
|
||||||
File[] files = dir.listFiles(new FileFilter() {
|
|
||||||
@Override
|
|
||||||
public boolean accept(File pathname) {
|
|
||||||
return Pattern.matches("cpu[0-9]+", pathname.getName());
|
|
||||||
}
|
|
||||||
});
|
|
||||||
if (files == null)
|
|
||||||
return 1;
|
|
||||||
return Math.max(files.length, 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
private final static void myAssert(boolean b) {
|
private final static void myAssert(boolean b) {
|
||||||
if (!b)
|
if (!b)
|
||||||
throw new RuntimeException();
|
throw new RuntimeException();
|
||||||
|
|||||||
@@ -33,9 +33,6 @@ public class EngineUtil {
|
|||||||
System.loadLibrary("nativeutil");
|
System.loadLibrary("nativeutil");
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Return number of physical processors, i.e. hyper-threading ignored. */
|
|
||||||
final static native int getNPhysicalProcessors();
|
|
||||||
|
|
||||||
/** Return file name of the internal stockfish executable. */
|
/** Return file name of the internal stockfish executable. */
|
||||||
public static String internalStockFishName() {
|
public static String internalStockFishName() {
|
||||||
String abi = Build.CPU_ABI;
|
String abi = Build.CPU_ABI;
|
||||||
|
|||||||
@@ -85,7 +85,4 @@ public interface UCIEngine {
|
|||||||
/** Register an option as supported by the engine.
|
/** Register an option as supported by the engine.
|
||||||
* @param tokens The UCI option line sent by the engine, split in words. */
|
* @param tokens The UCI option line sent by the engine, split in words. */
|
||||||
public UCIOptions.OptionBase registerOption(String[] tokens);
|
public UCIOptions.OptionBase registerOption(String[] tokens);
|
||||||
|
|
||||||
/** Set number of search threads to use. */
|
|
||||||
public void setNThreads(int nThreads);
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -140,7 +140,7 @@ public abstract class UCIEngineBase implements UCIEngine {
|
|||||||
name = name.toLowerCase(Locale.US);
|
name = name.toLowerCase(Locale.US);
|
||||||
if (name.startsWith("uci_") || name.equals("hash") || name.equals("ponder") ||
|
if (name.startsWith("uci_") || name.equals("hash") || name.equals("ponder") ||
|
||||||
name.equals("multipv") || name.equals("gaviotatbpath") ||
|
name.equals("multipv") || name.equals("gaviotatbpath") ||
|
||||||
name.equals("syzygypath") || name.equals("threads") || name.equals("cores"))
|
name.equals("syzygypath"))
|
||||||
return false;
|
return false;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -285,12 +285,4 @@ public abstract class UCIEngineBase implements UCIEngine {
|
|||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public final void setNThreads(int nThreads) {
|
|
||||||
if (options.contains("Threads"))
|
|
||||||
setOption("Threads", nThreads);
|
|
||||||
else if (options.contains("Cores"))
|
|
||||||
setOption("Cores", nThreads);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -938,8 +938,7 @@ public class DroidChessController {
|
|||||||
SearchRequest sr = DroidComputerPlayer.SearchRequest.analyzeRequest(
|
SearchRequest sr = DroidComputerPlayer.SearchRequest.analyzeRequest(
|
||||||
searchId, ph.first, ph.second,
|
searchId, ph.first, ph.second,
|
||||||
new Position(game.currPos()),
|
new Position(game.currPos()),
|
||||||
game.haveDrawOffer(), engine,
|
game.haveDrawOffer(), engine, numPV);
|
||||||
gui.engineThreads(), numPV);
|
|
||||||
computerPlayer.queueAnalyzeRequest(sr);
|
computerPlayer.queueAnalyzeRequest(sr);
|
||||||
} else if (computersTurn || ponder) {
|
} else if (computersTurn || ponder) {
|
||||||
listener.clearSearchInfo(searchId);
|
listener.clearSearchInfo(searchId);
|
||||||
@@ -963,8 +962,7 @@ public class DroidChessController {
|
|||||||
game.haveDrawOffer(),
|
game.haveDrawOffer(),
|
||||||
wTime, bTime, wInc, bInc, movesToGo,
|
wTime, bTime, wInc, bInc, movesToGo,
|
||||||
gui.ponderMode(), fPonderMove,
|
gui.ponderMode(), fPonderMove,
|
||||||
engine, gui.engineThreads(),
|
engine, strength);
|
||||||
strength);
|
|
||||||
computerPlayer.queueSearchRequest(sr);
|
computerPlayer.queueSearchRequest(sr);
|
||||||
} else {
|
} else {
|
||||||
computerPlayer.queueStartEngine(searchId, engine);
|
computerPlayer.queueStartEngine(searchId, engine);
|
||||||
|
|||||||
Reference in New Issue
Block a user