Chess engine stock fish process for mobile

I am making the chess interface I designed for a game. I am using the process to get answers from a stock fish binary:

stockfish = new Process {
StartInfo = new ProcessStartInfo {
FileName = System.IO.Directory.GetCurrentDirectory () + "\\Assets\\Scripts\\Stockfish\\stockfish.exe",
Arguments = "",
UseShellExecute = false,
RedirectStandardOutput = true,
RedirectStandardInput = true,
RedirectStandardError = true,
CreateNoWindow = true
}

};


The problem I face is it worked for my Windows build but for mobile package build it won't work with the executable. Is there a way around it?

This line should only ever work in Windows version (or for versions that your VS supports):

FileName = System.IO.Directory.GetCurrentDirectory () + "\\Assets\\Scripts\\Stockfish\\stockfish.exe",


For Unity's builder, you need to use Application.dataPath or Application.persistentDataPath. I've had success with using both, the former for accessing the game folder and the latter for saving or loading files.

• You'd also need a version of the external binary compiled for your target platform, as the exe is a Windows executable. Dec 22 '16 at 14:42
• What is the stranded binary for Android and how can i access it ? Can you guide me through on it. Dec 26 '16 at 10:18
• @AhmadIftikhar apk, which you get by changing the build target in Unity. Jan 8 '19 at 15:27

I have managed to make this work like this. You need to update the package name in the file path.

using System.Diagnostics;
using System.IO;
using UnityEngine;

namespace Assets.Scripts
{
public class EngineCommunicator
{
public static Process mProcess;
public static string fileName = "stockfish.android.armv7";
public static void Communicate()
{
#if UNITY_EDITOR
string filepath = "E:\\Personal\\Unity\\Chess2d\\Assets\\Plugins\\Windows\\stockfish_13_win_x64";
#elif UNITY_ANDROID
string filepath = "/data/data/com.tiringbring.Chess2d/lib/stockfish.android.armv7.so";
{
UI.Instance.TestText.GetComponent<TMPro.TextMeshProUGUI>().text = filepath;
});

if (!File.Exists(filepath))
{
{
});
}else{
{
UI.Instance.TestText.GetComponent<TMPro.TextMeshProUGUI>().text =UI.Instance.TestText.GetComponent<TMPro.TextMeshProUGUI>().text +" "+ "file found";
});
}
#else
string filepath = Application.streamingAssetsPath+ "/" + "stockfish_13_x64.exe";
#endif
// creating the process and communicating with the engine
mProcess = new Process();
ProcessStartInfo si = new ProcessStartInfo()
{
FileName = filepath,
UseShellExecute = false,
CreateNoWindow = true,
RedirectStandardError = true,
RedirectStandardInput = true,
RedirectStandardOutput = true
};
mProcess.StartInfo = si;
mProcess.Start();

SendLine("uci");
SendLine("ucinewgame");
SendLine("position startpos");
SendLine("go infinite searchmoves e2e4 d2d4");

}

private static void SendLine(string command)
{
mProcess.StandardInput.WriteLine(command);
mProcess.StandardInput.Flush();
}

{
string text = e.Data;