Пример #1
0
        /// <summary>
        /// AI啟動計算函式
        /// </summary>
        /// <param name="csq">當前地圖</param>
        /// <param name="cside">當前陣營方</param>
        /// <param name="stepNum">預計算之步數</param>
        public void AIStart(chessSquare csq, chessSquare.chessSides cside, int stepNum)
        {
            stepNumTot = stepNum;
            chessSquare.chessSides Ncside = cside;
            AIside = cside;
            if ((int)cside == 1)
            {
                Ncside = chessSquare.chessSides.Black;
            }
            else
            {
                Ncside = chessSquare.chessSides.White;
            }
            Console.WriteLine("============");
            sw.WriteLine("==============");
            sw.WriteLine(csq.CoverToForsythEdwardsNotation());

            //清除資料
            CPSZero      = null;
            ZeroMaxScore = int.MinValue;

            //計算另外一方之aSquare
            //csq.chessPointQnsALL(Ncside);
            csq.ListChessUpdate(Ncside, true);
            csq.aSquareUpdate(Ncside);

            //=================計算我方之路線
            AImain(new WalkRoute(csq, null, 0, cside, 0, stepNum, int.MinValue, int.MaxValue));
            //}
            //如果最終選擇之路線被宣告為無效者,且分數為負者,則棄手。
            if (CPSZero.FinalSelectWR.RouteIsInValid == true && CPSZero.FinalSelectWR.score < 0)
            {
                Rcwp           = null;
                AIGiveUpAction = true;
            }
            else
            {
                Rcwp = CPSZero.FinalSelectWR.cwp;
            }
            Console.WriteLine("============");
            sw.WriteLine("==============");
        }
