public static EvaluationScore ToRelative(this EvaluationScore score, int plyDistance)
 {
     //// ReSharper disable once ArrangeRedundantParentheses
     return(score.IsCheckmating()
         ? new EvaluationScore(score.Value - plyDistance)
         : (score.IsGettingCheckmated() ? new EvaluationScore(score.Value + plyDistance) : score));
 }
        private VariationLine(
            EvaluationScore value,
            EvaluationScore?localValue,
            [NotNull] ICollection <GameMove> moves)
            : this(value, localValue)
        {
            if (moves is null)
            {
                throw new ArgumentNullException(nameof(moves));
            }

            _movesInternal.AddRange(moves);
        }
        private VariationLine(EvaluationScore value, EvaluationScore?localValue)
        {
            if (value.Value.Abs() > EvaluationScore.MateValue)
            {
                throw new ArgumentOutOfRangeException(
                          nameof(value),
                          value.Value,
                          $@"The score value is out of the valid range [{-EvaluationScore.MateValue:#,##0} .. {
                        EvaluationScore.MateValue:#,##0}].");
            }

            _movesInternal = new List <GameMove>();
            Value          = value;
            LocalValue     = localValue;
            Moves          = _movesInternal.AsReadOnly();
        }
        public static int?GetMateMoveDistance(this EvaluationScore evaluationScore)
        {
            if (!evaluationScore.IsAnyMate())
            {
                return(null);
            }

            var score = evaluationScore.Value;

            var plyDistance = EvaluationScore.MateValue - score.Abs();

            if (plyDistance < 0)
            {
                throw new InvalidOperationException($@"Invalid score value: {score}.");
            }

            var mateMoveDistance = (plyDistance + 1) / 2;

            return(evaluationScore.Value > 0 ? mateMoveDistance : -mateMoveDistance);
        }
 public VariationLine(EvaluationScore value)
     : this(value, null)
 {
     // Nothing to do
 }
 public static bool IsGettingCheckmated(this EvaluationScore evaluationScore)
 {
     return(-evaluationScore.Value >= MateScoreLowerBound);
 }
 public static bool IsAnyMate(this EvaluationScore evaluationScore)
 {
     return(evaluationScore.Value.Abs() >= MateScoreLowerBound);
 }
 public static EvaluationScore Min(EvaluationScore score1, EvaluationScore score2)
 {
     return(score1.Value <= score2.Value ? score1 : score2);
 }