Exemple #1
0
        private void newPseudoMoves()
        {
#if NoCapacity
            PseudoQueenPromotion        = new List <Move>();
            PseudoUnderPromotion        = new List <Move>();
            PseudoQueenPromotionCapture = new List <Move>();
            PseudoUnderPromotionCapture = new List <Move>();
            PseudoEPCapture             = new List <Move>();
            PseudoCastles = new List <Move>();

            PseudoPawnAboveMove = new List <Move>();
            PseudoPawnBelowMove = new List <Move>();
            PseudoKingMove      = new List <Move>();
            PseudoKnightMove    = new List <Move>();
            PseudoDiagAboveMove = new List <Move>();
            PseudoDiagBelowMove = new List <Move>();
            PseudoRectAboveMove = new List <Move>();
            PseudoRectBelowMove = new List <Move>();

            PseudoPawnAboveCapture = new List <Move>();
            PseudoPawnBelowCapture = new List <Move>();
            PseudoKingCapture      = new List <Move>();
            PseudoKnightCapture    = new List <Move>();
            PseudoDiagAboveCapture = new List <Move>();
            PseudoDiagBelowCapture = new List <Move>();
            PseudoRectAboveCapture = new List <Move>();
            PseudoRectBelowCapture = new List <Move>();

            PseudoGoodCaptures = new List <Move>();
            PseudoBadCaptures  = new List <Move>();
            PseudoCaptures     = new List <Move>();
            PseudoMoves        = new List <Move>();
#else
            PseudoQueenPromotion        = new List <Move>(2);
            PseudoUnderPromotion        = new List <Move>(2 * 3);
            PseudoQueenPromotionCapture = new List <Move>(2);
            PseudoUnderPromotionCapture = new List <Move>(2 * 3);
            PseudoEPCapture             = new List <Move>(2);
            PseudoCastles = new List <Move>(2);

            PseudoPawnAboveMove = new List <Move>(8 * 3);
            PseudoPawnBelowMove = new List <Move>(8 * 3);
            PseudoKingMove      = new List <Move>(8);
            PseudoKnightMove    = new List <Move>(2 * 8);
            PseudoDiagAboveMove = new List <Move>(2 * 13);
            PseudoDiagBelowMove = new List <Move>(2 * 13);
            PseudoRectAboveMove = new List <Move>(2 * 14);
            PseudoRectBelowMove = new List <Move>(2 * 14);

            PseudoPawnAboveCapture = new List <Move>(8 * 2);
            PseudoPawnBelowCapture = new List <Move>(8 * 2);
            PseudoKingCapture      = new List <Move>(6);
            PseudoKnightCapture    = new List <Move>(2 * 6);
            PseudoDiagAboveCapture = new List <Move>(2 * 4);
            PseudoDiagBelowCapture = new List <Move>(2 * 4);
            PseudoRectAboveCapture = new List <Move>(2 * 4);
            PseudoRectBelowCapture = new List <Move>(2 * 4);

            PseudoGoodCaptures = new List <Move>(32);
            PseudoBadCaptures  = new List <Move>(32);
            PseudoCaptures     = new List <Move>(48);
            PseudoMoves        = new List <Move>(128);
#endif
#if UseMoveSort
            SortMoves = new SortMove[512];
#if LazyMoveSort
            PriorityMove = new Heap <SortMove>(default, SortMoves, 0);
Exemple #2
0
        protected Int32 sortMoves(List <Move> moves, List <GoodMove> goodMoves, Depth wDepth)
        {
            //[Test]goodMoves.Sort();

            var nMoves     = moves.Count;
            var mLateStart = Eval.MaxValue;
            var nEarly     = 0;         //[Init]

            foreach (var move in moves)
            {
                var nIndex = goodMoves.FindIndex(gm => equalMoves(gm.Move, move));
                if (nIndex >= 0)
                {
                    nEarly++;
                    State.IncEarlyMoveCount(SearchPly); // Update EarlyMove Histogram
                    var good       = goodMoves[nIndex];
                    var mGoodValue = good.Value;
                    if (EvalUndefined < mGoodValue && mGoodValue < mLateStart)
                    {
                        mLateStart = mGoodValue;
                    }
                }
            }

            var bWTM = WTM();

            State.AddEarlyTotal(bWTM, nEarly);

            var mLateNext  = mLateStart;
            var nGenerated = 0;

            foreach (var move in moves)
            {
                var nIndex = goodMoves.FindIndex(gm => equalMoves(gm.Move, move));
#if TestGoodValue
                var mValue = EvalUndefined;

                if (nIndex < 0)
                {
                    mValue = --mLateNext;
                }
                else
                {
                    var good       = goodMoves[nIndex];
                    var mGoodValue = good.Value;
                    //mValue = EvalUndefined < mGoodValue ? mGoodValue : (Eval)(mLateStart - nIndex);
                    if (EvalUndefined < mGoodValue)
                    {
                        mValue = mGoodValue;
                    }
                    else
                    {
                        mValue = (Eval)(mLateStart - nIndex);
                    }
                }
#else
                var mValue = nIndex < 0 ? EvalUndefined : (Eval)(Eval.MaxValue - nIndex);
#endif
                //
                // nGenerated index is included in SortMove so a Stable
                // Sort can be implemented on its IComparable interface
                //
                SortMoves[nGenerated++] = new SortMove(move, nGenerated, mValue, wDepth);
            }
#if LazyMoveSort
            PriorityMove.Truncate();    // Truncate Heap, preparing to rebuild.
            PriorityMove.IsAscending = true;

            //
            // Convert SortMoves[] into a Heap:
            //
            PriorityMove.Build(nGenerated);
#else
            Array.Sort <SortMove>(SortMoves, 0, nGenerated);
#endif
#if DebugMoveOrder
            if (IsTrace())
            {
                DisplayCurrent("sortMoves()");

                var sb = new StringBuilder();
#if LazyMoveSort
                var nMoveIndex = 0;
                foreach (var sm in PriorityMove)
                {
#else
                for (var nMoveIndex = 0; nMoveIndex < nGenerated; nMoveIndex++)
                {
                    var sm = SortMoves[nMoveIndex];
#endif
                    sb.Clear();
                    sb.AppendAN(sm.Move, State.Rule.IsChess960);
                    LogLine($"{nMoveIndex}) {sb}: Depth = {sm.Depth}, Value = {sm.Value}, Index = {sm.Index}");
#if LazyMoveSort
                    nMoveIndex++;
#endif
                }
#if LazyMoveSort
                Trace.Assert(!PriorityMove.IsAscending, "Heap Ascending after enumeration");
                if (!PriorityMove.IsAscending)
                {
                    PriorityMove.Reverse();
                }
#endif
            }
#endif                                  // DebugMoveOrder
            if (nGenerated != nMoves)
            {
                Debug.Assert(nGenerated == nMoves, "nGenerated != nMoves");
            }

            //[Commented]Scale(bWTM, wPly, 0.75f);
            return(nEarly);
        }