Ejemplo n.º 1
0
        //public AbdadaTable AbdadaTable { get; }

        public SearchState()
        {
            TranspositionTable      = new TranspositionTable();
            PrincipalVariationTable = new PrincipalVariationTable();
            //AbdadaTable = new AbdadaTable();
            ThreadStates = new ThreadUniqueState[SearchConstants.ThreadCount];
            for (int i = 0; i < ThreadStates.Length; i++)
            {
                ThreadStates[i] = new ThreadUniqueState(i);
            }
            EmptyContinuation = new ContinuationEntry();
        }
Ejemplo n.º 2
0
        public void OrderNextMove2(int currentIndex, Move[] moves, int[] staticScores, int[] seeScores, int moveCount, ThreadUniqueState state)
        {
            var bestScore      = int.MinValue;
            var bestScoreIndex = -1;

            for (var i = currentIndex; i < moveCount; i++)
            {
                var move  = moves[i];
                var score = staticScores[i];
                if (move.TakesPiece != ChessPiece.Empty)
                {
                    score += state.CaptureHistory[move.Piece][move.To][move.TakesPiece];
                }
                else if (score == 0)
                {
                    //if (score < 6_000_000 && move.Key2 == countermove)
                    //{
                    //    score = 7_000_000;
                    //}
                    score += state.History[move.ColorToMove][move.From][move.To];
                    //score += state.PieceToHistory[move.Piece][move.To] >> 2;
                    //score = 0;
                }

                if (score > bestScore)
                {
                    bestScore      = score;
                    bestScoreIndex = i;
                }
            }

            if (currentIndex != bestScoreIndex)
            {
                var bestMove   = moves[bestScoreIndex];
                var bestSee    = seeScores[bestScoreIndex];
                var bestStatic = staticScores[bestScoreIndex];

                for (int i = bestScoreIndex - 1; i >= currentIndex; i--)
                {
                    moves[i + 1]        = moves[i];
                    seeScores[i + 1]    = seeScores[i];
                    staticScores[i + 1] = staticScores[i];
                }

                moves[currentIndex]        = bestMove;
                seeScores[currentIndex]    = bestSee;
                staticScores[currentIndex] = bestStatic;
            }
        }
Ejemplo n.º 3
0
        public void OrderNextMove(int currentIndex, Move[] moves, int[] staticScores, int[] seeScores, int moveCount, ThreadUniqueState state)
        {
            var bestScore      = int.MinValue;
            var bestScoreIndex = -1;

            for (var i = currentIndex; i < moveCount; i++)
            {
                var move  = moves[i];
                var score = staticScores[i];
                if (move.TakesPiece != ChessPiece.Empty)
                {
                    score += state.CaptureHistory[move.Piece][move.To][move.TakesPiece];
                }
                else
                {
                    if (score == 0)
                    {
                        //if (score < 6_000_000 && move.Key2 == countermove)
                        //{
                        //    score = 7_000_000;
                        //}
                        var historyScore = state.History[move.ColorToMove][move.From][move.To];
                        //var continuation1 = state.CurrentContinuations[0].Scores[move.Piece][move.To];
                        //var continuation2 = state.CurrentContinuations[1].Scores[move.Piece][move.To];
                        //var continuation3 = state.CurrentContinuations[2].Scores[move.Piece][move.To];
                        //var continuation4 = state.CurrentContinuations[3].Scores[move.Piece][move.To];


                        //var continuationScores = state.CurrentContinuations.Select(x => x?.Scores[move.Piece][move.To]).ToList();
                        score += historyScore;
                        //score += continuation1 * 2;
                        //score += continuation2;
                        //score += continuation3;
                        //score += continuation4;
                        //if (score == 0)
                        //{
                        //    score += historyScore >> 2;
                        //}
                        //var a = state.CurrentContinuations;
                        //score += state.PieceToHistory[move.Piece][move.To] >> 2;
                        //score = 0;
                    }
                }

                if (score > bestScore)
                {
                    bestScore      = score;
                    bestScoreIndex = i;
                }
            }

            var tempMove = moves[currentIndex];

            moves[currentIndex]   = moves[bestScoreIndex];
            moves[bestScoreIndex] = tempMove;

            var tempSee = seeScores[currentIndex];

            seeScores[currentIndex]   = seeScores[bestScoreIndex];
            seeScores[bestScoreIndex] = tempSee;

            var tempScore = staticScores[currentIndex];

            staticScores[currentIndex]   = staticScores[bestScoreIndex];
            staticScores[bestScoreIndex] = tempScore;
        }