From 4fbb4b721c9dc6783ce43d2a25aa6913dd8430c3 Mon Sep 17 00:00:00 2001 From: Peter Osterlund Date: Sun, 1 Jun 2014 09:28:16 +0000 Subject: [PATCH] DroidFish: Show tablebase hits. Add support for SyzygyPath uci option. --- DroidFish/res/values/strings.xml | 2 ++ DroidFish/res/xml/preferences.xml | 8 +++++++- .../src/org/petero/droidfish/DroidFish.java | 11 +++++++++++ .../src/org/petero/droidfish/EngineOptions.java | 4 ++++ .../droidfish/engine/DroidComputerPlayer.java | 17 +++++++++++++---- .../petero/droidfish/engine/ExternalEngine.java | 5 +++++ .../petero/droidfish/engine/NetworkEngine.java | 5 +++++ .../gamelogic/DroidChessController.java | 17 ++++++++++++++++- .../droidfish/gamelogic/SearchListener.java | 6 ++++-- 9 files changed, 67 insertions(+), 8 deletions(-) diff --git a/DroidFish/res/values/strings.xml b/DroidFish/res/values/strings.xml index cfbe81b..de49a8a 100644 --- a/DroidFish/res/values/strings.xml +++ b/DroidFish/res/values/strings.xml @@ -405,6 +405,8 @@ you are not actively using the program.\ Enable tablebase probing in engine, when supported. Takes effect next time engine is started GTB Directory Directory where Gaviota tablebases are installed. Leave blank to use default directory + Syzygy Directory + Directory where Syzygy tablebases are installed. Leave blank to use default directory @string/prefs_custom_button_1 @string/prefs_custom_button_2 @string/prefs_custom_button_3 diff --git a/DroidFish/res/xml/preferences.xml b/DroidFish/res/xml/preferences.xml index 1e4306a..9c01d78 100644 --- a/DroidFish/res/xml/preferences.xml +++ b/DroidFish/res/xml/preferences.xml @@ -687,6 +687,12 @@ android:summary="@string/prefs_gtbPath_summary" android:defaultValue=""> - + + + diff --git a/DroidFish/src/org/petero/droidfish/DroidFish.java b/DroidFish/src/org/petero/droidfish/DroidFish.java index b7e3283..4133b02 100644 --- a/DroidFish/src/org/petero/droidfish/DroidFish.java +++ b/DroidFish/src/org/petero/droidfish/DroidFish.java @@ -208,6 +208,7 @@ public class DroidFish extends Activity implements GUIInterface { private final static String fenDir = "DroidFish/epd"; private final static String engineDir = "DroidFish/uci"; private final static String gtbDefaultDir = "DroidFish/gtb"; + private final static String rtbDefaultDir = "DroidFish/rtb"; private BookOptions bookOptions = new BookOptions(); private PGNOptions pgnOptions = new PGNOptions(); private EngineOptions engineOptions = new EngineOptions(); @@ -476,6 +477,7 @@ public class DroidFish extends Activity implements GUIInterface { new File(extDir + sep + fenDir).mkdirs(); new File(extDir + sep + engineDir).mkdirs(); new File(extDir + sep + gtbDefaultDir).mkdirs(); + new File(extDir + sep + rtbDefaultDir).mkdirs(); } /** @@ -960,6 +962,7 @@ public class DroidFish extends Activity implements GUIInterface { engineOptions.hintsEdit = settings.getBoolean("tbHintsEdit", false); engineOptions.rootProbe = settings.getBoolean("tbRootProbe", true); engineOptions.engineProbe = settings.getBoolean("tbEngineProbe", true); + String gtbPath = settings.getString("gtbPath", "").trim(); if (gtbPath.length() == 0) { File extDir = Environment.getExternalStorageDirectory(); @@ -967,6 +970,14 @@ public class DroidFish extends Activity implements GUIInterface { gtbPath = extDir.getAbsolutePath() + sep + gtbDefaultDir; } engineOptions.gtbPath = gtbPath; + String rtbPath = settings.getString("rtbPath", "").trim(); + if (rtbPath.length() == 0) { + File extDir = Environment.getExternalStorageDirectory(); + String sep = File.separator; + rtbPath = extDir.getAbsolutePath() + sep + rtbDefaultDir; + } + engineOptions.rtbPath = rtbPath; + setEngineOptions(false); setEgtbHints(cb.getSelectedSquare()); diff --git a/DroidFish/src/org/petero/droidfish/EngineOptions.java b/DroidFish/src/org/petero/droidfish/EngineOptions.java index 6be9b44..f430acf 100644 --- a/DroidFish/src/org/petero/droidfish/EngineOptions.java +++ b/DroidFish/src/org/petero/droidfish/EngineOptions.java @@ -26,6 +26,7 @@ public final class EngineOptions { public boolean rootProbe; // Only search optimal moves at root public boolean engineProbe; // Let engine use EGTB public String gtbPath; // GTB directory path + public String rtbPath; // Syzygy directory path public String networkID; // host+port network settings public EngineOptions() { @@ -35,6 +36,7 @@ public final class EngineOptions { rootProbe = false; engineProbe = false; gtbPath = ""; + rtbPath = ""; networkID = ""; } @@ -45,6 +47,7 @@ public final class EngineOptions { rootProbe = other.rootProbe; engineProbe = other.engineProbe; gtbPath = other.gtbPath; + rtbPath = other.rtbPath; networkID = other.networkID; } @@ -60,6 +63,7 @@ public final class EngineOptions { (rootProbe == other.rootProbe) && (engineProbe == other.engineProbe) && gtbPath.equals(other.gtbPath) && + rtbPath.equals(other.rtbPath) && networkID.equals(other.networkID)); } diff --git a/DroidFish/src/org/petero/droidfish/engine/DroidComputerPlayer.java b/DroidFish/src/org/petero/droidfish/engine/DroidComputerPlayer.java index a6bcbd9..7ce74a3 100644 --- a/DroidFish/src/org/petero/droidfish/engine/DroidComputerPlayer.java +++ b/DroidFish/src/org/petero/droidfish/engine/DroidComputerPlayer.java @@ -859,6 +859,7 @@ public class DroidComputerPlayer { private boolean statLowerBound = false; private int statTime = 0; private long statNodes = 0; + private long statTBHits = 0; private int statNps = 0; private int pvNum = 0; private ArrayList statPV = new ArrayList(); @@ -873,6 +874,11 @@ public class DroidComputerPlayer { private boolean statsModified = false; private final void clearInfo() { + statCurrDepth = statPVDepth = statScore = 0; + statIsMate = statUpperBound = statLowerBound = false; + statTime = 0; + statNodes = statTBHits = 0; + statNps = 0; depthModified = false; currMoveModified = false; pvModified = false; @@ -913,6 +919,9 @@ public class DroidComputerPlayer { } else if (is.equals("nodes")) { statNodes = Long.parseLong(tokens[i++]); statsModified = true; + } else if (is.equals("tbhits")) { + statTBHits = Long.parseLong(tokens[i++]); + statsModified = true; } else if (is.equals("nps")) { statNps = Integer.parseInt(tokens[i++]); statsModified = true; @@ -945,15 +954,15 @@ public class DroidComputerPlayer { } if (havePvData) { while (statPvInfo.size() < pvNum) - statPvInfo.add(new PvInfo(0, 0, 0, 0, 0, false, false, false, new ArrayList())); + statPvInfo.add(new PvInfo(0, 0, 0, 0, 0, 0, false, false, false, new ArrayList())); while (statPvInfo.size() <= pvNum) statPvInfo.add(null); ArrayList moves = new ArrayList(); int nMoves = statPV.size(); for (i = 0; i < nMoves; i++) moves.add(TextIO.UCIstringToMove(statPV.get(i))); - statPvInfo.set(pvNum, new PvInfo(statPVDepth, statScore, statTime, statNodes, statNps, statIsMate, - statUpperBound, statLowerBound, moves)); + statPvInfo.set(pvNum, new PvInfo(statPVDepth, statScore, statTime, statNodes, statNps, statTBHits, + statIsMate, statUpperBound, statLowerBound, moves)); } } catch (NumberFormatException nfe) { // Ignore @@ -997,7 +1006,7 @@ public class DroidComputerPlayer { pvModified = false; } if (statsModified) { - listener.notifyStats(id, statNodes, statNps, statTime); + listener.notifyStats(id, statNodes, statNps, statTBHits, statTime); statsModified = false; } } diff --git a/DroidFish/src/org/petero/droidfish/engine/ExternalEngine.java b/DroidFish/src/org/petero/droidfish/engine/ExternalEngine.java index b784c30..7df55ee 100644 --- a/DroidFish/src/org/petero/droidfish/engine/ExternalEngine.java +++ b/DroidFish/src/org/petero/droidfish/engine/ExternalEngine.java @@ -165,6 +165,7 @@ public class ExternalEngine extends UCIEngineBase { private int hashMB = -1; private String gaviotaTbPath = ""; + private String syzygyPath = ""; private boolean optionsInitialized = false; /** @inheritDoc */ @@ -177,6 +178,8 @@ public class ExternalEngine extends UCIEngineBase { gaviotaTbPath = engineOptions.gtbPath; setOption("GaviotaTbPath", engineOptions.gtbPath); setOption("GaviotaTbCache", 8); + syzygyPath = engineOptions.rtbPath; + setOption("SyzygyPath", engineOptions.rtbPath); } optionsInitialized = true; } @@ -202,6 +205,8 @@ public class ExternalEngine extends UCIEngineBase { return false; if (hasOption("gaviotatbpath") && !gaviotaTbPath.equals(engineOptions.gtbPath)) return false; + if (hasOption("syzygypath") && !syzygyPath.equals(engineOptions.rtbPath)) + return false; return true; } diff --git a/DroidFish/src/org/petero/droidfish/engine/NetworkEngine.java b/DroidFish/src/org/petero/droidfish/engine/NetworkEngine.java index e66a189..e59e8b9 100644 --- a/DroidFish/src/org/petero/droidfish/engine/NetworkEngine.java +++ b/DroidFish/src/org/petero/droidfish/engine/NetworkEngine.java @@ -196,6 +196,7 @@ public class NetworkEngine extends UCIEngineBase { private int hashMB = -1; private String gaviotaTbPath = ""; + private String syzygyPath = ""; private boolean optionsInitialized = false; /** @inheritDoc */ @@ -208,6 +209,8 @@ public class NetworkEngine extends UCIEngineBase { gaviotaTbPath = engineOptions.gtbPath; setOption("GaviotaTbPath", engineOptions.gtbPath); setOption("GaviotaTbCache", 8); + syzygyPath = engineOptions.rtbPath; + setOption("SyzygyPath", engineOptions.rtbPath); } optionsInitialized = true; } @@ -225,6 +228,8 @@ public class NetworkEngine extends UCIEngineBase { return false; if (hasOption("gaviotatbpath") && !gaviotaTbPath.equals(engineOptions.gtbPath)) return false; + if (hasOption("syzygypath") && !syzygyPath.equals(engineOptions.rtbPath)) + return false; return true; } diff --git a/DroidFish/src/org/petero/droidfish/gamelogic/DroidChessController.java b/DroidFish/src/org/petero/droidfish/gamelogic/DroidChessController.java index aa2cfd4..75ed6f1 100644 --- a/DroidFish/src/org/petero/droidfish/gamelogic/DroidChessController.java +++ b/DroidFish/src/org/petero/droidfish/gamelogic/DroidChessController.java @@ -633,6 +633,7 @@ public class DroidChessController { private String currMoveStr = ""; private long currNodes = 0; private int currNps = 0; + private long currTBHits = 0; private int currTime = 0; private boolean whiteMove = true; @@ -695,6 +696,18 @@ public class DroidChessController { } statStrTmp = String.format(Locale.US, "d:%d %d:%s t:%.2f n:%d%s nps:%d%s", currDepth, currMoveNr, currMoveStr, currTime / 1000.0, nodes, nodesPrefix, nps, npsPrefix); + if (currTBHits > 0) { + long tbHits = currTBHits; + String tbHitsPrefix = ""; + if (tbHits > 100000000) { + tbHits /= 1000000; + tbHitsPrefix = "M"; + } else if (tbHits > 100000) { + tbHits /= 1000; + tbHitsPrefix = "k"; + } + statStrTmp += String.format(Locale.US, " tb:%d%s", tbHits, tbHitsPrefix); + } } final String statStr = statStrTmp; final String newPV = buf.toString(); @@ -742,6 +755,7 @@ public class DroidChessController { currTime = pv.time; currNodes = pv.nodes; currNps = pv.nps; + currTBHits = pv.tbHits; StringBuilder buf = new StringBuilder(); Position tmpPos = new Position(pos); @@ -768,9 +782,10 @@ public class DroidChessController { } @Override - public void notifyStats(int id, long nodes, int nps, int time) { + public void notifyStats(int id, long nodes, int nps, long tbHits, int time) { currNodes = nodes; currNps = nps; + currTBHits = tbHits; currTime = time; setSearchInfo(id); } diff --git a/DroidFish/src/org/petero/droidfish/gamelogic/SearchListener.java b/DroidFish/src/org/petero/droidfish/gamelogic/SearchListener.java index ed98ba4..d413e35 100644 --- a/DroidFish/src/org/petero/droidfish/gamelogic/SearchListener.java +++ b/DroidFish/src/org/petero/droidfish/gamelogic/SearchListener.java @@ -31,19 +31,21 @@ public interface SearchListener { int time; long nodes; int nps; + long tbHits; boolean isMate; boolean upperBound; boolean lowerBound; ArrayList pv; String pvStr = ""; - public PvInfo(int depth, int score, int time, long nodes, int nps, + public PvInfo(int depth, int score, int time, long nodes, int nps, long tbHits, boolean isMate, boolean upperBound, boolean lowerBound, ArrayList pv) { this.depth = depth; this.score = score; this.time = time; this.nodes = nodes; this.nps = nps; + this.tbHits = tbHits; this.isMate = isMate; this.upperBound = upperBound; this.lowerBound = lowerBound; @@ -64,7 +66,7 @@ public interface SearchListener { public void notifyPV(int id, Position pos, ArrayList pvInfo, Move ponderMove); /** Report search statistics. */ - public void notifyStats(int id, long nodes, int nps, int time); + public void notifyStats(int id, long nodes, int nps, long tbHits, int time); /** Report opening book information. */ public void notifyBookInfo(int id, String bookInfo, ArrayList moveList);