I'm trying to work out how to integrate stockfish (or any UCI compatible engine) into my Android application.
I've downloaded the stockfish Android zip from here: Download Stockfish Engine.
Under the Android directory of the zip there are two files:
I have two questions:
Thanks!
Run AnywhereYou can use Stockfish on your computer or on your iOS or Android device.
You can access Stockfish on Chess.com by going to Chess.com/analysis. Another easy-to-use method of analyzing your games on Chess.com with Stockfish is to select "Analyze" after you complete a game in Live Chess. After you complete a live game on Chess.com, you can select "Analyze" and review your game with Stockfish.
As usual, downloads will be freely available at stockfishchess.org/download. The engine is now significantly stronger than just a few months ago, and wins four times more game pairs than it loses against the previous release version.
Stockfish is written in C++, to call it from a regular Android app written in Java, you need to
After you have learned how to compile Stockfish with JNI, you can interact with the engine via UCI protocol: Here are the UCI Specification.
Then you can call specific methods (e.g. to evaluate a position, or to suggest the best move). It all starts with sending the engine isready
. If you get an answer, you are on the right track.
It would be far easier to modify an existing project like Droidfish instead of starting from scratch.
After many days of searching the internet i have found a solution:
add_executable(
stockfish
benchmark.cpp evaluate.h ...(and the rest of the copied files)
)
targets "stockfish"
like so:externalNativeBuild {
cmake {
targets "stockfish"
cppFlags ""
}
}
lib_stockfish.so
, now the folders should look like this:...
-libs
-arm64-v8a
-lib_stockfish.so
-armeabi-v7a
-lib_stockfish.so
and so on...
...
sourceSets {
main {
jniLibs.srcDirs = ['libs']
}
}
implementation fileTree(dir: "libs", include: ["*.jar", "*.so"])
android:extractNativeLibs="true"
String path = getApplicationContext().getApplicationInfo().nativeLibraryDir+"/lib_stockfish.so";
File file = new File(path);
try {
process = Runtime.getRuntime().exec(file.getPath());
} catch (IOException e) {
e.printStackTrace();
}
Thread outThread = new Thread(new Runnable() {
@Override
public void run() {
Process processOut = process;
if(processOut == null){
return;
}
BufferedReader out = new BufferedReader(new InputStreamReader(processOut.getInputStream()));
String data;
try{
while( (data = out.readLine()) != null ){
//do something with data
}
} catch(IOException e){
}
}
});
outThread.start();
///to give commands
String command = "uci";//or other command
command += "\n";
try {
Process ep = process;
if (ep != null) {
ep.getOutputStream().write(command.getBytes());
ep.getOutputStream().flush();
}
} catch (IOException e) {
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With