StockFi sh Chess Engine не будет работать на устройстве Android, но отлично работает в автономном редакторе сборки и Unity - PullRequest
0 голосов
/ 13 апреля 2020

Я работал над шахматной игрой и использую шахматный движок Stockfi sh для реализации ИИ. Мне удалось запустить исполняемый файл, отправить код FEN в качестве входных данных и получить выходные данные из движка. Отлично работает на редакторе Unity и автономной сборке. Но, это не будет работать для устройства android. Я понятия не имею, почему.

Я убедился, что файл скопирован / создан в правильный каталог и успешно. Может кто-нибудь помочь мне разобраться с этой проблемой?

    string fen;
    public static Process mProcess;

    void Start()
    {
        Setup();
    }


    public void Setup()
    {
        // since the apk file is archived this code retreives the stockfish binary data and
        // creates a copy of it in the persistantdatapath location.
#if UNITY_EDITOR

        string filepath = "D:\\Chess Projects\\StockFishTest\\Assets\\StreamingAssets\\stockfish_10_x64.exe";
#elif UNITY_ANDROID
        string filepath = Application.persistentDataPath + "/" + "stockfish-10-armv7";
        Debug.Log(filepath);
        if (!File.Exists(filepath))
        {
            WWW executable = new WWW("jar:file://" + Application.dataPath + "!/assets/" + "stockfish-10-armv7");
            while (!executable.isDone)
            {
            }
            File.WriteAllBytes(filepath, executable.bytes);

            //change permissions via plugin

        }
        var plugin = new AndroidJavaClass("com.chessbattles.jeyasurya.consoleplugin.AndroidConsole");
            string command = "chmod 777 "+filepath;
            outPut = plugin.CallStatic<string>("ExecuteCommand",command);

#else
        string filepath = Application.streamingAssetsPath+ "/" + "stockfish_10_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.OutputDataReceived += new DataReceivedEventHandler(MProcess_OutputDataReceived);
        mProcess.Start();
        mProcess.BeginErrorReadLine();
        mProcess.BeginOutputReadLine();

        SendLine("uci");
        SendLine("isready");

    }

    public void GetMove(string fen, int processTime = 0, int DepthValue = 1)
    {

        if(fen ==null || fen == ""){
            UnityEngine.Debug.LogError("Enter proper Fen");
            Debug.Log("Enter proper Fen");
            return;
        }

        SendLine("position fen "+ fen);

        if(processTime != 0){
            SendLine("go movetime "+processTime);
        }
        else if(DepthValue != 0)
        {
            SendLine("go depth "+ DepthValue);
        }
        else
        {
            SendLine("go depth " + DepthValue);
        }

    }

    public string output = "";
    public bool moveReady = false;
    public void SendLine(string command) {
        mProcess.StandardInput.WriteLine(command);
        mProcess.StandardInput.Flush();
    }

    void MProcess_OutputDataReceived(object sender, DataReceivedEventArgs e)
    {
        output = "";
    //    UnityEngine.Debug.Log("Output: " + e.Data);
        output = e.Data;
        if (output.Length != 0)
            if (output[0] == 'b' && output[3] == 't')
            {
                output = e.Data.Substring(9, 4);
      //          Debug.Log(output);
                moveReady = true;
            }
            else
            {
                moveReady = false;
            }

    }
...