當前位置: 首頁>>代碼示例>>C#>>正文


C# Board.Reback方法代碼示例

本文整理匯總了C#中Board.Reback方法的典型用法代碼示例。如果您正苦於以下問題:C# Board.Reback方法的具體用法?C# Board.Reback怎麽用?C# Board.Reback使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Board的用法示例。


在下文中一共展示了Board.Reback方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: FastestFirstSolve

        /// <summary>
        /// 最快優先搜索
        /// </summary> 
        private int FastestFirstSolve(Board board, int alpha, int beta, int depth, SearchResult searchResult, int cur, int opp, bool prevmove = true)
        {
            lock (this) {
                //計算搜索的結點數
                searchResult.Nodes++;
                /*
                //嘗試置換表裁剪,並得到置換表走法
                HashResult hashResult = board.ReadHash(alpha, beta, depth);
                if (hashResult != null) {
                    Message.Hits++;
                    return hashResult.Score;
                }
                */

                if (board.EmptyCount == 0) {//遊戲結束
                    return EndEval(board,cur);
                }

                //葉子節點,局麵估分
                if (depth == 0) {
                    return Eval(board, cur);
                }

                int mvBest = 0;
                int score = -MaxScore;
                //是否調用零窗口的標誌
                bool foundPv = false;
                int eval;

                #region hash code
                /*
                //int mvHash = hashResult.Move;
                //初始化最佳值和最佳走法

                HashType hashType = HashType.LOWER_BOUND;

                //初始化走法排序結構
                board.InitMoves(); //board.InitMoves(mvHash);

                int quickMove = board.GetQuickMove();

                //            if (moveDefend > Evalation.Defend_FreeThree)
                //                return moveDefend;
                //if (board.MoveHash != 0)
                //    quickMove = board.MoveHash;
                //else if ((board.MoveKiller1 != board.MoveHash) && (board.MoveKiller1 != 0) && board.CanMove(board.MoveKiller1))
                //    quickMove = board.MoveKiller1;
                //else if ((board.MoveKiller2 != board.MoveHash) && (board.MoveKiller2 != 0) && board.CanMove(board.MoveKiller2))
                //    quickMove = board.MoveKiller2;

                if (quickMove != 0) {
                    //---------------------------
                    board.MakeMove(quickMove);
                    eval = -FastestFirstSolve(board, -beta, -alpha, depth - 1);
                    //恢複到上一步
                    board.Reback(quickMove);

                    if (eval > alpha) {
                        if (eval >= beta) {
                            //----------------------
                            hashType = HashType.UPPER_BOUND;
                            // 記錄到置換表
                            board.StoreHash(hashType, eval, depth, quickMove);
                            //TODO:有點懷疑是否需要這個條件
                            if (mvBest != 0) {
                                // 如果不是Alpha走法,就將最佳走法保存到曆史表
                                board.StoreBestMove(quickMove, depth);
                            }
                            //剪枝
                            return eval;
                        }
                        //----------------
                        hashType = HashType.EXACT;

                        alpha = eval;
                        foundPv = true;
                    }
                }

                Roulette roulette = new Roulette();
                int gness;
                int moves = roulette.CalculateGoodness(out gness);

                if (gness == Evalation.InfScore) {
                    return gness;
                }
                */

                #endregion

                var moves = rule.FindFlips(board, cur).ToList();

                if (moves.Count == 0) {
                    if (!prevmove) {//遊戲結束
                        return EndEval(board,cur);
                        /*
                        if (discdiff > 0)//自己贏
//.........這裏部分代碼省略.........
開發者ID:coolcode,項目名稱:ai,代碼行數:101,代碼來源:EndGameEngine.cs

示例2: Search

        public override SearchResult Search(Board board, int color,int depth)
        {
            SearchResult searchResult = new SearchResult();
            //board.CurrentColor = color;
            //PrepareToSolve(board);
            int alpha = -MaxScore - 1;
            int beta = MaxScore + 1;
            int opp =  color.Opp();

            Clock clock = new Clock();
            clock.Start();
            //Roulette roulette = new Roulette();
            //board.RefreshHash();

            int score = -MaxScore;
            int eval;
            //是否調用零窗口的標誌
            bool foundPv = false;

            var moves = rule.FindFlips(board, color).ToList();

            if (moves.Count == 0) {
                return new SearchResult() { Move = -1 };
            }

            //if (moves.Count == 1) {
            //    return new SearchResult() { Move = moves.First().Pos };
            //}

            for (int i = 0; i < moves.Count; i++) {
                var pos = moves[i].Pos;
                //下棋
                //---------------------------
                int flipCount = board.MakeMove(pos, color);

                searchResult.Nodes++;
                //檢測
                if (foundPv) {
                    //調用零窗口
                    eval = -FastestFirstSolve(board, -alpha - 1, -alpha, depth - 1, searchResult, opp, color);
                    if ((eval > alpha) && (eval < beta)) {
                        eval = -FastestFirstSolve(board, -beta, -eval, depth - 1, searchResult, opp, color);
                        //eval = -FastestFirstMidSolve( -beta, -alpha, oppcolor, depth - 1);
                    }
                }
                else {
                    eval = -FastestFirstSolve(board, -beta, -alpha, depth - 1, searchResult, opp, color);
                }

                //em.ReLink();
                //---------------------------
                //Eval.StepsPop(color);
                //恢複到上一步
                board.Reback(pos, flipCount, opp);

                searchResult.Message += string.Format("({0}:{1})", pos, eval);
                if (eval > score) {
                    score = eval;
                    //更新位置
                    searchResult.Move = pos;
                    searchResult.Score = score;

                    if (eval > alpha) {
                        if (eval >= beta) {
                            //剪枝
                            break;
                        }
                        alpha = eval;
                        foundPv = true;
                    }
                }
            }

            clock.Stop();

            searchResult.TimeSpan = clock.Elapsed;

            return searchResult;
        }
開發者ID:coolcode,項目名稱:ai,代碼行數:79,代碼來源:EndGameEngine.cs

示例3: Gen

        private void Gen(TextWriter writer, Board board, int color, bool prevmove = true)
        {
            if (Records >= Limit) {
                return;
            }

            if (board.EmptyCount == EndGameDepth) {
                var searchResult = Engine.Search(board.Copy(), color, this.SearchDepth);
                WriteRecord(writer, board, searchResult.Score, searchResult.Move, color);

                Records++;

                //每1000條記錄就Flush一次
                if (Records % 1000 == 0) {
                    Console.WriteLine("Write Records: {0}", Records);
                    writer.Flush();
                }

                return;
            }

            int opp = color.Opp();
            var moves = rule.FindFlips(board, color).ToList();

            if (moves.Count == 0) {
                if (prevmove) {
                    Gen(writer, board, opp, false);
                }

                return;
            }

            foreach (var move in moves) {
                int flipCount = board.MakeMove(move.Pos, color);

                Gen(writer, board, opp);

                board.Reback(move.Pos, flipCount, opp);
            }
        }
開發者ID:coolcode,項目名稱:ai,代碼行數:40,代碼來源:Knowledge.cs


注:本文中的Board.Reback方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。