public static int Evaluate(BoardState board, EvaluationStatistics statistics, int openingPhase, int endingPhase)
        {
            var entry = PawnHashTable.Get(board.PawnHash);

            if (entry.IsKeyValid(board.PawnHash))
            {
#if DEBUG
                statistics.PHTHits++;
#endif
                return(entry.Score);
            }
#if DEBUG
            else
            {
                statistics.PHTNonHits++;

                if (entry.Key != 0 || entry.Score != 0)
                {
                    statistics.PHTReplacements++;
                }
            }
#endif

            var result = Evaluate(board, Color.White, openingPhase, endingPhase) -
                         Evaluate(board, Color.Black, openingPhase, endingPhase);

            PawnHashTable.Add(board.PawnHash, (short)result);

#if DEBUG
            statistics.PHTAddedEntries++;
#endif
            return(result);
        }
Ejemplo n.º 2
0
        public static int Evaluate(BoardState board, EvaluationStatistics statistics, int openingPhase, int endingPhase)
        {
            var entry = PawnHashTable.Get(board.PawnHash);

            if (entry.IsKeyValid(board.PawnHash))
            {
#if DEBUG
                statistics.PHTHits++;
#endif
                return(TaperedEvaluation.AdjustToPhase(entry.OpeningScore, entry.EndingScore, openingPhase, endingPhase));
            }
#if DEBUG
            else
            {
                statistics.PHTNonHits++;

                if (entry.Key != 0 || entry.OpeningScore != 0 || entry.EndingScore != 0)
                {
                    statistics.PHTReplacements++;
                }
            }
#endif

            var(openingWhiteScore, endingWhiteScore) = Evaluate(board, Color.White, openingPhase, endingPhase);
            var(openingBlackScore, endingBlackScore) = Evaluate(board, Color.Black, openingPhase, endingPhase);

            var openingScore = openingWhiteScore - openingBlackScore;
            var endingScore  = endingWhiteScore - endingBlackScore;
            var result       = TaperedEvaluation.AdjustToPhase(openingScore, endingScore, openingPhase, endingPhase);

            PawnHashTable.Add(board.PawnHash, (short)openingScore, (short)endingScore);

#if DEBUG
            statistics.PHTAddedEntries++;
#endif
            return(result);
        }