private static void AddPawnMoves(this IPosition pos, MoveList moves, BitBoard targetSquares, Direction direction, EMoveType type, Emgf flags) { if (targetSquares.Empty()) { return; } var stm = pos.State.SideToMove; var piece = EPieceType.Pawn.MakePiece(stm); var promotionRank = stm.PromotionRank(); var promotionSquares = targetSquares & promotionRank; var nonPromotionSquares = targetSquares & ~promotionRank; while (nonPromotionSquares) { var to = nonPromotionSquares.Lsb(); var from = to - direction; pos.AddMove(moves, piece, from, to, PieceExtensions.EmptyPiece, flags, type); BitBoards.ResetLsb(ref nonPromotionSquares); } type |= EMoveType.Promotion; if (flags.HasFlagFast(Emgf.Queenpromotion)) { var sqTo = promotionSquares.Lsb(); var sqFrom = sqTo - direction; pos.AddMove(moves, piece, sqFrom, sqTo, EPieceType.Queen.MakePiece(stm), flags, type); BitBoards.ResetLsb(ref promotionSquares); } else { while (promotionSquares) { var sqTo = promotionSquares.Lsb(); var sqFrom = sqTo - direction; for (var promotedPiece = EPieceType.Queen; promotedPiece >= EPieceType.Knight; promotedPiece--) { pos.AddMove(moves, piece, sqFrom, sqTo, promotedPiece.MakePiece(stm), flags, type); } BitBoards.ResetLsb(ref promotionSquares); } } }
private static void AddMoves(this IPosition pos, MoveList moves, Piece piece, Square from, BitBoard attacks, Emgf flags) { var target = pos.Pieces(~pos.State.SideToMove) & attacks; while (target) { var to = target.Lsb(); pos.AddMove(moves, piece, from, to, PieceExtensions.EmptyPiece, flags, EMoveType.Capture); BitBoards.ResetLsb(ref target); } target = ~pos.Pieces() & attacks; while (target) { var to = target.Lsb(); pos.AddMove(moves, piece, from, to, PieceExtensions.EmptyPiece, flags); BitBoards.ResetLsb(ref target); } }
private static void AddCastleMove(this IPosition pos, MoveList moves, Square from, Square to, Emgf flags) => pos.AddMove(moves, EPieceType.King.MakePiece(pos.State.SideToMove), from, to, PieceExtensions.EmptyPiece, flags, EMoveType.Castle);