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)); }
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)); } }
public static void InBetween_ShouldReturnCorrectValue_GivenH8A1() { var expected = 0x40201008040200; var actual = BoardHelpers.InBetween(63, 0); Assert.AreEqual(expected, actual, "Should return correct value for h8-a1"); }
public static void InBetween_ShouldReturnCorrectValue_GivenA1H8() { var expected = 0x40201008040200; var actual = BoardHelpers.InBetween(0, 63); Assert.AreEqual(expected, actual, "Should return correct value for a1-h8"); }
public static void InBetween_ShouldReturnZero_GivenTwoNSOneAnother() { var expected = (ulong)0x00; var actual = BoardHelpers.InBetween(1, 9); Assert.AreEqual(expected, actual, "Should not be any squares between squares N+S of ona another (b1-b2)"); }
public static void InBetween_ShouldReturnZero_GivenTwoEWOneAnother() { var expected = (ulong)0x00; var actual = BoardHelpers.InBetween(3, 4); Assert.AreEqual(expected, actual, "Should not be any squares between squares E+W of one another (d1-e1)"); }
public void InBetweenTest(string strFrom, string strTo, ulong expected) { var from = strFrom.ToBoardIndex(); var to = strTo.ToBoardIndex(); Assert.IsNotNull(from); Assert.IsNotNull(to); var actual = BoardHelpers.InBetween(from, to); Assert.AreEqual(expected, actual, $"{strFrom}->{strTo}"); }
public static void InBetween_ShouldReturnCorrectValue_GivenRandomPositions() { var expected = (ulong)0x00; var actual = BoardHelpers.InBetween(3, 8); Assert.AreEqual(expected, actual, $"Should not be any squares between {3.ToSquareString()}{8.ToSquareString()}"); expected = 0x200; actual = BoardHelpers.InBetween(16, 2); Assert.AreEqual(expected, actual, $"Did not return correct value for in between {16.ToSquareString()} - {2.ToSquareString()}"); expected = 0x2040800000000; actual = BoardHelpers.InBetween(28, 56); Assert.AreEqual(expected, actual, $"Did not return correct value for in between {28.ToSquareString()} - {56.ToSquareString()}"); }