当前位置: 首页>>代码示例>>C#>>正文


C# Search.timeLimit方法代码示例

本文整理汇总了C#中Search.timeLimit方法的典型用法代码示例。如果您正苦于以下问题:C# Search.timeLimit方法的具体用法?C# Search.timeLimit怎么用?C# Search.timeLimit使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Search的用法示例。


在下文中一共展示了Search.timeLimit方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: findSemiRandomMove

        private Move findSemiRandomMove(Search sc, MoveGen.MoveList moves)
        {
            sc.timeLimit(minTimeMillis, maxTimeMillis);
            Move bestM = sc.iterativeDeepening(moves, 1, maxNodes, verbose);
            int bestScore = bestM.score;

            long t0 = SystemHelper.currentTimeMillis();
            Random rndGen = new Random((int)t0);

            int sum = 0;
            for (int mi = 0; mi < moves.size; mi++) {
            sum += moveProbWeight(moves.m[mi].score, bestScore);
            }
            int rnd = rndGen.Next(sum);
            for (int mi = 0; mi < moves.size; mi++) {
            int weight = moveProbWeight(moves.m[mi].score, bestScore);
            if (rnd < weight) {
                return moves.m[mi];
            }
            rnd -= weight;
            }
            SystemHelper.println("Assert error. Should never get here!");
            return null;
        }
开发者ID:Chessforeva,项目名称:Csharp4chess,代码行数:24,代码来源:ComputerPlayer.cs

示例2: getCommand

        public string getCommand(Position pos, bool drawOffer, List<Position> history)
        {
            // Create a search object
            ulong[] posHashList = new ulong[200 + history.Count];
            int posHashListSize = 0;
            for(int i=0;i<history.Count;i++)
            {
            Position p = history[i];
            posHashList[posHashListSize++] = p.zobristHash();
            }
            tt.nextGeneration();
            Search sc = new Search(pos, posHashList, posHashListSize, tt);

            // Determine all legal moves
            MoveGen.MoveList moves = new MoveGen().pseudoLegalMoves(pos);
            MoveGen.RemoveIllegal(pos, moves);
            sc.scoreMoveList(moves, 0);

            // Test for "game over"
            if (moves.size == 0) {
            // Switch sides so that the human can decide what to do next.
            return "swap";
            }

            if (bookEnabled) {
            Move bookMove = book.getBookMove(pos);
            if (bookMove != null) {
                SystemHelper.printf("Book moves: " + book.getAllBookMoves(pos));
                return TextIO.moveTostring(pos, bookMove, true);
            }
            }

            // Find best move using iterative deepening
            currentSearch = sc;
            sc.setListener(listener);
            Move bestM;
            if ((moves.size == 1) && (canClaimDraw(pos, posHashList, posHashListSize, moves.m[0]) == "")) {
            bestM = moves.m[0];
            bestM.score = 0;
            } else if (randomMode) {
            bestM = findSemiRandomMove(sc, moves);
            } else {
            sc.timeLimit(minTimeMillis, maxTimeMillis);
            bestM = sc.iterativeDeepening(moves, maxDepth, maxNodes, verbose);
            }
            currentSearch = null;
            //        tt.printStats();
            string strMove = TextIO.moveTostring(pos, bestM, true);
            bestmv = bestM;

            // Claim draw if appropriate
            if (bestM.score <= 0) {
            string drawClaim = canClaimDraw(pos, posHashList, posHashListSize, bestM);
            if (drawClaim != "")
                strMove = drawClaim;
            }
            return strMove;
        }
开发者ID:Chessforeva,项目名称:Csharp4chess,代码行数:58,代码来源:ComputerPlayer.cs

示例3: searchPosition

        /** Search a position and return the best move and score. Used for test suite processing. */
        public TwoReturnValues<Move, string> searchPosition(Position pos, int maxTimeMillis)
        {
            // Create a search object
            ulong[] posHashList = new ulong[200];
            tt.nextGeneration();
            Search sc = new Search(pos, posHashList, 0, tt);

            // Determine all legal moves
            MoveGen.MoveList moves = new MoveGen().pseudoLegalMoves(pos);
            MoveGen.RemoveIllegal(pos, moves);
            sc.scoreMoveList(moves, 0);

            // Find best move using iterative deepening
            sc.timeLimit(maxTimeMillis, maxTimeMillis);
            Move bestM = sc.iterativeDeepening(moves, -1, -1, false);

            // Extract PV
            string PV = TextIO.moveTostring(pos, bestM, false) + " ";
            UndoInfo ui = new UndoInfo();
            pos.makeMove(bestM, ui);
            PV += tt.extractPV(pos);
            pos.unMakeMove(bestM, ui);

            //        tt.printStats();

            // Return best move and PV
            return new TwoReturnValues<Move, string>(bestM, PV);
        }
开发者ID:Chessforeva,项目名称:Csharp4chess,代码行数:29,代码来源:ComputerPlayer.cs


注:本文中的Search.timeLimit方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。