Пример #2
0
        static void Main(string[] args)
        {
            bool GameTest = false;  //是否開啟循環測試模式

            do
            {
                GameRecord GRM = new GameRecord();
                //================
                ChessAI_MS ai  = new ChessAI_MS();
                ChessAI_MS ai2 = new ChessAI_MS();
                //================
                GUIVS gvs = new GUIVS();
                Pawn.DGetWalkRouteFuc         = new D_GetWalkRoute(GRM.GetWalkRoute);
                chessSquare.dQnsSpecailNO3Fnc = new D_QNSSpecialNo3(gvs.QnsSpecialNO3CMD);
                chessWalkPoint         cwpUser = null;
                chessSquare.chessSides gamecsideUser;
                chessSquare.chessSides gamecsideAI;
                chessSquare            csq = new chessSquare();
                chessSquare            csqBefore;
                int step = 0;
                //=============================================
                gamecsideUser = gvs.WBQnsUI();
                if ((int)gamecsideUser == 1)
                {
                    gamecsideAI = chessSquare.chessSides.Black;
                }
                else
                {
                    gamecsideAI = chessSquare.chessSides.White;
                }
                //=============================================
                csq.DebugPrint();
                Console.WriteLine();
                //================
                while (true)
                {
                    csqBefore = new chessSquare(csq, true);
                    ++step;
                    //====================
                    if (gamecsideUser == chessSquare.chessSides.White)
                    {
                        gvs.GameNowTurn = 1;
                        cwpUser         = gvs.UserTurnModeUI();
                        csq.movechess(cwpUser);
                        GRM.AddWalkRoute(cwpUser, csq.SquareInformationString(), GRM.CoverToAlgebraicNotation(cwpUser, csqBefore, csq));
                        Console.WriteLine(step + "." + GRM.GetWalkSAN());
                    }
                    else if (gamecsideAI == chessSquare.chessSides.White)
                    {
                        gvs.GameNowTurn = 2;
                        ai2.AIStart(new chessSquare(csq, true), gamecsideAI, 4);
                        if (ai2.Rcwp == null && ai2.AIGiveUpAction == true)
                        {
                            Console.WriteLine("{0} Give Up.", gamecsideAI);
                            GRM.reportSentMessage = string.Format("{0} Give Up.", gamecsideAI);
                            break;
                        }
                        else
                        {
                            Console.WriteLine("\n{0}{1}=>{2}{3} Type={4}\n",
                                              (char)(ai2.Rcwp.pNumX + 96), ai2.Rcwp.pNumY, (char)(ai2.Rcwp.nNumX + 96), ai2.Rcwp.nNumY, ai2.Rcwp.SpecialNum);
                            csq.movechess(ai2.Rcwp);
                            GRM.AddWalkRoute(ai2.Rcwp, csq.SquareInformationString(), GRM.CoverToAlgebraicNotation(ai2.Rcwp, csqBefore, csq));
                            csq.DebugPrint();
                            Console.WriteLine(csq.CoverToForsythEdwardsNotation());
                            Console.WriteLine(step + "." + GRM.GetWalkSAN());
                        }
                    }
                    //====================
                    if (GRM.CheckchessDraw(csq) == true)
                    {
                        if (GRM.DrawNum == 1)
                        {
                            Console.WriteLine("Draw:3步重複規則。");
                            GRM.reportSentMessage = "Draw:3步重複規則。";
                        }
                        else if (GRM.DrawNum == 2)
                        {
                            Console.WriteLine("Draw:50步規則。");
                            GRM.reportSentMessage = "Draw:50步規則。";
                        }
                        break;
                    }
                    if (gvs.CheckChessWin(csq, chessSquare.chessSides.White) == true)
                    {
                        Console.WriteLine("{0} Win!", chessSquare.chessSides.White);
                        GRM.reportSentMessage = string.Format("{0} Win!", chessSquare.chessSides.White);
                        break;
                    }
                    //====================================================
                    csqBefore = new chessSquare(csq, true);
                    //====================================================
                    if (gamecsideAI == chessSquare.chessSides.Black)
                    {
                        gvs.GameNowTurn = 2;
                        ai.AIStart(new chessSquare(csq, true), gamecsideAI, 4);
                        if (ai.Rcwp == null && ai.AIGiveUpAction == true)
                        {
                            Console.WriteLine("{0} Give Up.", gamecsideAI);
                            GRM.reportSentMessage = string.Format("{0} Give Up.", gamecsideAI);
                            break;
                        }
                        else
                        {
                            Console.WriteLine("\n{0}{1}=>{2}{3} Type={4}\n",
                                              (char)(ai.Rcwp.pNumX + 96), ai.Rcwp.pNumY, (char)(ai.Rcwp.nNumX + 96), ai.Rcwp.nNumY, ai.Rcwp.SpecialNum);
                            csq.movechess(ai.Rcwp);
                            GRM.AddWalkRoute(ai.Rcwp, csq.SquareInformationString(), GRM.CoverToAlgebraicNotation(ai.Rcwp, csqBefore, csq));
                            csq.DebugPrint();
                            Console.WriteLine(step + "." + GRM.GetWalkSAN());
                        }
                    }
                    else if (gamecsideUser == chessSquare.chessSides.Black)
                    {
                        gvs.GameNowTurn = 1;
                        cwpUser         = gvs.UserTurnModeUI();
                        csq.movechess(cwpUser);
                        GRM.AddWalkRoute(cwpUser, csq.SquareInformationString(), GRM.CoverToAlgebraicNotation(cwpUser, csqBefore, csq));
                        Console.WriteLine(step + "." + GRM.GetWalkSAN());
                    }
                    //=================
                    if (GRM.CheckchessDraw(csq) == true)
                    {
                        if (GRM.DrawNum == 1)
                        {
                            Console.WriteLine("Draw:3步重複規則。");
                            GRM.reportSentMessage = "Draw:3步重複規則。";
                        }
                        else if (GRM.DrawNum == 2)
                        {
                            Console.WriteLine("Draw:50步規則。");
                            GRM.reportSentMessage = "Draw:50步規則。";
                        }
                        break;
                    }
                    if (gvs.CheckChessWin(csq, chessSquare.chessSides.Black) == true)
                    {
                        Console.WriteLine("{0} Win!", chessSquare.chessSides.Black);
                        GRM.reportSentMessage = string.Format("{0} Win!", chessSquare.chessSides.Black);
                        break;
                    }
                }
                if (GRM.GameTotNum > 0)
                {
                    GRM.recordExport();
                }
            } while (GameTest == true);
            if (GameTest == false)
            {
                Console.ReadLine();
            }
        }