コード例 #1
0
        public void SearchEngine()
        {
            var board = new ChessBoard();

            ChessBoard.MovePosS bestMove;
            int iPremCount;
            int iCacheHit;
            int iMaxDepth;

            board.FindBestMove(
                new SearchEngine.SearchMode(
                    new BoardEvaluationUtil().BoardEvaluators[0],
                    new BoardEvaluationUtil().BoardEvaluators[0],
                    SrcChess2.SearchEngine.SearchMode.OptionE.UseAlphaBeta,
                    SrcChess2.SearchEngine.SearchMode.ThreadingModeE.DifferentThreadForSearch,
                    2,
                    15,
                    SrcChess2.SearchEngine.SearchMode.RandomModeE.Off
                    ),
                ChessBoard.PlayerColorE.Black,
                out bestMove,
                out iPremCount,
                out iCacheHit,
                out iMaxDepth);
            Console.WriteLine(bestMove.StartPos + @"   " + bestMove.EndPos);
        }
コード例 #2
0
        /// <summary>
        /// Find the best move for a player using alpha-beta pruning or minmax search
        /// </summary>
        /// <param name="searchMode">       Search mode</param>
        /// <param name="chessBoard">       Chess board to use. Null to use the base one</param>
        /// <param name="moveBest">         Best move found</param>
        /// <param name="iPermCount">       Total permutation evaluated</param>
        /// <param name="iCacheHit">        Number of moves found in the translation table cache</param>
        /// <param name="iMaxDepth">        Maximum depth evaluated</param>
        /// <returns>
        /// true if a move has been found
        /// </returns>
        public bool FindBestMove(SearchEngine.SearchMode searchMode, ChessBoard chessBoard, out ChessBoard.MovePosS moveBest, out int iPermCount, out int iCacheHit, out int iMaxDepth)
        {
            bool    bRetVal;
            bool    bUseBook;

            bUseBook = ((searchMode.m_eOption & SearchEngine.SearchMode.OptionE.UseBook) != 0);
            if (bUseBook && FindBookMove(searchMode, out moveBest)) {
                iPermCount = -1;
                iCacheHit  = -1;
                iMaxDepth  = 0;
                bRetVal    = true;
            } else {
                if (chessBoard == null) {
                    chessBoard = m_board;
                }
                m_dateTimeStartSearching = DateTime.Now;
                bRetVal                  = chessBoard.FindBestMove(searchMode, m_board.NextMoveColor, out moveBest, out iPermCount, out iCacheHit, out iMaxDepth);
                m_timeSpanLastSearch     = DateTime.Now - m_dateTimeStartSearching;
            }
            return(bRetVal);
        }