private static bool isOwnKingAttackable(ChessBoard cb, ColoredBitBoard legalMove, ChessPieceColors color) { List <ColoredBitBoard> legalMoves = new List <ColoredBitBoard>(); EmptyBitBoard blackPieces = new EmptyBitBoard(); EmptyBitBoard whitePieces = new EmptyBitBoard(); EmptyBitBoard allPieces = new EmptyBitBoard(); cb.Update(legalMove); blackPieces = MoveGenUtils.SetBlackBoard(cb); whitePieces = MoveGenUtils.SetWhiteBoard(cb); allPieces = MoveGenUtils.SetWholeBoard(cb); legalMoves.AddRange(GeneratePseudoLegalNonSlidingMoves(cb, color, blackPieces, whitePieces, allPieces)); legalMoves.AddRange(GeneratePseudoLegalSlidingMoves(cb, color, blackPieces, whitePieces, allPieces)); foreach (ColoredBitBoard cbb in legalMoves) { if (color == ChessPieceColors.White && (cb.BlackKing.Bits & cbb.Bits) != 0) { cb.Undo(); return(true); } else if (color == ChessPieceColors.Black && (cb.WhiteKing.Bits & cbb.Bits) != 0) { cb.Undo(); return(true); } } cb.Undo(); return(false); }
private static bool isEnemyKingAttackable(ChessBoard cb, ColoredBitBoard legalMove, ChessPieceColors color) { List <ColoredBitBoard> legalMoves = new List <ColoredBitBoard>(); EmptyBitBoard blackPieces = new EmptyBitBoard(); EmptyBitBoard whitePieces = new EmptyBitBoard(); EmptyBitBoard allPieces = new EmptyBitBoard(); cb.Update(legalMove); blackPieces = MoveGenUtils.SetBlackBoard(cb); whitePieces = MoveGenUtils.SetWhiteBoard(cb); allPieces = MoveGenUtils.SetWholeBoard(cb); if (legalMove is PawnBitBoard) { legalMoves.AddRange(PawnMoveGen.PawnBitBoardResults(cb, color, blackPieces, whitePieces, allPieces)); } else if (legalMove is BishopBitBoard) { legalMoves.AddRange(BishopMoveGen.BishopBitBoardResults(cb, color, blackPieces, whitePieces, allPieces)); } else if (legalMove is KingBitBoard) { legalMoves.AddRange(KingMoveGen.KingBitBoardResults(cb, color, blackPieces, whitePieces, allPieces)); } else if (legalMove is KnightBitBoard) { legalMoves.AddRange(KnightMoveGen.KnightBitBoardResults(cb, color, blackPieces, whitePieces, allPieces)); } else if (legalMove is QueenBitBoard) { legalMoves.AddRange(QueenMoveGen.QueenBitBoardResults(cb, color, blackPieces, whitePieces, allPieces)); } else if (legalMove is RookBitBoard) { legalMoves.AddRange(RookMoveGen.RookBitBoardResults(cb, color, blackPieces, whitePieces, allPieces)); } foreach (ColoredBitBoard cbb in legalMoves) { if (color == ChessPieceColors.White && (cb.BlackKing.Bits & cbb.Bits) != 0) { cb.Undo(); return(true); } else if (color == ChessPieceColors.Black && (cb.WhiteKing.Bits & cbb.Bits) != 0) { cb.Undo(); return(true); } } cb.Undo(); return(false); }
public static List <ColoredBitBoard> GenerateLegalMoves(ChessBoard inputChessBoard, ChessPieceColors color) { List <ColoredBitBoard> result = new List <ColoredBitBoard>(); EmptyBitBoard blackPieces = MoveGenUtils.SetBlackBoard(inputChessBoard); EmptyBitBoard whitePieces = MoveGenUtils.SetWhiteBoard(inputChessBoard); EmptyBitBoard allPieces = MoveGenUtils.SetWholeBoard(inputChessBoard); result.AddRange(GeneratePseudoLegalNonSlidingMoves(inputChessBoard, color, blackPieces, whitePieces, allPieces)); result.AddRange(GeneratePseudoLegalSlidingMoves(inputChessBoard, color, blackPieces, whitePieces, allPieces)); result = RemoveOwnKingChecks(inputChessBoard, result, color); result = SetDoesCheck(inputChessBoard, result, color); var sortedMoves = MoveGenUtils.SortMoves(result, inputChessBoard, blackPieces, whitePieces); return(sortedMoves); }
public static List <ColoredBitBoard> SortMovesByCapturing(List <ColoredBitBoard> legalMoves, ChessBoard inputChessBoard, BitBoard blackMoves, BitBoard whiteMoves) { List <ColoredBitBoard> capturing = new List <ColoredBitBoard>(); List <ColoredBitBoard> nonCapturing = new List <ColoredBitBoard>(); List <ColoredBitBoard> result = new List <ColoredBitBoard>(); //Sets the IsCapturing flag on all moves that is a capturing move SetIsCapturing(legalMoves, blackMoves, whiteMoves); foreach (ColoredBitBoard cbb in legalMoves) { if (cbb.IsCapturing) { capturing.Add(cbb); } else { nonCapturing.Add(cbb); } } result.AddRange(MoveGenUtils.SortCapturingMoves(capturing, inputChessBoard)); result.AddRange(nonCapturing); return(result); }