DroidFish: Reinitialize tablebases when activity is started.

This commit is contained in:
Peter Osterlund 2012-01-21 08:51:01 +00:00
parent 1370b50ec7
commit 50ef527376
8 changed files with 17 additions and 21 deletions

View File

@ -105,7 +105,7 @@ public class ChessBoard extends View {
labelPaint = new Paint(); labelPaint = new Paint();
labelPaint.setAntiAlias(true); labelPaint.setAntiAlias(true);
decorationPaint = new Paint(); decorationPaint = new Paint();
decorationPaint.setAntiAlias(true); decorationPaint.setAntiAlias(true);

View File

@ -208,6 +208,7 @@ public class DroidFish extends Activity implements GUIInterface {
if (ctrl != null) if (ctrl != null)
ctrl.shutdownEngine(); ctrl.shutdownEngine();
ctrl = new DroidChessController(this, gameTextListener, pgnOptions); ctrl = new DroidChessController(this, gameTextListener, pgnOptions);
egtbForceReload = true;
readPrefs(); readPrefs();
ctrl.newGame(gameMode); ctrl.newGame(gameMode);
{ {
@ -700,8 +701,12 @@ public class DroidFish extends Activity implements GUIInterface {
ctrl.setBookOptions(options); ctrl.setBookOptions(options);
} }
private boolean egtbForceReload = false;
private final void setEgtbOptions() { private final void setEgtbOptions() {
ctrl.setEgtbOptions(new EGTBOptions(egtbOptions)); ctrl.setEgtbOptions(new EGTBOptions(egtbOptions));
Probe.getInstance().setPath(egtbOptions.gtbPath, egtbForceReload);
egtbForceReload = false;
} }
private final void setEgtbHints(int sq) { private final void setEgtbHints(int sq) {

View File

@ -35,7 +35,6 @@ import org.petero.droidfish.gamelogic.TextIO;
import org.petero.droidfish.gamelogic.UndoInfo; import org.petero.droidfish.gamelogic.UndoInfo;
import org.petero.droidfish.gamelogic.SearchListener.PvInfo; import org.petero.droidfish.gamelogic.SearchListener.PvInfo;
import org.petero.droidfish.gtb.Probe; import org.petero.droidfish.gtb.Probe;
import org.petero.droidfish.gtb.Probe.ProbeResult;
import android.content.Context; import android.content.Context;
@ -49,7 +48,6 @@ public class DroidComputerPlayer {
private final SearchListener listener; private final SearchListener listener;
private final DroidBook book; private final DroidBook book;
private EGTBOptions egtbOptions; private EGTBOptions egtbOptions;
private final Probe gtbProbe;
/** Set when "ucinewgame" needs to be sent. */ /** Set when "ucinewgame" needs to be sent. */
private boolean newGame = false; private boolean newGame = false;
@ -245,7 +243,6 @@ public class DroidComputerPlayer {
this.listener = listener; this.listener = listener;
book = DroidBook.getInstance(); book = DroidBook.getInstance();
egtbOptions = new EGTBOptions(); egtbOptions = new EGTBOptions();
gtbProbe = Probe.getInstance();
engineState = new EngineState(); engineState = new EngineState();
searchRequest = null; searchRequest = null;
} }
@ -272,10 +269,9 @@ public class DroidComputerPlayer {
public final void setBookOptions(BookOptions options) { public final void setBookOptions(BookOptions options) {
book.setOptions(options); book.setOptions(options);
} }
public final void setEgtbOptions(EGTBOptions options) { public final void setEgtbOptions(EGTBOptions options) {
egtbOptions = options; egtbOptions = options;
gtbProbe.setPath(options.gtbPath);
} }
/** Return all book moves, both as a formatted string and as a list of moves. */ /** Return all book moves, both as a formatted string and as a list of moves. */
@ -283,10 +279,6 @@ public class DroidComputerPlayer {
return book.getAllBookMoves(pos); return book.getAllBookMoves(pos);
} }
public final ProbeResult egtbProbe(Position pos) {
return gtbProbe.probeHard(pos);
}
/** Get engine reported name. */ /** Get engine reported name. */
public final synchronized String getEngineName() { public final synchronized String getEngineName() {
return engineName; return engineName;
@ -339,9 +331,8 @@ public class DroidComputerPlayer {
/** Decide what moves to search. Filters out non-optimal moves if tablebases are used. */ /** Decide what moves to search. Filters out non-optimal moves if tablebases are used. */
private final ArrayList<Move> movesToSearch(SearchRequest sr) { private final ArrayList<Move> movesToSearch(SearchRequest sr) {
ArrayList<Move> moves = null; ArrayList<Move> moves = null;
if (egtbOptions.rootProbe) { if (egtbOptions.rootProbe)
moves = gtbProbe.findOptimal(sr.currPos); moves = Probe.getInstance().findOptimal(sr.currPos);
}
if (moves != null) { if (moves != null) {
sr.searchMoves = moves; sr.searchMoves = moves;
} else { } else {

View File

@ -101,7 +101,7 @@ public class ExternalEngine extends UCIEngineBase {
} }
}); });
exitThread.start(); exitThread.start();
// Start a thread to read stdin // Start a thread to read stdin
stdInThread = new Thread(new Runnable() { stdInThread = new Thread(new Runnable() {
@Override @Override

View File

@ -78,7 +78,7 @@ public abstract class UCIEngineBase implements UCIEngine {
public void clearOptions() { public void clearOptions() {
allOptions.clear(); allOptions.clear();
} }
@Override @Override
public void registerOption(String optName) { public void registerOption(String optName) {
allOptions.add(optName); allOptions.add(optName);

View File

@ -719,7 +719,7 @@ public class DroidChessController {
} }
}); });
} }
@Override @Override
public void reportEngineError(final String errMsg) { public void reportEngineError(final String errMsg) {
gui.runOnUIThread(new Runnable() { gui.runOnUIThread(new Runnable() {

View File

@ -29,8 +29,8 @@ class GtbProbe {
GtbProbe() { GtbProbe() {
} }
final synchronized void setPath(String tbPath) { final synchronized void setPath(String tbPath, boolean forceReload) {
if (!currTbPath.equals(tbPath)) { if (forceReload || !currTbPath.equals(tbPath)) {
currTbPath = tbPath; currTbPath = tbPath;
init(tbPath); init(tbPath);
} }

View File

@ -50,9 +50,9 @@ public class Probe {
whitePieces = new byte[65]; whitePieces = new byte[65];
blackPieces = new byte[65]; blackPieces = new byte[65];
} }
public void setPath(String tbPath) { public void setPath(String tbPath, boolean forceReload) {
gtb.setPath(tbPath); gtb.setPath(tbPath, forceReload);
} }
public static final class ProbeResult { public static final class ProbeResult {