Пример #1
0
        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);
        }