public static IEnumerable <TestCaseData> GetCastlingMoves(Color color, Move move)
        {
            const string emptyFenWhiteToMove    = "4k3/8/8/8/8/8/8/4K3 w - - 0 1";
            const string emptyFenBlackToMove    = "4k3/8/8/8/8/8/8/4K3 b - - 0 1";
            var          rookInitialSquareIndex = MoveHelpers.GetRookMoveForCastleMove(move).SourceIndex;
            var          between             = BoardHelpers.InBetween(rookInitialSquareIndex, move.SourceIndex);
            var          blockerPermutations = MovingPieceService.GetAllPermutationsOfSetBits(between.GetSetBits(), 0, 0)
                                               .Where(x => x != 0);
            var fen   = color == Color.Black ? emptyFenBlackToMove : emptyFenWhiteToMove;
            var board = fenTextToBoard.Translate(fen);

            foreach (var permutation in blockerPermutations)
            {
                var editedBoard = (Board)board.Clone();
                editedBoard.Occupancy[(int)color][(int)Piece.King] = permutation;
                var strBlockers = string.Join(", ", permutation.GetSetBits());
                yield return(new TestCaseData(editedBoard, move)
                             .SetName($"Blockers on indices {strBlockers}")
                             .Returns(MoveError.CastleOccupancyBetween));
            }

            yield return(new TestCaseData(board, move)
                         .SetName("No Blockers")
                         .Returns(MoveError.NoneSet));
        }
Exemplo n.º 2
0
        private static IEnumerable <TestCaseData> SetupPathSquareValidation(Board board, Move castlingMove)
        {
            var totalOccupancy  = board.Occupancy.Occupancy();
            var enPassantSquare = board.EnPassantIndex;

            var inBetweenSquares = BoardHelpers.InBetween(castlingMove.SourceIndex, castlingMove.DestinationIndex) |
                                   castlingMove.DestinationValue;
            var inBetweenSquareArr = inBetweenSquares.GetSetBits().ToArray();
            var permutations       =
                MovingPieceService.GetAllPermutationsOfSetBits(inBetweenSquareArr, 0, 0)
                .Distinct()
                .ToList();

            TestContext.WriteLine(permutations);
            TestContext.WriteLine("----------------------------------------");
            foreach (var attackedSquaresValue in permutations)
            {
                var bb = new Mock <IBitboard>();
                var attackedSquares = attackedSquaresValue.GetSetBits();

                foreach (var squareBetween in inBetweenSquareArr)
                {
                    var isAttacked = attackedSquares.Contains(squareBetween);
                    SetupMock(board, squareBetween, totalOccupancy, enPassantSquare, bb, isAttacked);
                }

                var strBlockers = attackedSquares.Any() ? string.Join(", ", attackedSquares) : "[None]";
                TestContext.WriteLine($"Returning test case for {attackedSquaresValue}");
                var expectedReturnValue = attackedSquares.Any() ? MoveError.CastleThroughCheck : MoveError.NoneSet;
                yield return(new TestCaseData(bb, board, castlingMove)
                             .SetName($"Indices Attacked: {strBlockers}")
                             .Returns(expectedReturnValue));
            }
        }
Exemplo n.º 3
0
        protected static IEnumerable <TestCase <CastlingAvailability, CastlingAvailability> > GetCastlingAbilityTestCases()
        {
            var max = 15ul;

            var permutations      = MovingPieceService.GetAllPermutationsOfSetBits(max.GetSetBits(), 0, 0);
            var castlingCartesian = permutations.Distinct()
                                    .Select(x => (CastlingAvailability)x)
                                    .Select(x =>
                                            new TestCase <CastlingAvailability, CastlingAvailability>(x,
                                                                                                      x, $"{FENHelpers.MakeCastlingAvailabilityStringFromBitFlags(x)}")).ToArray();

            return(castlingCartesian);
        }
Exemplo n.º 4
0
        private static IEnumerable <MoveTestCase> GetTestCases(Color color, ushort squareIndex)
        {
            var moveSet      = GetPawnShift(squareIndex, color);
            var setSquares   = MovingPieceService.GetSetBits(moveSet);
            var permutations = MovingPieceService.GetAllPermutationsOfSetBits(setSquares, 0, 0);
            var testCases    = new List <MoveTestCase>();

            foreach (var block in permutations)
            {
                var obstructionBoards = GetMovesFromObstructions(color, block, squareIndex);

                testCases.Add(new MoveTestCase(squareIndex, color, 0, obstructionBoards.Occupancy,
                                               obstructionBoards.MoveBoard));
            }

            return(testCases);
        }