Exemplo n.º 1
0
        public void GetMoves_SingleJumpAndMakeKingSequence()
        {
            var board = new SquareBoard(3);

            board.Set(Figure.CreateSimple(2, 2, Side.Black));
            board.Set(Figure.CreateSimple(1, 1, Side.Red));
            testOutput.WriteLine(board.ToString());

            var subject = GetSubject();
            var moves   = subject.GetMoves(board, Side.Black);

            var move             = moves[Figure.CreateSimple(2, 2, Side.Black)].Single();
            var expectedSequence = new MoveSequence(MoveStep.Jump(0, 0), MoveStep.King());

            Assert.Equal(expectedSequence, move);
        }
Exemplo n.º 2
0
        public void GetMoves_PresetBoard_SimpleShouldStopWhenPromoted()
        {
            var board = Board6x6Preset1();

            testOutput.WriteLine(board.ToString());

            var subject = GetSubject();
            var moves   = subject.GetMoves(board, Side.Black);

            var simpleMoves             = moves[Figure.CreateSimple(4, 6, Side.Black)];
            var jumpUntilPromotedToKing = new MoveSequence(
                MoveStep.Jump(2, 4),
                MoveStep.Jump(0, 2),
                MoveStep.King());

            Assert.Contains(jumpUntilPromotedToKing, simpleMoves);
        }
Exemplo n.º 3
0
        public void GetMoves_PresetBoard_KingCanJumpBack()
        {
            var board = Board6x6Preset1();

            testOutput.WriteLine(board.ToString());

            var subject = GetSubject();
            var moves   = subject.GetMoves(board, Side.Black);

            var kingMoves            = moves[Figure.CreateKing(2, 0, Side.Black)];
            var expectedKingSequence = new MoveSequence(
                MoveStep.Jump(0, 2),
                MoveStep.Jump(2, 4),
                MoveStep.Jump(0, 6));

            Assert.Equal(expectedKingSequence, kingMoves.Single());
        }
Exemplo n.º 4
0
        public void GetMoves_SingleJumpMoveForward()
        {
            var figure = Figure.CreateSimple(3, 3, Side.Black);
            var board  = new SquareBoard(4);

            board.Set(figure);
            board.Set(Figure.CreateSimple(2, 2, Side.Red));
            testOutput.WriteLine(board.ToString());

            var subject = GetSubject();
            var moves   = subject.GetMoves(board, Side.Black);

            var figureMoves = Assert.Contains(figure, moves);
            var move        = Assert.Single(figureMoves);
            var step        = Assert.Single(move);

            Assert.Equal(MoveStep.Jump(Point.At(1, 1)), step);
        }
Exemplo n.º 5
0
        public void FindBestMove_ChooseToStrikeKing()
        {
            /*     0 1 2 3 4
            *    0 . . . . .
            *    1 . r . R .   Simple and King
            *    2 . . . . .
            *    3 . r . . .
            *    4 b . . . .   */
            var board = new SquareBoard(5);

            board.Set(Figure.CreateSimple(1, 1, Side.Red));
            board.Set(Figure.CreateKing(1, 3, Side.Red));
            board.Set(Figure.CreateSimple(3, 1, Side.Red));
            board.Set(Figure.CreateSimple(4, 0, Side.Black));

            var subject = GetSubject();
            var move    = subject.FindBestMove(board, Side.Black, CancellationToken.None, Options(maxDepth: 2));

            Assert.Equal(Figure.CreateSimple(4, 0, Side.Black), move.Figure);
            Assert.Equal(new MoveSequence(MoveStep.Jump(2, 2), MoveStep.Jump(0, 4), MoveStep.King()), move.Sequence);
        }
Exemplo n.º 6
0
        public void FindBestMove_SingleMoveExists_FastPathWithNoEvaluation()
        {
            /*    0 1 2 3 4
             *  0 . . . . .
             *  1 . R . . .
             *  2 . . B . B
             *  3 . . . . .
             *  4 . . . . .   */
            var board = new SquareBoard(5);

            board.Set(Figure.CreateKing(2, 2, Side.Black));
            board.Set(Figure.CreateKing(2, 4, Side.Black));
            board.Set(Figure.CreateKing(1, 1, Side.Red));

            var subject = GetSubject();
            var options = Options(maxParallel: 2, maxDepth: 3);

            var move = subject.FindBestMove(board, Side.Black, CancellationToken.None, options);

            Assert.Equal(0, subject.TotalMovesEstimated);
            Assert.Equal(Point.At(2, 2), move.Figure.Point);
            Assert.Equal(new MoveSequence(MoveStep.Jump(0, 0)), move.Sequence);
        }
Exemplo n.º 7
0
        public void GetMoves_PresetBoard_SimpleHasSeveralJumpBranches()
        {
            var board = Board6x6Preset1();

            testOutput.WriteLine(board.ToString());

            var subject = GetSubject();
            var moves   = subject.GetMoves(board, Side.Black);

            var simpleMoves             = moves[Figure.CreateSimple(4, 6, Side.Black)];
            var expectedSimpleSequence1 = new MoveSequence(
                MoveStep.Jump(2, 4),
                MoveStep.Jump(0, 2),
                MoveStep.King());
            var expectedSimpleSequence2 = new MoveSequence(
                MoveStep.Jump(2, 4),
                MoveStep.Jump(0, 6),
                MoveStep.King());

            Assert.Collection(simpleMoves,
                              (x) => Assert.Equal(expectedSimpleSequence1, x),
                              (x) => Assert.Equal(expectedSimpleSequence2, x));
        }