public ChessEngineManager() { procEngine = null; queReceived = null; swWRiter = null; //srReader = null; //srErrReader = null; cmdParser = null; configData = null; }
public void End() { queReceived.Clear(); swWRiter.Close(); // 비동기 로딩 스트림은 클로즈 하면 안된다!!! //srReader.Close(); //srErrReader.Close(); procEngine.Kill(); procEngine.Close(); procEngine = null; cmdParser = null; configData = null; }
private ChessEngineManager() { procEngine = null; queReceived = null; queSyncRoot = new object(); //swWRiter = null; threadSend = null; sendWorker = null; //srReader = null; //srErrReader = null; cmdParser = null; DefaultConfigData = null; CurrentConfigData = null; IsEngineInit = false; IsEngineRunning = false; IsPonderMode = false; IsPonderFailed = false; IsWaitforNewGame = false; IsForceStop = false; }
// interface public IEnumerator Start() { // clear received command respond que queReceived = new Queue(); procEngine = new Process(); procEngine.StartInfo.FileName = strProcPath; //procEngine.StartInfo.Arguments = "uci"; procEngine.StartInfo.CreateNoWindow = true; procEngine.StartInfo.UseShellExecute = false; procEngine.StartInfo.ErrorDialog = false; procEngine.StartInfo.RedirectStandardOutput = true; procEngine.StartInfo.RedirectStandardInput = true; //procEngine.StartInfo.RedirectStandardError = true; // Set our event handler to asynchronously read the sort output/err. procEngine.OutputDataReceived += new DataReceivedEventHandler(StandardOutputHandler); //procEngine.ErrorDataReceived += new DataReceivedEventHandler(StandardErrorHandler); // start chess engine(stockfish) procEngine.Start(); // Start the asynchronous read of the output stream. procEngine.BeginOutputReadLine(); //procEngine.BeginErrorReadLine(); swWRiter = procEngine.StandardInput; //srReader = procEngine.StandardOutput; //srErrReader = procEngine.StandardError; cmdParser = new ChessEngineCmdParser() { Cmd = null }; configData = new ChessEngineConfig(); // wait for 2.0 sec for process thread running yield return new WaitForSeconds(2.0f); // send command to chess engine // 첫번째 명령이 안먹는 이유는????? // 실행 파라미터로 "uci"를 주어야 하는데 스트림 리다이렉션때문에 이게 안먹힘... // Send( "Ping Test" ); Send( "uci" ); //Send( "isready" ); }
// interface //public IEnumerator Start() { public void Start() { // clear received command respond que queReceived = new Queue<string>(); try { procEngine = new Process(); procEngine.StartInfo.FileName = strProcPath; //procEngine.StartInfo.WorkingDirectory = @"ChessEngine\"; //procEngine.StartInfo.Arguments = "uci"; procEngine.StartInfo.CreateNoWindow = true; procEngine.StartInfo.UseShellExecute = false; procEngine.StartInfo.ErrorDialog = false; procEngine.StartInfo.RedirectStandardOutput = true; procEngine.StartInfo.RedirectStandardInput = true; procEngine.StartInfo.RedirectStandardError = true; // Set our event handler to asynchronously read the sort output/err. procEngine.OutputDataReceived += new DataReceivedEventHandler(StandardOutputHandler); procEngine.ErrorDataReceived += new DataReceivedEventHandler(StandardErrorHandler); // start chess engine(stockfish) procEngine.Start(); // Start the asynchronous read of the output stream. procEngine.BeginOutputReadLine(); procEngine.BeginErrorReadLine(); //swWRiter = procEngine.StandardInput; //swWRiter.AutoFlush = true; //srReader = procEngine.StandardOutput; //srErrReader = procEngine.StandardError; cmdParser = new ChessEngineCmdParser() { Cmd = null }; DefaultConfigData = new ChessEngineConfig(); CurrentConfigData = new ChessEngineConfig(); // wait for 2.0 sec for process thread running //yield return new WaitForSeconds(2.0f); //yield return new WaitForSeconds(5.0f); sendWorker = new SendWorker( procEngine.StandardInput ); threadSend = new Thread(sendWorker.ProcessSend); threadSend.Start(); IsEngineRunning = true; } catch( System.Exception e ) { UnityEngine.Debug.LogError( "ChessEngineManager - Start() Failed!!! because of" + e.Message ); } }
public void End() { if( IsEngineRunning ) { queReceived.Clear(); sendWorker.RequestStop(); threadSend.Join(); threadSend = null; sendWorker = null; // 비동기 로딩 스트림은 클로즈 하면 안된다!!! //srReader.Close(); //srErrReader.Close(); procEngine.CancelOutputRead(); procEngine.CancelErrorRead(); procEngine.Close(); procEngine = null; cmdParser = null; DefaultConfigData = null; CurrentConfigData = null; IsEngineRunning = false; IsEngineInit = false; } }