/// <summary> /// ScoreBoundTypeの値を反転させます。 /// </summary> public static ScoreBound Flip(this ScoreBound bound) { return( bound == ScoreBound.Lower ? ScoreBound.Upper : bound == ScoreBound.Upper ? ScoreBound.Lower : ScoreBound.Exact); }
/// <summary> /// コンストラクタ /// </summary> public Score(BWType turn, int value = 0, ScoreBound bound = ScoreBound.Exact) { ScoreType = ScoreType.Value; ScoreBound = bound; Turn = turn; Value = value; }
/// <summary> /// 符号を反転します。 /// </summary> public void Neg() { if (ScoreType == ScoreType.Mate) { IsMateWin = !IsMateWin; } Value *= -1; ScoreBound = ScoreBound.Flip(); Turn = Turn.Flip(); }
/// <summary> /// ScoreBoundの値を文字列で表現する。 /// /// Chessの記法に倣う。 /// </summary> /// <param name="bound"></param> /// <returns></returns> public static string Pretty(this ScoreBound bound) { switch (bound) { case ScoreBound.Exact: return(""); case ScoreBound.Lower: return("++"); // 真の値は、この値以上のはずなので case ScoreBound.Upper: return("--"); // 真の値は、この値以下のはずなので } return("??"); }
/// <summary> /// ScoreBoundの値を文字列で表現する。 /// /// Chessの記法に倣う。 /// </summary> /// <param name="bound"></param> /// <returns></returns> public static string Pretty(this ScoreBound bound) { switch (bound) { case ScoreBound.Exact: return(""); case ScoreBound.Upper: return("++"); case ScoreBound.Lower: return("--"); } return("??"); }
private void AssertValue(string text, int value, ScoreBound bound) { var score = Score.ParseValue(text, BWType.Black); Assert.AreEqual(ScoreType.Value, score.ScoreType); Assert.AreEqual(bound, score.ScoreBound); Assert.AreEqual(value, score.Value); Assert.AreEqual(BWType.Black, score.Turn); score.Neg(); Assert.AreEqual(-value, score.Value); Assert.AreEqual(bound.Flip(), score.ScoreBound); Assert.AreEqual(BWType.White, score.Turn); score.Neg(); Assert.AreEqual(value, score.Value); Assert.AreEqual(bound, score.ScoreBound); Assert.AreEqual(BWType.Black, score.Turn); }
public void TestTranspositionTable() { var transpositionTable = new TranspositionTable(FakeLogger.Instance, TranspositionTableHelper.SizeInMegaBytesRange.Lower); Assert.That(transpositionTable.Version, Is.Not.EqualTo(0)); const long Key = 0x12345678ABCDEF01L; const long OtherKey = 0x987654321L; const ScoreBound Bound = ScoreBound.Exact; const int Depth = CommonEngineConstants.MaxPlyDepthUpperLimit; var bestMove = GameMove.FromStringNotation("b2b1q"); var score = EvaluationScore.Mate; var localScore = new EvaluationScore(-789); var entry = new TranspositionTableEntry(Key, bestMove, score, localScore, Bound, Depth); transpositionTable.Save(ref entry); Assert.That(entry.Version, Is.EqualTo(transpositionTable.Version)); Assert.That(transpositionTable.ProbeCount, Is.EqualTo(0)); Assert.That(transpositionTable.HitCount, Is.EqualTo(0)); var foundEntry1 = transpositionTable.Probe(Key); Assert.That(transpositionTable.ProbeCount, Is.EqualTo(1)); Assert.That(transpositionTable.HitCount, Is.EqualTo(1)); Assert.That(foundEntry1.HasValue, Is.True); Assert.That(foundEntry1.Value.Key, Is.EqualTo(Key)); Assert.That(foundEntry1.Value.BestMove, Is.EqualTo(bestMove)); Assert.That(foundEntry1.Value.Score, Is.EqualTo(score)); Assert.That(foundEntry1.Value.LocalScore, Is.EqualTo(localScore)); Assert.That(foundEntry1.Value.Bound, Is.EqualTo(Bound)); Assert.That(foundEntry1.Value.Depth, Is.EqualTo(Depth)); Assert.That(foundEntry1.Value.Version, Is.EqualTo(transpositionTable.Version)); var foundEntry2 = transpositionTable.Probe(OtherKey); Assert.That(transpositionTable.ProbeCount, Is.EqualTo(2)); Assert.That(transpositionTable.HitCount, Is.EqualTo(1)); Assert.That(foundEntry2.HasValue, Is.False); }
public void TestTranspositionTableEntryConstruction() { const long Key = 0x12345678ABCDEF01L; const ScoreBound Bound = ScoreBound.Exact; const int Depth = CommonEngineConstants.MaxPlyDepthUpperLimit; var bestMove = GameMove.FromStringNotation("b2b1q"); var score = EvaluationScore.Mate; var localScore = new EvaluationScore(-789); var entry = new TranspositionTableEntry(Key, bestMove, score, localScore, Bound, Depth); Assert.That(entry.Key, Is.EqualTo(Key)); Assert.That(entry.BestMove, Is.EqualTo(bestMove)); Assert.That(entry.Score, Is.EqualTo(score)); Assert.That(entry.LocalScore, Is.EqualTo(localScore)); Assert.That(entry.Bound, Is.EqualTo(Bound)); Assert.That(entry.Depth, Is.EqualTo(Depth)); Assert.That(entry.Version, Is.EqualTo(0)); }
/// <summary> /// 通常の評価値をパースします。 /// </summary> /// <example> /// 0 /// -98 /// +456↑ /// </example> public static Score ParseValue(string text, BWType turn, ScoreBound bound = ScoreBound.Exact) { if (string.IsNullOrEmpty(text)) { throw new ArgumentNullException("text"); } var trimmedText = text.Trim(); var value = StringToInt(trimmedText); // 評価値の最後に↑や↓があれば評価値タイプを上書き var last = trimmedText.LastOrDefault(); bound = ( last == '↑' ? ScoreBound.Lower : last == '↓' ? ScoreBound.Upper : bound); return(new Score(turn, value, bound)); }
public TranspositionTableEntry( long key, [CanBeNull] GameMove bestMove, EvaluationScore score, EvaluationScore localScore, ScoreBound bound, int depth) { Key = key; _bestMoveEncoded = (ushort)(bestMove is null ? 0 : (bestMove.From.SquareIndex & ChessConstants.MaxSquareIndex) << 9 | (bestMove.To.SquareIndex & ChessConstants.MaxSquareIndex) << 3 | (int)bestMove.PromotionResult & 0x7); _scoreValue = score.Value; _localScoreValue = localScore.Value; Bound = bound; Depth = depth; Version = 0; }
public EvalValueEx(EvalValue eval, ScoreBound bound) { Eval = eval; Bound = bound; }