コード例 #1
0
        public static int CalculateScore(ChessBoard cb, ThreadData threadData)
        {
            var score = MaterialUtil.ScoreUnknown;

            if (BitOperations.PopCount((ulong)cb.AllPieces) <= 5)
            {
                score = MaterialUtil.IsDrawByMaterial(cb)
                    ? EvalConstants.ScoreDraw
                    : MaterialUtil.CalculateEndgameScore(cb);
            }

            if (score == MaterialUtil.ScoreUnknown)
            {
                score = TaperedEval(cb, threadData);
                if (score > 25)
                {
                    score = AdjustEndgame(cb, score, White, threadData.MaterialCache);
                }
                else if (score < -25)
                {
                    score = AdjustEndgame(cb, score, Black, threadData.MaterialCache);
                }
            }

            score *= ColorFactor[cb.ColorToMove];
            if (EngineConstants.TestEvalCaches)
            {
                var cachedScore = EvalCacheUtil.GetScore(cb.ZobristKey, threadData.EvalCache);
                if (cachedScore != CacheMiss)
                {
                    if (cachedScore != score)
                    {
                        throw new ArgumentException($"Cached eval score != score: {cachedScore}, {score}");
                    }
                }
            }

            EvalCacheUtil.AddValue(cb.ZobristKey, score, threadData.EvalCache);

            if (EngineConstants.TestEvalValues)
            {
                ChessBoardTestUtil.CompareScores(cb);
            }

            return(score);
        }
コード例 #2
0
        public static int GetScore(ChessBoard cb, ThreadData threadData)
        {
            if (Statistics.Enabled)
            {
                Statistics.EvalNodes++;
            }

            if (EngineConstants.EnableEvalCache && !EngineConstants.TestEvalCaches)
            {
                var score = EvalCacheUtil.GetScore(cb.ZobristKey, threadData.EvalCache);
                if (score != CacheMiss)
                {
                    return(score);
                }
            }

            return(CalculateScore(cb, threadData));
        }