使用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( 9 4 );
    }
}

 

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

你可能感兴趣的:(C#)