예제 #1
0
 private static void Co3() // Bishop magics
 {
     bTables = new ulong[64][];
     bMasks  = new ulong[64];
     for (int sq = 0; sq < 64; sq++)
     {
         int x = Position.getX(sq);
         int y = Position.getY(sq);
         bMasks[sq] = addBishopRays(x, y, 0L, true);
         int     tableSize = 1 << bBits[sq];
         ulong[] table     = new ulong[tableSize];
         for (int i = 0; i < tableSize; i++)
         {
             table[i] = Defs.ulongN1;                                /* -1 */
         }
         int nPatterns = 1 << BITS.bitCount(bMasks[sq]);
         for (int i = 0; i < nPatterns; i++)
         {
             ulong p     = createPattern(i, bMasks[sq]);
             int   entry = (int)((p * bMagics[sq]) >> (64 - bBits[sq]));
             ulong atks  = addBishopRays(x, y, p, false);
             if (table[entry] == Defs.ulongN1 /* -1 */)
             {
                 table[entry] = atks;
             }
             else if (table[entry] != atks)
             {
                 throw new RuntimeException();
             }
         }
         bTables[sq] = table;
     }
 }
예제 #2
0
 public static int numberOfTrailingZeros(ulong mask)
 {
     return(trailingZ[(int)(((mask & BITS.Neg(mask) /* -mask */) * 0x07EDD5E59A4E28C2L) >> 58)]);
 }