/// <summary>
        /// Zen走棋(线程)
        /// </summary>
        /// <param name="stepNum"></param>
        public void GetZenMove(int stepNum)
        {
            Task task = Task.Factory.StartNew(() =>
            {
                int turn = stepNum % 4;
                DllImport.SetNumberOfSimulations(aiSettings[turn].Layout);
                DllImport.StartThinking(aiSettings[turn].Color);
                Thread.Sleep(aiSettings[turn].TimePerMove * 1000);
                DllImport.StopThinking();
                //Thread.Sleep(500);
                int x       = 0, y = 0;
                bool isPass = false, isResign = false;
                DllImport.ReadGeneratedMove(ref x, ref y, ref isPass, ref isResign);
                int count     = 0;
                float winRate = 0;
                DllImport.GetTopMoveInfo(0, ref x, ref y, ref count, ref winRate, null, 0);


                DealZenResult(stepNum, x, y, isPass, isResign, count, winRate);
            });
        }
Example #2
0
        private bool Vsgnugo_OnMsgOutput(string obj, Action <int, string> inputMove)
        {
            if (obj.Contains("illegal move"))
            {
                WriteMsgLine("illegal");
                return(true);
            }
            if (obj.Contains("resign"))
            {
                ClientLog.WriteLog(")");
                //MessageBox.Show("done");
                ZenVsGnugoOver();
                return(true);
            }
            if (obj.Contains("PASS"))
            {
                ClientLog.WriteLog(")");
                //MessageBox.Show("done");
                ZenVsGnugoOver();
                return(true);
            }
            obj = obj.Substring(2);

            int opponentColor = DllImport.GetNextColor();

            //分析对手
            DllImport.StartThinking(opponentColor);
            Thread.Sleep(1500);
            DllImport.StopThinking();
            int  opX = 0, opY = 0;
            bool opPass = false, opResign = false;

            DllImport.ReadGeneratedMove(ref opX, ref opY, ref opPass, ref opResign);


            char gnugoOutX = char.Parse(obj.Substring(0, 1));

            if (gnugoOutX > 'I')
            {
                gnugoOutX--;
            }
            int x = gnugoOutX - 'A';

            int y = int.Parse(obj.Substring(1, obj.Length - 1)) - 1;

            DllImport.Play(x, y, opponentColor);
            moveCount++;

            string msg = string.Format(moveCount + "\tgnugo:\t{0}", "" + obj);

            Console.WriteLine(msg);//WriteMsgLine(msg);
            ClientLog.WriteLog(";" + (opponentColor == 1 ? "W" : "B") + "[" + (char)('a' + x) + (char)('a' + y) + "]");
            if (x != opX || y != opY)
            {
                ClientLog.WriteLog("LB[" + (char)('a' + opX) + (char)('a' + opY) + ":A]");
                //ClientLog.WriteLog("LB[" + (char)('a' + opX) + (char)('a' + opY) + ":A]C[Zen认为A点可能更好]");
            }

            int nextColor2 = DllImport.GetNextColor();//这一条有时会得不到正确结果

            DllImport.StartThinking(nextColor2);
            Thread.Sleep(1500);
            DllImport.StopThinking();

            int  selfX = 0, selfY = 0;
            bool selfPass = false, selfResign = false;

            DllImport.ReadGeneratedMove(ref selfX, ref selfY, ref selfPass, ref selfResign);


            int   para0 = 0, para1 = 0, para2 = 0, para3 = 0, para6 = 0;
            float winning = 0;

            byte[] para5 = new byte[19 * 19];
            DllImport.GetTopMoveInfo(para0, ref para1, ref para2, ref para3, ref winning, para5, para6);

            if (selfPass || selfResign)
            {
                ClientLog.WriteLog(")");
                //MessageBox.Show("done");
                ZenVsGnugoOver();
                return(true);
            }

            DllImport.Play(selfX, selfY, nextColor2);
            moveCount++;

            //Console.WriteLine("zen\t" + (nextColor2));

            msg = string.Format(moveCount + "\tZen:\t{0}", "" + (char)('A' + selfX) + (selfY + 1) + "\t  " + winning.ToString("G2"));
            Console.WriteLine(msg);//WriteMsgLine(msg);
            ClientLog.WriteLog(";" + (nextColor2 == 1 ? "W" : "B") + "[" + (char)('a' + selfX) + (char)('a' + selfY) + "]C[预估胜率:" + (winning * 100).ToString("G3") + "%]");

            char gnuX = (char)('A' + selfX);

            if (gnuX > 'H')
            {
                gnuX++;
            }
            inputMove(nextColor2, "" + gnuX + (selfY + 1));
            return(false);
        }