/// <summary> /// 将棋エンジンを起動します。 /// </summary> public void Start(string shogiEngineFilePath) { try { if (this.ShogiEngineManInterface.IsLive()) { Util_Message.Show("将棋エンジンサービスは終了していません。"); goto gt_EndMethod; } //------------------------------ // ログファイルを削除します。 //------------------------------ Logger.RemoveAllLogFile(); ProcessStartInfo startInfo = new ProcessStartInfo(); startInfo.FileName = shogiEngineFilePath; // 実行するファイル名 //startInfo.CreateNoWindow = true; // コンソール・ウィンドウを開かない startInfo.UseShellExecute = false; // シェル機能を使用しない startInfo.RedirectStandardInput = true; //標準入力をリダイレクト startInfo.RedirectStandardOutput = true; // 標準出力をリダイレクト this.ShogiEngineManInterface.ShogiServerMessenger.ShogiEngine = Process.Start(startInfo); // アプリの実行開始 // OutputDataReceivedイベントハンドラを追加 this.ShogiEngineManInterface.ShogiServerMessenger.ShogiEngine.OutputDataReceived += this.ListenUpload_Async; this.ShogiEngineManInterface.ShogiServerMessenger.ShogiEngine.Exited += this.OnExited; // 非同期受信スタート☆! this.ShogiEngineManInterface.ShogiServerMessenger.ShogiEngine.BeginOutputReadLine(); // 「usi」 this.ShogiEngineManInterface.Usi(); // エンジン設定 // 「setoption」 //Server.shogiEnginePr.StandardInput.WriteLine("setoption"); // // サーバー・スレッドはここで終了しますが、 // 代わりに、Server.shogiEnginePr プロセスが動き続け、 // ReceivedData_FromShogiEngine メソッドが非同期に呼び出され続けます。 // //this.thread = new Thread(new ThreadStart(Server.Main2)); //this.thread.IsBackground = true; //this.thread.Start(); } catch (Exception ex) { Util_Message.Show(ex.GetType().Name + ":" + ex.Message); } gt_EndMethod: ; }
public bool Write() { bool successfule = true; XmlDocument xDoc = new XmlDocument(); // UTF-8 エンコーディングで書くものとします。 XmlProcessingInstruction xPi = xDoc.CreateProcessingInstruction("xml", "version=\"1.0\" encoding=\"UTF-8\""); xDoc.AppendChild(xPi); try { // ルート要素 <kifunarabe> を作成 XmlElement xKifunarabe = xDoc.CreateElement("kifunarabe"); xDoc.AppendChild(xKifunarabe); // setteiFileVer="1.00.0" xKifunarabe.SetAttribute("setteiFileVer", this.SetteiFileVer); // コメント xKifunarabe.AppendChild(xDoc.CreateComment("v(^-^)vイェーイ☆ 『将棋GUI きふならべ』の設定ファイルなんだぜ☆! 今は一番上に書いてある <shogiEngine> を見に行くぜ☆")); // <shogiEngine> XmlElement xShogiEngine = xDoc.CreateElement("shogiEngine"); // name="The将棋エンジン" xShogiEngine.SetAttribute("file", this.ShogiEngineName); // file="shogiEngine.exe" xShogiEngine.SetAttribute("file", this.ShogiEngineFilePath); xKifunarabe.AppendChild(xShogiEngine); // .xmlファイルを保存 xDoc.Save(this.SetteiFileName); } catch (Exception ex) { // エラー successfule = false; Util_Message.Show(ex.GetType().Name + " " + ex.Message); } return(successfule); }
/// <summary> /// 将棋エンジンを起動します。 /// </summary> public void Start(string shogiEngineFilePath) { try { if (this.ShogiEngineProcessWrapper.IsLive_ShogiEngine()) { Util_Message.Show("将棋エンジンサービスは終了していません。"); goto gt_EndMethod; } //------------------------------ // ログファイルを削除します。 //------------------------------ Logger.RemoveAllLogFiles(); ProcessStartInfo startInfo = new ProcessStartInfo(); startInfo.FileName = shogiEngineFilePath; // 実行するファイル名 //startInfo.CreateNoWindow = true; // コンソール・ウィンドウを開かない startInfo.UseShellExecute = false; // シェル機能を使用しない startInfo.RedirectStandardInput = true; //標準入力をリダイレクト startInfo.RedirectStandardOutput = true; // 標準出力をリダイレクト this.ShogiEngineProcessWrapper.SetShogiEngine(Process.Start(startInfo)); // アプリの実行開始 // OutputDataReceivedイベントハンドラを追加 this.ShogiEngineProcessWrapper.ShogiEngine.OutputDataReceived += this.Receiver.OnListenUpload_Async; this.ShogiEngineProcessWrapper.ShogiEngine.Exited += this.OnExited; // 非同期受信スタート☆! this.ShogiEngineProcessWrapper.ShogiEngine.BeginOutputReadLine(); } catch (Exception ex) { Util_Message.Show($"{ex}"); } gt_EndMethod: ; }
/// <summary> /// ************************************************************************************************************************ /// 1手進む /// ************************************************************************************************************************ /// /// <棋譜読込用><マウス入力非対応> /// /// 「棋譜並べモード」と「vsコンピューター対局」でも、これを使いますが、 /// 「棋譜並べモード」では送られてくる SFEN が「position startpos moves 8c8d」とフルであるのに対し、 /// 「vsコンピューター対局」では、送られてくる SFEN が「8c8d」だけです。 /// /// それにより、処理の流れが異なります。 /// /// </summary> public static bool ReadLine_TuginoItteSusumu_Srv( ref string inputLine, Model_Taikyoku model_Taikyoku,//SetCurNodeがある。[コマ送り][再生]などで使用。 Model_Manual model_Manual, out bool toBreak, string hint , [CallerMemberName] string memberName = "", [CallerFilePath] string sourceFilePath = "", [CallerLineNumber] int sourceLineNumber = 0 ) { //IErrorController logTag = OwataMinister.SERVER_KIFU_YOMITORI; bool successful = false; KifuParserA_Impl kifuParserA_Impl = new KifuParserA_Impl(); KifuParserA_Result result = new KifuParserA_ResultImpl(); KifuParserA_Genjo genjo = new KifuParserA_GenjoImpl(inputLine); try { if (kifuParserA_Impl.State is KifuParserA_StateA0_Document) { // 最初はここ #if DEBUG Logger.Trace("(^o^)... ..."); Logger.Trace($"サイショハココ☆ : {memberName}.{sourceFilePath}.{sourceLineNumber}"); #endif inputLine = kifuParserA_Impl.Execute_Step( ref result, model_Taikyoku, genjo ); Debug.Assert(result.Out_newNode_OrNull == null, "ここでノードに変化があるのはおかしい。"); if (genjo.IsBreak()) { goto gt_EndMethod; } // (1)position コマンドを処理しました。→startpos // (2)日本式棋譜で、何もしませんでした。→moves } if (kifuParserA_Impl.State is KifuParserA_StateA1_SfenPosition) { //------------------------------------------------------------ // このブロックでは「position ~ moves 」まで一気に(*1)を処理します。 //------------------------------------------------------------ // // *1…初期配置を作るということです。 // { #if DEBUG string message = $"(^o^)ツギハ ヒラテ マタハ シテイキョクメン ヲ ショリシタイ☆ inputLine=[{inputLine}]"; Logger.Trace(message); #endif inputLine = kifuParserA_Impl.Execute_Step( ref result, model_Taikyoku, genjo ); Debug.Assert(result.Out_newNode_OrNull == null, "ここでノードに変化があるのはおかしい。"); if (genjo.IsBreak()) { goto gt_EndMethod; } } { #if DEBUG Logger.Trace("(^o^)ツギハ ムーブス ヲ ショリシタイ☆"); #endif inputLine = kifuParserA_Impl.Execute_Step( ref result, model_Taikyoku, genjo ); Debug.Assert(result.Out_newNode_OrNull == null, "ここでノードに変化があるのはおかしい。"); if (genjo.IsBreak()) { goto gt_EndMethod; } // moves を処理しました。 // ここまでで、「position ~ moves 」といった記述が入力されていたとすれば、入力欄から削除済みです。 } // →moves } // // 対COMP戦で関係があるのはここです。 // if (kifuParserA_Impl.State is KifuParserA_StateA2_SfenMoves) { #if DEBUG Logger.Trace("ツギハ イッテ ショリシタイ☆"); #endif inputLine = kifuParserA_Impl.Execute_Step( ref result, model_Taikyoku, genjo ); if (null != result.Out_newNode_OrNull) { string jsaFugoStr; Util_Functions_Server.SetCurNode_Srv(model_Taikyoku, model_Manual, result.Out_newNode_OrNull, out jsaFugoStr); } if (genjo.IsBreak()) { goto gt_EndMethod; } // 1手を処理した☆? } if (null != genjo.StartposImporter_OrNull) { // 初期配置が平手でないとき。 // ************************************************************************************************************************ // SFENの初期配置の書き方(*1)を元に、駒を並べます。 // ************************************************************************************************************************ // // *1…「position startpos moves 7g7f 3c3d 2g2f」といった書き方。 // ParsedKyokumen parsedKyokumen = Conv_StartposImporter.ToParsedKyokumen( model_Manual, genjo.StartposImporter_OrNull,//指定されているはず。 genjo ); //------------------------------ // 駒の配置 //------------------------------ string jsaFugoStr; Util_Functions_Server.SetCurNode_Srv(model_Taikyoku, model_Manual, parsedKyokumen.KifuNode, out jsaFugoStr);// GUIに通知するだけ。 ////------------------------------ //// 駒を、駒袋から駒台に移動させます。 ////------------------------------ //model_Operating.Manual.SetGuiSky( // SkyConst.NewInstance( // parsedKyokumen.buffer_Sky, // -1//そのまま // ) //); } successful = true; } catch (Exception ex) { Util_Message.Show($"{ex}"); toBreak = true; successful = false; } gt_EndMethod: toBreak = genjo.IsBreak(); return(successful); }
/// <summary> /// 1手進む /// /// <棋譜読込用><マウス入力非対応> /// /// 「棋譜並べモード」と「vsコンピューター対局」でも、これを使いますが、 /// 「棋譜並べモード」では送られてくる SFEN が「position startpos moves 8c8d」とフルであるのに対し、 /// 「vsコンピューター対局」では、送られてくる SFEN が「8c8d」だけです。 /// /// それにより、処理の流れが異なります。 /// /// </summary> public static bool ReadLine_TuginoItteSusumu_Srv( ref string inputLine, IRoomViewModel roomViewModel, out bool toBreak, string hint , [CallerMemberName] string memberName = "", [CallerFilePath] string sourceFilePath = "", [CallerLineNumber] int sourceLineNumber = 0 ) { bool successful = false; KifuParserA_Impl kifuParserA_Impl = new KifuParserA_Impl(); KifuParserA_Result result = new KifuParserA_ResultImpl(); KifuParserA_Genjo genjo = new KifuParserA_GenjoImpl(inputLine); try { kifuParserA_Impl.Delegate_OnChangeSky_Im_Srv = Util_InServer.OnChangeSky_Im_Srv; if (kifuParserA_Impl.State is KifuParserA_StateA0_Document) { // 最初はここ Logger.Trace("... ..."); Logger.Trace("サイショハココ☆ : " + memberName + "." + sourceFilePath + "." + sourceLineNumber); inputLine = kifuParserA_Impl.Execute_Step( ref result, roomViewModel, genjo ); Debug.Assert(result.Out_newNode_OrNull == null, "ここでノードに変化があるのはおかしい。"); if (genjo.ToBreak) { goto gt_EndMethod; } // (1)position コマンドを処理しました。→startpos // (2)日本式棋譜で、何もしませんでした。→moves } if (kifuParserA_Impl.State is KifuParserA_StateA1_SfenPosition) { //------------------------------------------------------------ // このブロックでは「position ~ moves 」まで一気に(*1)を処理します。 //------------------------------------------------------------ // // *1…初期配置を作るということです。 // { string message = "ツギハ ヒラテ マタハ シテイキョクメン ヲ ショリシタイ☆ inputLine=[" + inputLine + "]"; Logger.Trace(message); inputLine = kifuParserA_Impl.Execute_Step( ref result, roomViewModel, genjo ); Debug.Assert(result.Out_newNode_OrNull == null, "ここでノードに変化があるのはおかしい。"); if (genjo.ToBreak) { goto gt_EndMethod; } } { Logger.Trace("ツギハ ムーブス ヲ ショリシタイ☆"); inputLine = kifuParserA_Impl.Execute_Step( ref result, roomViewModel, genjo ); Debug.Assert(result.Out_newNode_OrNull == null, "ここでノードに変化があるのはおかしい。"); if (genjo.ToBreak) { goto gt_EndMethod; } // moves を処理しました。 // ここまでで、「position ~ moves 」といった記述が入力されていたとすれば、入力欄から削除済みです。 } // →moves } // // 対COMP戦で関係があるのはここです。 // if (kifuParserA_Impl.State is KifuParserA_StateA2_SfenMoves) { Logger.Trace("ツギハ イッテ ショリシタイ☆"); inputLine = kifuParserA_Impl.Execute_Step( ref result, roomViewModel, genjo ); if (null != result.Out_newNode_OrNull) { Util_InServer.SetCurNode_Srv(roomViewModel, result.Out_newNode_OrNull); } if (genjo.ToBreak) { goto gt_EndMethod; } // 1手を処理した☆? } successful = true; } catch (Exception ex) { Util_Message.Show(ex.GetType().Name + ":" + ex.Message); toBreak = true; successful = false; } gt_EndMethod: toBreak = genjo.ToBreak; return(successful); }
/// <summary> /// ************************************************************************************************************************ /// 打った駒の種類。 /// ************************************************************************************************************************ /// </summary> /// <param name="syurui"></param> /// <returns></returns> public static void SfenUttaSyurui(string sfen, out PieceType syurui) { switch (sfen) { case "P": syurui = PieceType.P; break; case "L": syurui = PieceType.L; break; case "N": syurui = PieceType.N; break; case "S": syurui = PieceType.S; break; case "G": syurui = PieceType.G; break; case "R": syurui = PieceType.R; break; case "B": syurui = PieceType.B; break; case "K": syurui = PieceType.K; break; case "+P": syurui = PieceType.PP; break; case "+L": syurui = PieceType.PL; break; case "+N": syurui = PieceType.PN; break; case "+S": syurui = PieceType.PS; break; case "+R": syurui = PieceType.R; break; case "+B": syurui = PieceType.B; break; default: Util_Message.Show($"▲バグ【駒種類】Sfen=[{sfen}]"); syurui = PieceType.None; break; } }