1

I'm looking for a way to execute a chess engine (Stockfish, for example) without having to use NDK and JNI.

The main issue I have is, how to execute a software (like in a prompt) and keep it running as it send to me the outputs.

The second and more specific issue is how to get the installed chess engines on the device, if it is possible (and if there is a way to make use of them).

below I tell in details I want to achieve

I don't know if what I want to do is even possible, so I will explain: when you install a chess engine app, like Komodo or Stockfish, when you execute them you see a message informing that you have to download a GUI app in order to it to work as a fully chess program. What anyone can infer from these messages is that a GUI App can make use of an installed engine in a device.

Is there a way to see the installed engines on the device to show on an select box, and "extract" these engines from the apps, or to find the location of them in the device, or to execute the apps via another way similar to intents?

The problem is that a chess engine is a software that has to be kept running to avail a position; you send them the position you like them to avail and as they analyse, they keep sending you their avaliation, and they keep doind this until you send them a comand to stop.

If you execute the Stockfish in the prompt of the Windows, you can see clearly what I am talking about. When it execute, it waits for a command; them you send a comand "uci"; then you send a comand like "position fen ", then you send "go infinite" and they start calculating and kept sending output about their calculation.

So, I would like to create an app that make use of the installed engines in the device.

Until now I didn't discover how to do that. I had to download the DoidFish app source code and analysed what they did... and they got the source code of stockfish and executed it with JNI.

But that way I would have a fixed and limited engine list on my app, and I would be leaving out the engines which have no opened source, like Komodo and Houdini. I see that the Chessbase app can use several engines, as you can see in the screenshots in the app's page. They also showed the Komodo engine in the list (as I purchase the app to see)... I have Komodo installed... So they had to do in some other way...

As I couldn't solve the mistery, I downloaded the compiled arm version of the stockfish, and tried to execute it with the Runtime's exec method like:

Runtime rt = Runtime.getRuntime();
String[] commands = {enginePath, "uci"};

Process proc = rt.exec(commands);

However an engine is a software that you have to execute, and it has to be kept running as you send comands to it as I explained before, but in this way I executed the engine, then it sent to me an output (I got with BufferedReader) and then stopped executing.

Sorry for a so big text, could you help me to figure that out?

jairhumberto
  • 535
  • 1
  • 11
  • 31

3 Answers3

1

Playstore rules prevent compiling the GUI with the Engine; but you can Host the engine online, create a PWA with Yandex.Disk or bubble.io and googledrive, or do APK apps to F-Droid; (more on that below).

This eliminates your compilation issues and trades them for some others.

Android uses OEX open exchange protocol; the GUI must support this. (such as droidfish supports this, and a git-branch of droidfish called 'Harmon Honey App');

Android NDK is used to compile the c++ into an installable apk (Gradle);
This is why you get a 'splash screen'. With NDK the Engine is treated as a java app by design; and when the developer compiled the engine in android studio they chose that template. In 2021, you can open Android studio --> File--> New --> C++ Native --> previously this option did not exist and NDK was side loaded. You had no choice but to create a template.

The publisher of the OEX app is NOT the Dev. I emailed Karl Schreiner who published many engines on playstore; he replied to me promptly and was very knowledgable but stated he does not compile them or know how. I reached out to the DEV of Acid-Ape-Studio; for which they declined to answer but was nice enough to point me in the direction of Android NDK as the preferred method. (I guess cross-compile is easier then Kotlin Conversion from C-Code)
Use a Linter, Inspector, and Smart Syntax AI if possible.

The Chess GUI (in this case Droidfish) Calls the engine.

ISSUE 1: This does NOT Guarantee the engine was compiled for your ARM7, ARM8, mobile hardware Etc...

ISSUE 2: This ALSO Does not guarantee UCI features will work such as SYZGZY Probe, Opening Book, Novelty bitboard (Scorpio), winboard, MCTS, Frutility, or other analysis tricks; and most important NN-Classic options (Neural Net Location and type).

ISSUE 3: Playstore Rules! You Cannot Pre-Compile the GUI and the Engine. and not sure if rules prevent pre-compile of EGTB with Engine.

Your best bet; create a PWA or PWA similar service like Yandex.disk or Web2Android; and even let users post their engines. Edit the PWA Features to Use Lichess API to call EGTB, Bots, and other stuff. Create a Dropdown inside the PWA to download offline tablesbases, offline NNUE, training FEN's, training EPD suites, etc.

(Why LiChess doesn't do personal bots, or host vintage engines with cookies for UCI settings? Or personality bots already? Well they do "Kindof"; you can post your bots, but they need to be hosted somehow by you...and then there's the cheaters).

Workaround for the mostly-technical; You can host your own bot easily with Banksai-GUI and a Lichess BOT API Account. Then fire up your android tablet and challenge the BOT to a game.

Technically you can host this bot anyhow you please; even on Docker, GoogleDrive, and Droidfish also has a "Network Engine" feature.

I Tried going on Fivver to hire a dev to compile for me. I was NOT Successful.

If you are successful; please post your engine somewhere others can enjoy it such as GITHUB, and Chess Engine Forums.

user132992
  • 11
  • 2
0

If you are wondering how Stockfish exposes itself to different chess GUI apps, look at Stockfish Chess source code.

Note that you will need an understanding of Bound Services and AIDL which are advanced topics for Android. So as long as a specific chess engine supports interface ccc.chess.engines.IChessEngineService appropriately the GUI app can use the same mechanism to communicate with it.

While that would describe how the connection is made, as you are aware, the protocol between the engine and GUI would be the Universal Chess Interface

Morrison Chang
  • 11,691
  • 3
  • 41
  • 77
0

In order to keep the engine running, I had to use the ProcessBuild to create a process.

For that I used the following code:

    process = processBuilder.start(); // To run the engine

    //
    // Start the thread that will handle the responses of the engine.
    //
    Thread responseThread = new Thread(runnableobject);
    responseThread.start(); // Then treat the response in this file

To get an installed engine, I used the intent "intent.chess.provider.ENGINE"

jairhumberto
  • 535
  • 1
  • 11
  • 31