Пример #1
0
        public void TestTranspositionTableBucketConstruction()
        {
            var entry1 = new TranspositionTableEntry(
                0x1234567890A,
                GameMove.FromStringNotation("a1b1"),
                EvaluationScore.Mate,
                EvaluationScore.Zero,
                ScoreBound.Exact,
                3);

            var entry2 = new TranspositionTableEntry(
                0xABCDEF9876,
                GameMove.FromStringNotation("g7g8q"),
                new EvaluationScore(1001),
                new EvaluationScore(997),
                ScoreBound.Lower,
                11);

            Assert.That(entry1.Key, Is.Not.EqualTo(entry2.Key));
            Assert.That(entry1.BestMove, Is.Not.EqualTo(entry2.BestMove));
            Assert.That(entry1.Score, Is.Not.EqualTo(entry2.Score));
            Assert.That(entry1.LocalScore, Is.Not.EqualTo(entry2.LocalScore));
            Assert.That(entry1.Bound, Is.Not.EqualTo(entry2.Bound));
            Assert.That(entry1.Depth, Is.Not.EqualTo(entry2.Depth));

            var bucket = new TranspositionTableBucket
            {
                Entry1 = entry1,
                Entry2 = entry2
            };

            Assert.That(bucket.Entry1, Is.EqualTo(entry1));
            Assert.That(bucket.Entry2, Is.EqualTo(entry2));
        }
        public void TestPerformanceOfGetMoveForQueenUnderAttack(
            int maxPlyDepth,
            [CanBeNull] string expectedBestMoveString)
        {
            const string Fen = "rn3rk1/ppp2ppb/3qp2p/8/1b2P3/2Q3P1/PPPN1PBP/R1B2RK1 w - - 5 13";

            var expectedBestMove = expectedBestMoveString is null
                ? null
                : GameMove.FromStringNotation(expectedBestMoveString);

            ExecuteTestForFenAndDepth(Fen, maxPlyDepth, expectedBestMove);
        }
        public void TestPerformanceOfGetMoveForPosition1(
            int maxPlyDepth,
            [CanBeNull] string expectedBestMoveString)
        {
            const string Fen = "r1bqkbnr/pppp1ppp/4p3/n7/4P3/3B1N2/PPPP1PPP/RNBQK2R b KQkq - 3 4";

            var expectedBestMove = expectedBestMoveString is null
                ? null
                : GameMove.FromStringNotation(expectedBestMoveString);

            ExecuteTestForFenAndDepth(Fen, maxPlyDepth, expectedBestMove);
        }
Пример #4
0
        public void TestGetStandardAlgebraicNotation(string fen, string moveNotation, string expectedResult)
        {
            var board = new GameBoard(fen);
            var move  = GameMove.FromStringNotation(moveNotation);

            var actualResult1 = board.GetStandardAlgebraicNotation(move);

            Assert.That(actualResult1, Is.EqualTo(expectedResult));

            var actualResult2 = move.ToStandardAlgebraicNotation(board);

            Assert.That(actualResult2, Is.EqualTo(expectedResult));
        }
Пример #5
0
        public void TestGetStandardAlgebraicNotationForCollection()
        {
            const string Fen   = "rnbqkbnr/pppppppp/8/8/4P3/8/PPPP1PPP/RNBQKBNR b KQkq e3 0 1";
            var          board = new GameBoard(Fen);

            var moves = new[]
            {
                GameMove.FromStringNotation("d7d5"),
                GameMove.FromStringNotation("e4d5"),
                GameMove.FromStringNotation("d8d5")
            };

            var actualResult = board.GetStandardAlgebraicNotation(moves);

            Assert.That(actualResult, Is.EqualTo("d5, exd5, Qxd5"));
        }
Пример #6
0
        public void TestFromStringNotation(
            string input,
            Square expectedFrom,
            Square expectedTo,
            PieceType expectedPromotionResult)
        {
            foreach (var useExplicitMethod in new[] { false, true })
            {
                var move = useExplicitMethod ? GameMove.FromStringNotation(input) : input;

                Assert.That(move, Is.Not.Null);
                Assert.That(move.From, Is.EqualTo(expectedFrom));
                Assert.That(move.To, Is.EqualTo(expectedTo));
                Assert.That(move.PromotionResult, Is.EqualTo(expectedPromotionResult));
            }
        }
Пример #7
0
        public void TestEquality(string firstMoveStringNotation, GameMove second, bool expectedEquals)
        {
            var first = GameMove.FromStringNotation(firstMoveStringNotation);

            Assert.That(first, Is.Not.Null);
            Assert.That(second, Is.Not.Null);

            Assert.That(first.Equals(second), Is.EqualTo(expectedEquals));
            Assert.That(second.Equals(first), Is.EqualTo(expectedEquals));
            Assert.That(Equals(first, second), Is.EqualTo(expectedEquals));
            Assert.That(EqualityComparer <GameMove> .Default.Equals(first, second), Is.EqualTo(expectedEquals));
            Assert.That(first == second, Is.EqualTo(expectedEquals));
            Assert.That(first != second, Is.EqualTo(!expectedEquals));

            if (expectedEquals)
            {
                Assert.That(first.GetHashCode(), Is.EqualTo(second.GetHashCode()));
            }
        }
Пример #8
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);
        }
Пример #9
0
        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));
        }
Пример #10
0
 public void TestFromStringNotationNegativeCases()
 {
     Assert.That(() => GameMove.FromStringNotation(null !), Throws.TypeOf <ArgumentNullException>());
     Assert.That(() => GameMove.FromStringNotation("a2a1=q"), Throws.TypeOf <ArgumentException>());
     Assert.That(() => GameMove.FromStringNotation("a2-a1Q"), Throws.TypeOf <ArgumentException>());
 }