public static int[] GenerateOffsets(Bitboard bitboard) { int[] result = new int[Bitboards.CountBits(bitboard)]; int cnt = 0; while (bitboard != 0) { result[cnt++] = Bitboards.BitScanForward(bitboard); Bitboards.PopLsb(ref bitboard); } return(result); }
public static Bitboard[] GeneratePermutations(Bitboard occupancyBitboard) { int numBits = Bitboards.CountBits(occupancyBitboard); int numPossibilities = (int)Math.Pow(2, numBits); int[] offsets = GenerateOffsets(occupancyBitboard); Bitboard[] result = new Bitboard[numPossibilities]; for (int i = 0; i < numPossibilities; i++) { for (int bit = 0; bit < numBits; bit++) { bool bitIsSet = (i & (1 << bit)) != 0; if (bitIsSet) { result[i] |= Bitboards.SquareBitboards[offsets[bit]]; } } } return(result); }