I am trying to create a chess AI bot required for a chess game running on a mobile phone by using the Stockfish API in Unity.
I have already downloaded the Stockfish API for Android and Windows from the official site, and the chess AI running on Windows has been completed. However, if I build the project to the Android platform, the engine does not work.
My code looks like this:
#if UNITY_ANDROID
string stockfishPath = Application.persistentDataPath + "/" + "stockfish-android-armv7";
if (!File.Exists(stockfishPath))
{
WWW executable = new WWW("jar:file://" + Application.dataPath + "!/assets/" + "stockfish-android-armv7");
while (!executable.isDone)
{
}
File.WriteAllBytes(stockfishPath, executable.bytes);
//change permissions via plugin
}
var plugin = new AndroidJavaClass("com.chessbattles.jeyasurya.consoleplugin.AndroidConsole");
string command = "chmod 777 "+stockfishPath;
plugin.CallStatic<string>("ExecuteCommand",command);
#else
string stockfishPath = Application.streamingAssetsPath+ "/" + "stockfish-windows-x86-64-avx2.exe";
#endif
tempText.text = stockfishPath;
// Start the Stockfish process
AIProcess = new Process();
AIProcess.StartInfo.FileName = stockfishPath;
AIProcess.StartInfo.UseShellExecute = false;
AIProcess.StartInfo.RedirectStandardInput = true;
AIProcess.StartInfo.RedirectStandardOutput = true;
AIProcess.StartInfo.CreateNoWindow = true;
AIProcess.Start();
In this code, the process is started in the same way on Android and Windows with only the different sources, but as I have no knowledge of Android, I don’t know if this is the right way.
I’ve exhausted just about every online source but have not found the proper solution so any help is much appreciated!
Thanks.