コード例 #1
0
        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);
        }
コード例 #2
0
        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);
        }