mirror of
https://github.com/peterosterlund2/droidfish.git
synced 2025-02-12 07:07:54 +01:00
DroidFish: Disabled the internal stockfish engine on Android 1.5, because it doesn't work there.
This commit is contained in:
parent
6c85f9e0c1
commit
441b6bc59a
|
@ -21,11 +21,11 @@
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Class: org_petero_droidfish_engine_NativeUtil
|
* Class: org_petero_droidfish_engine_EngineUtil
|
||||||
* Method: getNPhysicalProcessors
|
* Method: getNPhysicalProcessors
|
||||||
* Signature: ()I
|
* Signature: ()I
|
||||||
*/
|
*/
|
||||||
extern "C" JNIEXPORT jint JNICALL Java_org_petero_droidfish_engine_NativeUtil_getNPhysicalProcessors
|
extern "C" JNIEXPORT jint JNICALL Java_org_petero_droidfish_engine_EngineUtil_getNPhysicalProcessors
|
||||||
(JNIEnv *, jclass)
|
(JNIEnv *, jclass)
|
||||||
{
|
{
|
||||||
return sysconf(_SC_NPROCESSORS_ONLN);
|
return sysconf(_SC_NPROCESSORS_ONLN);
|
||||||
|
|
|
@ -35,6 +35,7 @@ import org.petero.droidfish.activities.EditPGNSave;
|
||||||
import org.petero.droidfish.activities.LoadScid;
|
import org.petero.droidfish.activities.LoadScid;
|
||||||
import org.petero.droidfish.activities.Preferences;
|
import org.petero.droidfish.activities.Preferences;
|
||||||
import org.petero.droidfish.book.BookOptions;
|
import org.petero.droidfish.book.BookOptions;
|
||||||
|
import org.petero.droidfish.engine.EngineUtil;
|
||||||
import org.petero.droidfish.gamelogic.DroidChessController;
|
import org.petero.droidfish.gamelogic.DroidChessController;
|
||||||
import org.petero.droidfish.gamelogic.ChessParseError;
|
import org.petero.droidfish.gamelogic.ChessParseError;
|
||||||
import org.petero.droidfish.gamelogic.Move;
|
import org.petero.droidfish.gamelogic.Move;
|
||||||
|
@ -1251,19 +1252,25 @@ public class DroidFish extends Activity implements GUIInterface {
|
||||||
case SELECT_ENGINE_DIALOG: {
|
case SELECT_ENGINE_DIALOG: {
|
||||||
String[] fileNames = findFilesInDirectory(engineDir, null);
|
String[] fileNames = findFilesInDirectory(engineDir, null);
|
||||||
final int numFiles = fileNames.length;
|
final int numFiles = fileNames.length;
|
||||||
final String[] items = new String[numFiles + 2];
|
boolean haveSf = EngineUtil.internalStockFishName() != null;
|
||||||
final String[] ids = new String[numFiles + 2];
|
final int nEngines = numFiles + (haveSf ? 2 : 1);
|
||||||
ids[0] = "stockfish"; items[0] = getString(R.string.stockfish_engine);
|
final String[] items = new String[nEngines];
|
||||||
ids[1] = "cuckoochess"; items[1] = getString(R.string.cuckoochess_engine);
|
final String[] ids = new String[nEngines];
|
||||||
|
int idx = 0;
|
||||||
|
if (haveSf) {
|
||||||
|
ids[idx] = "stockfish"; items[idx] = getString(R.string.stockfish_engine); idx++;
|
||||||
|
}
|
||||||
|
ids[idx] = "cuckoochess"; items[idx] = getString(R.string.cuckoochess_engine); idx++;
|
||||||
String sep = File.separator;
|
String sep = File.separator;
|
||||||
String base = Environment.getExternalStorageDirectory() + sep + engineDir + sep;
|
String base = Environment.getExternalStorageDirectory() + sep + engineDir + sep;
|
||||||
for (int i = 0; i < numFiles; i++) {
|
for (int i = 0; i < numFiles; i++) {
|
||||||
ids[i+2] = base + fileNames[i];
|
ids[idx] = base + fileNames[i];
|
||||||
items[i+2] = fileNames[i];
|
items[idx] = fileNames[i];
|
||||||
|
idx++;
|
||||||
}
|
}
|
||||||
String currEngine = ctrl.getEngine();
|
String currEngine = ctrl.getEngine();
|
||||||
int defaultItem = 0;
|
int defaultItem = 0;
|
||||||
for (int i = 0; i < ids.length; i++) {
|
for (int i = 0; i < nEngines; i++) {
|
||||||
if (ids[i].equals(currEngine)) {
|
if (ids[i].equals(currEngine)) {
|
||||||
defaultItem = i;
|
defaultItem = i;
|
||||||
break;
|
break;
|
||||||
|
@ -1273,7 +1280,7 @@ public class DroidFish extends Activity implements GUIInterface {
|
||||||
builder.setTitle(R.string.select_chess_engine);
|
builder.setTitle(R.string.select_chess_engine);
|
||||||
builder.setSingleChoiceItems(items, defaultItem, new DialogInterface.OnClickListener() {
|
builder.setSingleChoiceItems(items, defaultItem, new DialogInterface.OnClickListener() {
|
||||||
public void onClick(DialogInterface dialog, int item) {
|
public void onClick(DialogInterface dialog, int item) {
|
||||||
if ((item < 0) || (item >= ids.length))
|
if ((item < 0) || (item >= nEngines))
|
||||||
return;
|
return;
|
||||||
Editor editor = settings.edit();
|
Editor editor = settings.edit();
|
||||||
String engine = ids[item];
|
String engine = ids[item];
|
||||||
|
|
|
@ -928,7 +928,7 @@ public class DroidComputerPlayer {
|
||||||
nCPUsFromProc = nCPUs;
|
nCPUsFromProc = nCPUs;
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
}
|
}
|
||||||
int nCPUsFromOS = NativeUtil.getNPhysicalProcessors();
|
int nCPUsFromOS = EngineUtil.getNPhysicalProcessors();
|
||||||
return Math.max(nCPUsFromProc, nCPUsFromOS);
|
return Math.max(nCPUsFromProc, nCPUsFromOS);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -18,11 +18,26 @@
|
||||||
|
|
||||||
package org.petero.droidfish.engine;
|
package org.petero.droidfish.engine;
|
||||||
|
|
||||||
public class NativeUtil {
|
import android.os.Build;
|
||||||
|
|
||||||
|
public class EngineUtil {
|
||||||
static {
|
static {
|
||||||
System.loadLibrary("nativeutil");
|
System.loadLibrary("nativeutil");
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Return number of physical processors, i.e. hyper-threading ignored. */
|
/** Return number of physical processors, i.e. hyper-threading ignored. */
|
||||||
final static native int getNPhysicalProcessors();
|
final static native int getNPhysicalProcessors();
|
||||||
|
|
||||||
|
private static final class CpuAbi {
|
||||||
|
static final String get() { return Build.CPU_ABI; }
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Return file name of the internal stockfish executable,
|
||||||
|
* or null if the internal stockfish engine is not supported. */
|
||||||
|
public static String internalStockFishName() {
|
||||||
|
final int sdkVersion = Integer.parseInt(Build.VERSION.SDK);
|
||||||
|
if (sdkVersion < 4)
|
||||||
|
return null;
|
||||||
|
return "stockfish-" + CpuAbi.get();
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -30,7 +30,6 @@ import java.security.MessageDigest;
|
||||||
import java.security.NoSuchAlgorithmException;
|
import java.security.NoSuchAlgorithmException;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.os.Build;
|
|
||||||
|
|
||||||
/** Stockfish engine running as process, started from assets resource. */
|
/** Stockfish engine running as process, started from assets resource. */
|
||||||
public class InternalStockFish extends ExternalEngine {
|
public class InternalStockFish extends ExternalEngine {
|
||||||
|
@ -51,10 +50,6 @@ public class InternalStockFish extends ExternalEngine {
|
||||||
setOption("Skill Level", strength/50);
|
setOption("Skill Level", strength/50);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static final class CpuAbi {
|
|
||||||
final String get() { return Build.CPU_ABI; }
|
|
||||||
}
|
|
||||||
|
|
||||||
private final long readCheckSum(File f) {
|
private final long readCheckSum(File f) {
|
||||||
InputStream is = null;
|
InputStream is = null;
|
||||||
try {
|
try {
|
||||||
|
@ -109,9 +104,7 @@ public class InternalStockFish extends ExternalEngine {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void copyFile(File from, File to) throws IOException {
|
protected void copyFile(File from, File to) throws IOException {
|
||||||
final int sdkVersion = Integer.parseInt(Build.VERSION.SDK);
|
final String sfExe = EngineUtil.internalStockFishName();
|
||||||
final String abi = (sdkVersion < 4) ? "armeabi" : new CpuAbi().get();
|
|
||||||
final String sfExe = "stockfish-" + abi;
|
|
||||||
|
|
||||||
// The checksum test is to avoid writing to /data unless necessary,
|
// The checksum test is to avoid writing to /data unless necessary,
|
||||||
// on the assumption that it will reduce memory wear.
|
// on the assumption that it will reduce memory wear.
|
||||||
|
|
|
@ -29,6 +29,8 @@ public abstract class UCIEngineBase implements UCIEngine {
|
||||||
private boolean processAlive;
|
private boolean processAlive;
|
||||||
|
|
||||||
public static UCIEngine getEngine(Context context, String engine, Report report) {
|
public static UCIEngine getEngine(Context context, String engine, Report report) {
|
||||||
|
if ("stockfish".equals(engine) && (EngineUtil.internalStockFishName() == null))
|
||||||
|
engine = "cuckoochess";
|
||||||
if ("cuckoochess".equals(engine))
|
if ("cuckoochess".equals(engine))
|
||||||
return new CuckooChessEngine(report);
|
return new CuckooChessEngine(report);
|
||||||
else if ("stockfish".equals(engine))
|
else if ("stockfish".equals(engine))
|
||||||
|
|
Loading…
Reference in New Issue
Block a user