使用C#实现与ELEEYE引擎的基本通讯

使用以下代码请遵循协议.

 

ChessEngine
public static class ChessEngine
{
    
public static string NextStep(string FEN, bool isRed, int timeSpan)
    {
        Process proEngine 
= new Process();

        proEngine.StartInfo.FileName 
= "eleeye.exe";

        proEngine.StartInfo.CreateNoWindow 
= true;
        proEngine.StartInfo.RedirectStandardError 
= true;
        proEngine.StartInfo.RedirectStandardInput 
= true;
        proEngine.StartInfo.RedirectStandardOutput 
= true;
        proEngine.StartInfo.UseShellExecute 
= false;

        proEngine.Start();

        proEngine.StandardInput.WriteLine(
"ucci");
        proEngine.StandardInput.WriteLine(
"setoption batch on");
        proEngine.StandardInput.WriteLine(
"position fen " + FEN + " " + (isRed ? "w" : "b"+ " - - 0 0");
        proEngine.StandardInput.WriteLine(
"go time " + timeSpan.ToString());
        proEngine.StandardInput.WriteLine(
"quit");
        
string output = proEngine.StandardOutput.ReadToEnd();
        proEngine.Close();
        Regex regex 
= new Regex(@"bestmove\s.*?\n");
        
return regex.Match(output).Group[0].Substring(94);
    }
}

 

参考代码: http://www.cnblogs.com/zcsor/archive/2009/10/23/1588641.html

posted @ 2010-01-04 18:57  杨圣青  阅读(380)  评论(0编辑  收藏  举报