From 929f77ced2af9f02b307ebd692bc1cacc0b986bf Mon Sep 17 00:00:00 2001 From: Peter Osterlund Date: Tue, 29 Dec 2015 10:24:54 +0100 Subject: [PATCH] DroidFish: Added "secret" way to allocate an unsafely large hash table. --- DroidFish/src/org/petero/droidfish/DroidFish.java | 13 +++++-------- .../src/org/petero/droidfish/EngineOptions.java | 4 ++++ .../org/petero/droidfish/engine/ExternalEngine.java | 9 +++++---- 3 files changed, 14 insertions(+), 12 deletions(-) diff --git a/DroidFish/src/org/petero/droidfish/DroidFish.java b/DroidFish/src/org/petero/droidfish/DroidFish.java index af1ed57..e5a7de5 100644 --- a/DroidFish/src/org/petero/droidfish/DroidFish.java +++ b/DroidFish/src/org/petero/droidfish/DroidFish.java @@ -1048,27 +1048,24 @@ public class DroidFish extends Activity implements GUIInterface { bookOptions.random = (settings.getInt("bookRandom", 500) - 500) * (3.0 / 500); setBookOptions(); + File extDir = Environment.getExternalStorageDirectory(); + String sep = File.separator; engineOptions.hashMB = getIntSetting("hashMB", 16); + engineOptions.unSafeHash = new File(extDir + sep + engineDir + sep + ".unsafehash").exists(); engineOptions.hints = settings.getBoolean("tbHints", false); 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(); - String sep = File.separator; + if (gtbPath.length() == 0) gtbPath = extDir.getAbsolutePath() + sep + gtbDefaultDir; - } engineOptions.gtbPath = gtbPath; String gtbPathNet = settings.getString("gtbPathNet", "").trim(); engineOptions.gtbPathNet = gtbPathNet; String rtbPath = settings.getString("rtbPath", "").trim(); - if (rtbPath.length() == 0) { - File extDir = Environment.getExternalStorageDirectory(); - String sep = File.separator; + if (rtbPath.length() == 0) rtbPath = extDir.getAbsolutePath() + sep + rtbDefaultDir; - } engineOptions.rtbPath = rtbPath; String rtbPathNet = settings.getString("rtbPathNet", "").trim(); engineOptions.rtbPathNet = rtbPathNet; diff --git a/DroidFish/src/org/petero/droidfish/EngineOptions.java b/DroidFish/src/org/petero/droidfish/EngineOptions.java index aa8eeb1..d4ab754 100644 --- a/DroidFish/src/org/petero/droidfish/EngineOptions.java +++ b/DroidFish/src/org/petero/droidfish/EngineOptions.java @@ -21,6 +21,7 @@ package org.petero.droidfish; /** Engine options, including endgame tablebase probing options. */ public final class EngineOptions { public int hashMB; // Engine hash table size in MB + public boolean unSafeHash; // True if allocating very large hash is allowed public boolean hints; // Hints when playing/analyzing public boolean hintsEdit; // Hints in "edit board" mode public boolean rootProbe; // Only search optimal moves at root @@ -33,6 +34,7 @@ public final class EngineOptions { public EngineOptions() { hashMB = 16; + unSafeHash = false; hints = false; hintsEdit = false; rootProbe = false; @@ -46,6 +48,7 @@ public final class EngineOptions { public EngineOptions(EngineOptions other) { hashMB = other.hashMB; + unSafeHash = other.unSafeHash; hints = other.hints; hintsEdit = other.hintsEdit; rootProbe = other.rootProbe; @@ -78,6 +81,7 @@ public final class EngineOptions { EngineOptions other = (EngineOptions)o; return ((hashMB == other.hashMB) && + (unSafeHash == other.unSafeHash) && (hints == other.hints) && (hintsEdit == other.hintsEdit) && (rootProbe == other.rootProbe) && diff --git a/DroidFish/src/org/petero/droidfish/engine/ExternalEngine.java b/DroidFish/src/org/petero/droidfish/engine/ExternalEngine.java index 839f651..eb8403b 100644 --- a/DroidFish/src/org/petero/droidfish/engine/ExternalEngine.java +++ b/DroidFish/src/org/petero/droidfish/engine/ExternalEngine.java @@ -205,7 +205,7 @@ public class ExternalEngine extends UCIEngineBase { @Override public void initOptions(EngineOptions engineOptions) { super.initOptions(engineOptions); - hashMB = getHashMB(engineOptions.hashMB); + hashMB = getHashMB(engineOptions); setOption("Hash", hashMB); syzygyPath = engineOptions.getEngineRtbPath(false); setOption("SyzygyPath", syzygyPath); @@ -220,8 +220,9 @@ public class ExternalEngine extends UCIEngineBase { } /** Reduce too large hash sizes. */ - private final int getHashMB(int hashMB) { - if (hashMB > 16) { + private final static int getHashMB(EngineOptions engineOptions) { + int hashMB = engineOptions.hashMB; + if (hashMB > 16 && !engineOptions.unSafeHash) { int maxMem = (int)(Runtime.getRuntime().maxMemory() / (1024*1024)); if (maxMem < 16) maxMem = 16; @@ -236,7 +237,7 @@ public class ExternalEngine extends UCIEngineBase { public boolean optionsOk(EngineOptions engineOptions) { if (!optionsInitialized) return true; - if (hashMB != getHashMB(engineOptions.hashMB)) + if (hashMB != getHashMB(engineOptions)) return false; if (hasOption("gaviotatbpath") && !gaviotaTbPath.equals(engineOptions.getEngineGtbPath(false))) return false;