示例#1
0
        internal static MoveContent IterativeSearchOld(Board examineBoard, ChessEngine.Engine.Engine.TimeSettings gameTimeSettings, ref int nodesSearched, ref int nodesQuiessence, ref string pvLine, BackgroundWorker worker, ref byte plyDepthReached, ref byte rootMovesSearched, List <OpeningMove> currentGameBook)
        {
            Zobrist.MarkAncient();
            MoveContent            moveContent1   = new MoveContent();
            MoveContent            moveContent2   = new MoveContent();
            string                 str1           = "";
            List <Search.Position> positionList1  = new List <Search.Position>();
            ResultBoards           sortValidMoves = Search.GetSortValidMoves(examineBoard);

            rootMovesSearched = (byte)sortValidMoves.Positions.Count;
            int  num1  = 30;
            int  num2  = 40;
            byte depth = 1;

            if (gameTimeSettings == ChessEngine.Engine.Engine.TimeSettings.Moves40In10Minutes)
            {
                num1 = 15;
            }
            else if (gameTimeSettings == ChessEngine.Engine.Engine.TimeSettings.Moves40In20Minutes)
            {
                num1 = 30;
            }
            else if (gameTimeSettings == ChessEngine.Engine.Engine.TimeSettings.Moves40In30Minutes)
            {
                num1 = 45;
            }
            else if (gameTimeSettings == ChessEngine.Engine.Engine.TimeSettings.Moves40In40Minutes)
            {
                num1 = 60;
            }
            else if (gameTimeSettings == ChessEngine.Engine.Engine.TimeSettings.Moves40In60Minutes)
            {
                num1 = 90;
            }
            else if (gameTimeSettings == ChessEngine.Engine.Engine.TimeSettings.Moves40In90Minutes)
            {
                num1 = 135;
            }
            DateTime now = DateTime.Now;

            do
            {
                pvLine = "";
                int num3 = -400000000;
                sortValidMoves.Positions.Sort(new Comparison <Board>(Search.Sort));
                foreach (Board position1 in sortValidMoves.Positions)
                {
                    if (DateTime.Now - now > TimeSpan.FromSeconds((double)num1))
                    {
                        pvLine = str1;
                        return(moveContent2);
                    }
                    if (worker != null)
                    {
                        worker.ReportProgress((int)((DateTime.Now - now).TotalSeconds / (double)num1 * 100.0));
                    }
                    List <Search.Position> pvLine1 = new List <Search.Position>();
                    int num4 = -Search.AlphaBeta(position1, depth, -400000000, -num3, ref nodesSearched, ref nodesQuiessence, ref pvLine1, true);
                    if (num4 >= (int)short.MaxValue)
                    {
                        pvLine = str1;
                        return(position1.LastMove);
                    }
                    if ((int)examineBoard.RepeatedMove == 2)
                    {
                        string str2 = Board.Fen(true, position1);
                        foreach (OpeningMove openingMove in currentGameBook)
                        {
                            if (openingMove.EndingFEN == str2)
                            {
                                num4 = 0;
                                break;
                            }
                        }
                    }
                    position1.Score = num4;
                    if (num4 > num3)
                    {
                        List <Search.Position> positionList2 = new List <Search.Position>();
                        pvLine = position1.LastMove.ToString();
                        foreach (Search.Position position2 in pvLine1)
                        {
                            pvLine = pvLine + " " + position2.ToString();
                            positionList2.Add(position2);
                        }
                        positionList2.Reverse();
                        num3         = num4;
                        moveContent1 = position1.LastMove;
                    }
                }
                moveContent2    = moveContent1;
                str1            = pvLine;
                plyDepthReached = depth;
                ++depth;
            }while (DateTime.Now - now < TimeSpan.FromSeconds((double)num1) && (int)plyDepthReached < 19);
            plyDepthReached = (byte)((uint)plyDepthReached + 1U);
            int num5 = num2 != 1 ? num2 - 1 : 40;

            return(moveContent2);
        }
示例#2
0
        internal static MoveContent IterativeSearch(Board examineBoard, byte depth, ref int nodesSearched, ref int nodesQuiessence, ref string pvLine, BackgroundWorker worker, ref byte plyDepthReached, ref byte rootMovesSearched, List <OpeningMove> currentGameBook)
        {
            List <Search.Position> pvLine1 = new List <Search.Position>();
            int num1 = -400000000;

            Zobrist.MarkAncient();
            MoveContent  moveContent    = new MoveContent();
            ResultBoards sortValidMoves = Search.GetSortValidMoves(examineBoard);

            rootMovesSearched = (byte)sortValidMoves.Positions.Count;
            if ((int)rootMovesSearched == 1)
            {
                return(sortValidMoves.Positions[0].LastMove);
            }
            foreach (Board position in sortValidMoves.Positions)
            {
                if (-Search.AlphaBeta(position, (byte)1, -400000000, -num1, ref nodesSearched, ref nodesQuiessence, ref pvLine1, true) >= (int)short.MaxValue)
                {
                    return(position.LastMove);
                }
            }
            int num2 = 0;
            int num3 = -400000000;

            sortValidMoves.Positions.Sort(new Comparison <Board>(Search.Sort));
            --depth;
            plyDepthReached = Search.ModifyDepth(depth, sortValidMoves.Positions.Count);
            foreach (Board position1 in sortValidMoves.Positions)
            {
                ++num2;
                if (worker != null)
                {
                    worker.ReportProgress((int)((Decimal)num2 / (Decimal)sortValidMoves.Positions.Count * new Decimal(100)));
                }
                List <Search.Position> pvLine2 = new List <Search.Position>();
                int num4 = -Search.AlphaBeta(position1, depth, -400000000, -num3, ref nodesSearched, ref nodesQuiessence, ref pvLine2, false);
                if (num4 >= (int)short.MaxValue)
                {
                    return(position1.LastMove);
                }
                if ((int)examineBoard.RepeatedMove == 2)
                {
                    string str = Board.Fen(true, position1);
                    foreach (OpeningMove openingMove in currentGameBook)
                    {
                        if (openingMove.EndingFEN == str)
                        {
                            num4 = 0;
                            break;
                        }
                    }
                }
                position1.Score = num4;
                if (num4 > num3 || num3 == -400000000)
                {
                    pvLine = position1.LastMove.ToString();
                    foreach (Search.Position position2 in pvLine2)
                    {
                        pvLine = pvLine + " " + position2.ToString();
                    }
                    num3        = num4;
                    moveContent = position1.LastMove;
                }
            }
            plyDepthReached = (byte)((uint)plyDepthReached + 1U);
            return(moveContent);
        }