private static bool IsPawnInStartingPosition(ushort squareIndex, Color color) { var bv = MovingPieceService.GetBoardValueOfIndex(squareIndex); var secondRankMask = MovingPieceService.GetPawnStartRankMask(color); return((bv & secondRankMask) != 0); }
private static ulong GetAllCapturesFromSquare(ushort squareIndex, Color color) { var shiftNE = GetRelativeNEShift(color); var shiftNW = GetRelativeNWShift(color); var squareValue = MovingPieceService.GetBoardValueOfIndex(squareIndex); return(shiftNE(squareValue) | shiftNW(squareValue)); }
private static ulong GetPawnShift(ushort squareIndex, Color color) { var startingRank = MovingPieceService.GetPawnStartRankMask(color); var squareValue = MovingPieceService.GetBoardValueOfIndex(squareIndex); var shift1XMethod = GetShift(color); var shift2XMethod = GetDoubleShift(color); return(((startingRank & squareValue) != 0 ? shift2XMethod(squareValue) : 0) | shift1XMethod(squareValue)); }
private void InitializeWhitePawnMovesAndAttacks() { for (ushort square = 0; square < 64; square++) { var squareValue = MovingPieceService.GetBoardValueOfIndex(square); MoveMask[(int)Color.White][square] = MovingPieceService.ShiftN(squareValue) | ((squareValue & BoardConstants.Rank2) << 16); AttackMask[(int)Color.White][square] = MovingPieceService.ShiftNW(squareValue) | MovingPieceService.ShiftNE(squareValue); } }
private void InitializeBlackPawnMovesAndAttacks() { foreach (var square in BoardConstants.AllSquares) { var squareValue = MovingPieceService.GetBoardValueOfIndex(square); MoveMask[(int)Color.Black][square] = MovingPieceService.ShiftS(squareValue) | ((squareValue & BoardConstants.Rank7) >> 16); AttackMask[(int)Color.Black][square] = MovingPieceService.ShiftSW(squareValue) | MovingPieceService.ShiftSE(squareValue); } }
internal ulong GetMoves(ushort square) { var squareValue = MovingPieceService.GetBoardValueOfIndex(square); ulong squares = 0; foreach (var shift in _knightDirectionMethods) { squares |= shift(squareValue); } return(squares); }
public void RookMovesShouldBeInitialized(ushort squareIndex) { var rank = MovingPieceService.RankFromIdx(squareIndex); var file = MovingPieceService.FileFromIdx(squareIndex); var rankFill = (ulong)0xff << (rank * 8); var fileFill = (ulong)0x101010101010101 << file; var boardVal = MovingPieceService.GetBoardValueOfIndex(squareIndex); var mask = (rankFill | fileFill) ^ boardVal; var actual = BitBoard.GetPseudoLegalMoves(squareIndex, Piece.Rook, Color.Black, 0); Assert.AreEqual(mask, actual); }
private ulong GetMoves(ushort square, ulong occupancy) { ulong result = 0; var squareValue = MovingPieceService.GetBoardValueOfIndex(square); foreach (var shiftDirection in MoveShifts) { if (shiftDirection == null) { continue; } result |= Traverse(shiftDirection, squareValue, occupancy); } return(result); }
private static MoveObstructionBoard GetMovesFromObstructions(Color color, ulong obstructions, ushort squareIndex) { ulong moves = 0; var sqValue = MovingPieceService.GetBoardValueOfIndex(squareIndex); var shiftN = GetShift(color)(sqValue); var shiftDoubleN = IsStartingRank(color, squareIndex) ? GetDoubleShift(color)(sqValue) : (ulong?)null; var attacks = GetAllCapturesFromSquare(squareIndex, color); if ((shiftN & obstructions) == 0) { moves |= shiftN; if (shiftDoubleN.HasValue && (shiftDoubleN.Value & obstructions) == 0) { moves |= shiftDoubleN.Value; } } moves |= attacks & obstructions; return(new MoveObstructionBoard(obstructions, moves)); }