USIプロトコルの将棋GUIの開発

徐々にできてきました。
呼び出した思考エンジンをKillが上手く動かなかったんですが、Formのデストラクターの中じゃなくて、
FormClosingメソッドの中でKill()したら、ちゃんとKillしてくれました。
Formのデストラクターの中だと、色々とクローズされててプロセスの情報が無くなってしまってるのかも?
(このへんが、システムがどう動いてるか不透明で嫌な感じですが…)

usi→usiok
isready→readyok
usinewgame→
position startpos→
go btime 0 wtime 0 byoyomi 1000→

で思考開始。実際は定跡があるのですぐ探索は終了する




いい感じですねー
将棋盤を持たせてbestmoveの返事によって駒を動かしつつ、
読み筋の表示とかできるようになれば、ある程度形になりますね
そこにソケット通信を追加して……

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.Diagnostics;
using System.Threading;

namespace hikaru
{
    public partial class Form1 : Form
    {
        private Process process;

        public Form1()
        {
            InitializeComponent();

            process = new Process();
            process.StartInfo.FileName = "main.exe";
            process.StartInfo.UseShellExecute = false;
            process.StartInfo.CreateNoWindow = true;
            process.EnableRaisingEvents = true;
            process.StartInfo.RedirectStandardOutput = true;
            process.StartInfo.RedirectStandardInput = true;
            process.OutputDataReceived += new DataReceivedEventHandler(process_DataReceived);
            process.Start();
            process.BeginOutputReadLine();

            sendEngine("usi");
        }

        private void process_DataReceived(object sender, DataReceivedEventArgs e) {
            this.Invoke((MethodInvoker)delegate
            {
                String text = e.Data;

                richTextBox1.AppendText("RECV:" + e.Data+"\r\n");

                if (e.Data == "usiok")
                {
                    sendEngine("isready");
                }
                if (e.Data == "readyok")
                {
                    sendEngine("usinewgame");
                    sendEngine("position startpos");
                    sendEngine("go btime 0 wtime 0 byoyomi 1000");
                }
                if ( text.IndexOf("bestmove")>=0 )
                {
                    richTextBox1.AppendText("bestmove\r\n");
                }
            });
        }

        private void sendEngine(String text)
        {
                richTextBox1.AppendText("SEND:" + text+"\r\n");
                process.StandardInput.WriteLine(text);
        }

        private void Form1_FormClosing(object sender, FormClosingEventArgs e)
        {
            process.Kill();
        }
    }
}