bool Search::checkInsufficientMaterial(int N_PIECE) { //regexp: KN?B*KB* if (N_PIECE > 6) { return false; } // KK if (N_PIECE == 2) { return true; } if (!chessboard[PAWN_BLACK] && !chessboard[PAWN_WHITE] && !chessboard[ROOK_BLACK] && !chessboard[ROOK_WHITE] && !chessboard[QUEEN_WHITE] && !chessboard[QUEEN_BLACK]) { u64 allBishop = chessboard[BISHOP_BLACK] | chessboard[BISHOP_WHITE]; u64 allKnight = chessboard[KNIGHT_BLACK] | chessboard[KNIGHT_WHITE]; if (allBishop || allKnight) { //insufficient material to mate if (!allKnight) { //regexp: KB+KB* if ((bitCount(allBishop) == 1) || ((allBishop & BLACK_SQUARES) == allBishop || (allBishop & WHITE_SQUARES) == allBishop)) { return true; } } else { //KNKN* if (!allBishop && bitCount(allKnight) < 3) { return true; } } } } return false; }
int Search::search(bool smp, int depth, int alpha, int beta) { ASSERT_RANGE(depth, 0, MAX_PLY); if (smp) { return getSide() ? search<WHITE, SMP_YES>(depth, alpha, beta, &pvLine, bitCount(getBitmap<WHITE>() | getBitmap<BLACK>()), &mainMateIn) : search<BLACK, SMP_YES>(depth, alpha, beta, &pvLine, bitCount(getBitmap<WHITE>() | getBitmap<BLACK>()), &mainMateIn); } else { return getSide() ? search<WHITE, SMP_NO>(depth, alpha, beta, &pvLine, bitCount(getBitmap<WHITE>() | getBitmap<BLACK>()), &mainMateIn) : search<BLACK, SMP_NO>(depth, alpha, beta, &pvLine, bitCount(getBitmap<WHITE>() | getBitmap<BLACK>()), &mainMateIn); } }
// ASSUMES piece placement routines set bitboard correctly boardErr_t testValidBoard(board_t *b) { int wKingOffset; int bKingOffset; bool_t inCheck; // LEVEL 0: Positions which make an illegal and unplayable board // Verify exactly one king per side... if(bitCount(b->colors[WHITE] & b->pieces[KING]) != 1) return ERR_BAD_WHITE_KING_COUNT; if(bitCount(b->colors[BLACK] & b->pieces[KING]) != 1) return ERR_BAD_BLACK_KING_COUNT; // Verify kings are not in contact with eachother wKingOffset = 63 - getLSBindex(b->colors[WHITE] & b->pieces[KING]); bKingOffset = 63 - getLSBindex(b->colors[BLACK] & b->pieces[KING]); if( (kingCoverage[wKingOffset] & squareMask[bKingOffset]) != 0) return ERR_OPPOSING_KINGS; // Verify side NOT to move is NOT check (i.e. king is not capturable) if(b->toMove == WHITE) { b->toMove = BLACK; inCheck = testInCheck(b); b->toMove = WHITE; } else { b->toMove = WHITE; inCheck = testInCheck(b); b->toMove = BLACK; } if(inCheck == TRUE) return ERR_OPP_ALREADY_IN_CHECK; // Verify no pawns on first or last rank if( (b->pieces[PAWN] & (rowMask[0] | rowMask[7]) ) != 0 ) return ERR_BAD_PAWN_POSITION; // LEVEL 1: Positions which create impossible combinations of pieces... // Verify max 16 pieces per side... if( bitCount(b->colors[WHITE]) > 16) return ERR_TOO_MANY_WHITE_PIECES; if( bitCount(b->colors[BLACK]) > 16) return ERR_TOO_MANY_BLACK_PIECES; // Verify piece mix for each side is obtainable through pawn promotions // (1) Determine number of missing pawns for a given side // (2) Verify "extra" pieces do not exceed (1) // LEVEL 2: Positions that are unreachable through normal play from starting position // Verify Doubled pawns accounted for by missings pieces (i.e. capture required to do this) return BRD_NO_ERROR; }
static void compareSolveNToSolve1(u64 mover, u64 enemy, int sq) { int result1 = solve1(mover, enemy, sq); const int resultN = solveNValue(-64, 64, mover, enemy); if (result1!=resultN) { printBoard(mover, enemy); std::cout << "black to move\n"; std::cout << " Black: " << bitCount(mover) << " White: " << bitCount(enemy) << " Empty: " << bitCount(~(mover|enemy)) << "\n"; solveNValue(-64, 64, mover, enemy); } assertEquals(result1, resultN); }
// public bool IPAddress::inSubnetWithMask(const IPAddress& subnet, ByteRange mask) const { auto mkByteArray4 = [&]() -> ByteArray4 { ByteArray4 ba{{0}}; std::memcpy(ba.data(), mask.begin(), std::min<size_t>(mask.size(), 4)); return ba; }; if (bitCount() == subnet.bitCount()) { if (isV4()) { return asV4().inSubnetWithMask(subnet.asV4(), mkByteArray4()); } else { ByteArray16 ba{{0}}; std::memcpy(ba.data(), mask.begin(), std::min<size_t>(mask.size(), 16)); return asV6().inSubnetWithMask(subnet.asV6(), ba); } } // an IPv4 address can never belong in a IPv6 subnet unless the IPv6 is a 6to4 // address and vice-versa if (isV6()) { const IPAddressV6& v6addr = asV6(); const IPAddressV4& v4subnet = subnet.asV4(); if (v6addr.is6To4()) { return v6addr.getIPv4For6To4().inSubnetWithMask(v4subnet, mkByteArray4()); } } else if (subnet.isV6()) { const IPAddressV6& v6subnet = subnet.asV6(); const IPAddressV4& v4addr = asV4(); if (v6subnet.is6To4()) { return v4addr.inSubnetWithMask(v6subnet.getIPv4For6To4(), mkByteArray4()); } } return false; }
// public bool IPAddress::inSubnet(const IPAddress& subnet, uint8_t cidr) const { if (bitCount() == subnet.bitCount()) { if (isV4()) { return asV4().inSubnet(subnet.asV4(), cidr); } else { return asV6().inSubnet(subnet.asV6(), cidr); } } // an IPv4 address can never belong in a IPv6 subnet unless the IPv6 is a 6to4 // address and vice-versa if (isV6()) { const IPAddressV6& v6addr = asV6(); const IPAddressV4& v4subnet = subnet.asV4(); if (v6addr.is6To4()) { return v6addr.getIPv4For6To4().inSubnet(v4subnet, cidr); } } else if (subnet.isV6()) { const IPAddressV6& v6subnet = subnet.asV6(); const IPAddressV4& v4addr = asV4(); if (v6subnet.is6To4()) { return v4addr.inSubnet(v6subnet.getIPv4For6To4(), cidr); } } return false; }
// protected const ByteArray4 IPAddressV4::fetchMask(size_t numBits) { static const uint8_t bits = bitCount(); if (numBits > bits) { throw IPAddressFormatException("IPv4 addresses are 32 bits"); } // masks_ is backed by an array so is zero indexed return masks_[numBits]; }
size_t BitVector::bitCountSlow() const { ASSERT(!isInline()); const OutOfLineBits* bits = outOfLineBits(); size_t result = 0; for (unsigned i = bits->numWords(); i--;) result += bitCount(bits->bits()[i]); return result; }
// public IPAddressV4 IPAddressV4::mask(size_t numBits) const { static const auto bits = bitCount(); if (numBits > bits) { throw IPAddressFormatException("numBits(", numBits, ") > bitsCount(", bits, ")"); } ByteArray4 ba = detail::Bytes::mask(fetchMask(numBits), addr_.bytes_); return IPAddressV4(ba); }
int main() { int num; printf("Enter a number: "); scanf("%d", &num); printf("Number of bits for representing %d is: %d", num, bitCount(num)); return 0; }
static void testLastFlipCounts(int sq, u64 mover) { mover &= ~mask(sq); const u64 enemy = ~(mover | mask(sq)); int expected = lastFlipCount(sq, mover); u64 flip = flips(sq, mover, enemy); u64 actual = bitCount(flip); if (actual!=expected) { std::cout << "lastFlipCount error\n"; std::cout << "lastFlipCount : " << expected << "\n"; std::cout << "flips : (" << bitCount(flip) << ")\n"; printBitBoard(flip); std::cout << "\nboard : (* to move)\n"; printBoard(mover, enemy); std::cout << "\n"; std::cout << "enemy : " << asHex(enemy) << "\n"; std::cout << "square : " << squareText(sq) << " (" << sq << ")" << std::endl; } assertHexEquals(expected, actual); }
int main() { printf("Test with main.\n"); printf("bitAnd Result: %d\n", bitAnd(15,3)); printf("getByte Result: %d \n",getByte(0x12345678,22)); printf("bitcount Result: %d \n", bitCount(1)); printf("bang result is: %d \n", bang(3)); printf("minimum two's complement integer is: %d \n",tmin()); printf("fitbits result is: %d \n",fitsBits(-4,3)); printf("divpwr2 result is: %d \n",divpwr2(-33,4)); printf("negate result is: %d \n",negate(4)); printf("isPositive result is: %d \n",isPositive(-4)); printf("isLessOrEqual result is: %d \n",isLessOrEqual(5,5)); printf("float_neg result is: %d \n",float_neg(13)); printf("float_i2f result is: %d \n",float_i2f(15)); printf("float_twice result is: %d \n",float_twice(9.84)); }
/*********************************************************** Given an s-simplex (with s+1 vertexes) in n dimensions, calculate the vertexes of the kth (0 <= k < (1<<s)) subsimplex in the recursive subdivision of the simplex. Several implementations of the bitCount() function are described in "Of Integers, Fields, and Bit Counting", Paeth and Schilling, Graphics Gems II. Entry: src_vtx - list of the vertexes of the original simplex n - each n consecutive floats represents one vertex s - there are s+1 vertexes in the s-simplex k - identifies which subsimplex is to be generated Exit: dst_vtx - list of the vertexes of the kth subsimplex ***********************************************************/ void rec_subsimplex(register float* dst_vtx, const float* const src_vtx, int n, int s, int k) { int id[2]; id[1] = n*bitCount(k); id[0] = -id[1]; for (int j = 0; j <= s; ++j) { for (int i = 0; i < n; ++i) *dst_vtx++ = (src_vtx[i-id[0]] + src_vtx[i+id[1]]) / 2.0; id[ (k&1)] += n; k >>= 1; } }
static void buildBitLookUp(const short *quantSpectrum, const int maxSfb, const int *sfbOffset, const unsigned short *sfbMax, int bitLookUp[MAX_SFB_LONG][CODE_BOOK_ESC_NDX + 1], SECTION_INFO * section) { int i; COUNT_sub_start("buildBitLookUp"); PTR_INIT(4); /* pointers for section[], sfbOffset[], sfbMax[], bitLookUp[] */ LOOP(1); for (i = 0; i < maxSfb; i++) { int sfbWidth, maxVal; MOVE(4); section[i].sfbCnt = 1; section[i].sfbStart = i; section[i].sectionBits = INVALID_BITCOUNT; section[i].codeBook = -1; ADD(1); sfbWidth = sfbOffset[i + 1] - sfbOffset[i]; MOVE(1); maxVal = sfbMax[i]; PTR_INIT(1); FUNC(4); bitCount(quantSpectrum + sfbOffset[i], sfbWidth, maxVal, bitLookUp[i]); } COUNT_sub_end(); }
/***************************************************************************** * * function name: buildBitLookUp * description: count bits using all possible tables * *****************************************************************************/ static void buildBitLookUp(const Word16 *quantSpectrum, const Word16 maxSfb, const Word16 *sfbOffset, const UWord16 *sfbMax, Word16 bitLookUp[MAX_SFB_LONG][CODE_BOOK_ESC_NDX + 1], SECTION_INFO * sectionInfo) { Word32 i; for (i=0; i<maxSfb; i++) { Word16 sfbWidth, maxVal; sectionInfo[i].sfbCnt = 1; sectionInfo[i].sfbStart = i; sectionInfo[i].sectionBits = INVALID_BITCOUNT; sectionInfo[i].codeBook = -1; sfbWidth = sfbOffset[i + 1] - sfbOffset[i]; maxVal = sfbMax[i]; bitCount(quantSpectrum + sfbOffset[i], sfbWidth, maxVal, bitLookUp[i]); } }
void ShGcInt::reveal(span<u64> pIdxs) { ShGc::OutputItem out; out.mLabels.reset(new std::vector<block>(bitCount())); if (std::find(pIdxs.begin(), pIdxs.end(), mRt.mPartyIdx) != pIdxs.end()) { out.mOutputProm.reset(new std::promise<BitVector>()); mFutr = out.mOutputProm->get_future(); } else if (mFutr.valid()) { mFutr = std::future<BitVector>(); } out.mOutPartyIdxs.assign(pIdxs.begin(), pIdxs.end()); ShGc::CircuitItem cc; cc.mLabels.resize(2); cc.mLabels[0] = mLabels; cc.mLabels[1] = out.mLabels; mRt.enqueue(std::move(out)); mRt.enqueue(std::move(cc)); }
int main(int argc, char ** argv){ int input = atoi(argv[1]); printBinary(input); printf("number of 1 bits in input is: %d",bitCount(input)); }
StepCode EliminateNakedTriplesStep::runOnHouse(House &house) { bool modified = false; if (house.size() <= 3) { return {false, modified}; } std::vector<std::pair<Mask, std::vector<const Cell *>>> found_masks; for (const Cell *cell : house) { std::size_t num_candidates = cell->candidates.count(); if (num_candidates == 0) { return {true, modified}; } if (num_candidates != 2 && num_candidates != 3) { continue; } const Mask mask = cell->candidates.to_ulong(); bool found_match = false; for (unsigned i = 0; i < found_masks.size(); ++i) { const Mask m = found_masks[i].first; // ORing the two masks together will switch on all candidates found in // both masks. If it's less than three, then we're still a triple // candidate. // TODO: If the current mask is size 2 and the OR of the two is 3, then // we should create two masks: one for the two and one for the OR. // Otherwise you could get 1/2 match with 1/2/3 and 1/2/4. // For now, only accept found masks of size 3. Easy naked triples. if (bitCount(m) == 3 && bitCount(mask | m) == 3) { found_match = true; found_masks[i].second.push_back(cell); } } if (!found_match) { std::pair<Mask, std::vector<const Cell *>> pair; pair.first = mask; pair.second.push_back(cell); found_masks.push_back(pair); } } for (auto &pair : found_masks) { if (pair.second.size() != 3) { continue; } auto &matches = pair.second; const Mask mask = pair.first; for (Cell *cell : house) { if (cell->isFixed()) { continue; } if (std::find(matches.begin(), matches.end(), cell) != matches.end()) { continue; } CandidateSet *candidates = &cell->candidates; if (candidates->to_ulong() == mask) { continue; } auto new_cands = CandidateSet(candidates->to_ulong() & ~mask); if (*candidates == new_cands) { continue; } if (DEBUG) { const Mask intersection = candidates->to_ulong() & mask; dbgs() << "Naked Triple " << printCandidateString(mask) << " removes " << printCandidateString(intersection) << " from " << cell->coord << "\n"; } modified = true; changed.insert(cell); *candidates = new_cands; } } return {false, modified}; }
FBConfigInfo *GlxBackend::infoForVisual(xcb_visualid_t visual) { FBConfigInfo *&info = m_fbconfigHash[visual]; if (info) return info; info = new FBConfigInfo; info->fbconfig = nullptr; info->bind_texture_format = 0; info->texture_targets = 0; info->y_inverted = 0; info->mipmap = 0; const xcb_render_pictformat_t format = XRenderUtils::findPictFormat(visual); const xcb_render_directformat_t *direct = XRenderUtils::findPictFormatInfo(format); if (!direct) { qCCritical(KWIN_CORE).nospace() << "Could not find a picture format for visual 0x" << hex << visual; return info; } const int red_bits = bitCount(direct->red_mask); const int green_bits = bitCount(direct->green_mask); const int blue_bits = bitCount(direct->blue_mask); const int alpha_bits = bitCount(direct->alpha_mask); const int depth = visualDepth(visual); const auto rgb_sizes = std::tie(red_bits, green_bits, blue_bits); const int attribs[] = { GLX_RENDER_TYPE, GLX_RGBA_BIT, GLX_DRAWABLE_TYPE, GLX_WINDOW_BIT | GLX_PIXMAP_BIT, GLX_X_VISUAL_TYPE, GLX_TRUE_COLOR, GLX_X_RENDERABLE, True, GLX_CONFIG_CAVEAT, int(GLX_DONT_CARE), // The ARGB32 visual is marked non-conformant in Catalyst GLX_BUFFER_SIZE, red_bits + green_bits + blue_bits + alpha_bits, GLX_RED_SIZE, red_bits, GLX_GREEN_SIZE, green_bits, GLX_BLUE_SIZE, blue_bits, GLX_ALPHA_SIZE, alpha_bits, GLX_STENCIL_SIZE, 0, GLX_DEPTH_SIZE, 0, 0 }; int count = 0; GLXFBConfig *configs = glXChooseFBConfig(display(), DefaultScreen(display()), attribs, &count); if (count < 1) { qCCritical(KWIN_CORE).nospace() << "Could not find a framebuffer configuration for visual 0x" << hex << visual; return info; } struct FBConfig { GLXFBConfig config; int depth; int stencil; int format; }; std::deque<FBConfig> candidates; for (int i = 0; i < count; i++) { int red, green, blue; glXGetFBConfigAttrib(display(), configs[i], GLX_RED_SIZE, &red); glXGetFBConfigAttrib(display(), configs[i], GLX_GREEN_SIZE, &green); glXGetFBConfigAttrib(display(), configs[i], GLX_BLUE_SIZE, &blue); if (std::tie(red, green, blue) != rgb_sizes) continue; xcb_visualid_t visual; glXGetFBConfigAttrib(display(), configs[i], GLX_VISUAL_ID, (int *) &visual); if (visualDepth(visual) != depth) continue; int bind_rgb, bind_rgba; glXGetFBConfigAttrib(display(), configs[i], GLX_BIND_TO_TEXTURE_RGBA_EXT, &bind_rgba); glXGetFBConfigAttrib(display(), configs[i], GLX_BIND_TO_TEXTURE_RGB_EXT, &bind_rgb); if (!bind_rgb && !bind_rgba) continue; int depth, stencil; glXGetFBConfigAttrib(display(), configs[i], GLX_DEPTH_SIZE, &depth); glXGetFBConfigAttrib(display(), configs[i], GLX_STENCIL_SIZE, &stencil); int texture_format; if (alpha_bits) texture_format = bind_rgba ? GLX_TEXTURE_FORMAT_RGBA_EXT : GLX_TEXTURE_FORMAT_RGB_EXT; else texture_format = bind_rgb ? GLX_TEXTURE_FORMAT_RGB_EXT : GLX_TEXTURE_FORMAT_RGBA_EXT; candidates.emplace_back(FBConfig{configs[i], depth, stencil, texture_format}); } if (count > 0) XFree(configs); std::stable_sort(candidates.begin(), candidates.end(), [](const FBConfig &left, const FBConfig &right) { if (left.depth < right.depth) return true; if (left.stencil < right.stencil) return true; return false; }); if (candidates.size() > 0) { const FBConfig &candidate = candidates.front(); int y_inverted, texture_targets; glXGetFBConfigAttrib(display(), candidate.config, GLX_BIND_TO_TEXTURE_TARGETS_EXT, &texture_targets); glXGetFBConfigAttrib(display(), candidate.config, GLX_Y_INVERTED_EXT, &y_inverted); info->fbconfig = candidate.config; info->bind_texture_format = candidate.format; info->texture_targets = texture_targets; info->y_inverted = y_inverted; info->mipmap = 0; } if (info->fbconfig) { int fbc_id = 0; int visual_id = 0; glXGetFBConfigAttrib(display(), info->fbconfig, GLX_FBCONFIG_ID, &fbc_id); glXGetFBConfigAttrib(display(), info->fbconfig, GLX_VISUAL_ID, &visual_id); qCDebug(KWIN_CORE).nospace() << "Using FBConfig 0x" << hex << fbc_id << " for visual 0x" << hex << visual_id; } return info; }
int Endgame::getEndgameValue(const int N_PIECE, const int side) { ASSERT(N_PIECE != 999); ASSERT_RANGE(side, 0, 1); int result = INT_MAX; int winnerSide = -1; switch (N_PIECE) { case 4 : if (chessboard[QUEEN_BLACK]) { if (chessboard[PAWN_WHITE]) { result = KQKP(WHITE, BITScanForward(chessboard[KING_BLACK]), BITScanForward(chessboard[KING_WHITE]), BITScanForward(chessboard[PAWN_WHITE])); winnerSide = BLACK; } else if (chessboard[ROOK_WHITE]) { result = KQKR(BITScanForward(chessboard[KING_BLACK]), BITScanForward(chessboard[KING_WHITE])); winnerSide = BLACK; } } else if (chessboard[QUEEN_WHITE]) { if (chessboard[PAWN_BLACK]) { result = KQKP(BLACK, BITScanForward(chessboard[KING_WHITE]), BITScanForward(chessboard[KING_BLACK]), BITScanForward(chessboard[PAWN_BLACK])); winnerSide = WHITE; } else if (chessboard[ROOK_BLACK]) { result = KQKR(BITScanForward(chessboard[KING_WHITE]), BITScanForward(chessboard[KING_BLACK])); winnerSide = WHITE; } } else if (chessboard[ROOK_BLACK]) { if (chessboard[PAWN_WHITE]) { result = KRKP<WHITE>(side == BLACK, BITScanForward(chessboard[KING_BLACK]), BITScanForward(chessboard[KING_WHITE]), BITScanForward(chessboard[ROOK_BLACK]), BITScanForward(chessboard[PAWN_WHITE])); winnerSide = BLACK; } else if (chessboard[BISHOP_WHITE]) { result = KRKB(BITScanForward(chessboard[KING_WHITE])); winnerSide = BLACK; } else if (chessboard[KNIGHT_WHITE]) { result = KRKN(BITScanForward(chessboard[KING_WHITE]), BITScanForward(chessboard[KNIGHT_WHITE])); winnerSide = BLACK; } } else if (chessboard[ROOK_WHITE]) { if (chessboard[PAWN_BLACK]) { result = KRKP<BLACK>(side == WHITE, BITScanForward(chessboard[KING_WHITE]), BITScanForward(chessboard[KING_BLACK]), BITScanForward(chessboard[ROOK_WHITE]), BITScanForward(chessboard[PAWN_BLACK])); winnerSide = WHITE; } else if (chessboard[BISHOP_BLACK]) { result = KRKB(BITScanForward(chessboard[KING_BLACK])); winnerSide = WHITE; } else if (chessboard[KNIGHT_BLACK]) { result = KRKN(BITScanForward(chessboard[KING_WHITE]), BITScanForward(chessboard[KNIGHT_BLACK])); winnerSide = WHITE; } } else if ((chessboard[BISHOP_BLACK] && chessboard[KNIGHT_BLACK])) { result = KBNK(BITScanForward(chessboard[KING_BLACK]), BITScanForward(chessboard[KING_WHITE])); winnerSide = BLACK; } else if (chessboard[BISHOP_WHITE] && chessboard[KNIGHT_WHITE]) { result = KBNK(BITScanForward(chessboard[KING_WHITE]), BITScanForward(chessboard[KING_BLACK])); winnerSide = WHITE; } break; case 5: if (chessboard[KNIGHT_WHITE] && bitCount(chessboard[BISHOP_BLACK]) == 2) { result = KBBKN(BITScanForward(chessboard[KING_BLACK]), BITScanForward(chessboard[KING_WHITE]), BITScanForward(chessboard[KNIGHT_WHITE])); winnerSide = BLACK; } else if (chessboard[KNIGHT_BLACK] && bitCount(chessboard[BISHOP_WHITE]) == 2) { result = KBBKN(BITScanForward(chessboard[KING_WHITE]), BITScanForward(chessboard[KING_BLACK]), BITScanForward(chessboard[KNIGHT_BLACK])); winnerSide = WHITE; } break; default: break; } if (winnerSide == -1)return INT_MAX; return winnerSide == side ? result : -result; }
Bits::Bits() { //LINK_ROOKS LINK_ROOKS = ( u64** ) malloc ( 64 * sizeof ( u64* ) ); for ( int i = 0; i < 64; i++ ) { LINK_ROOKS[i] = ( u64* ) malloc ( 64 * sizeof ( u64 ) ); } int from, to; for ( int i = 0; i < 64; i++ ) { for ( int j = 0; j < 64; j++ ) { u64 t = 0; if ( RANK[i] & RANK[j] ) { //rank from = min ( i, j ); to = max ( i, j ); for ( int k = from + 1; k <= to - 1; k++ ) { t |= POW2[k]; } } else if ( FILE_[i] & FILE_[j] ) { //file from = min ( i, j ); to = max ( i, j ); for ( int k = from + 8; k <= to - 8; k += 8 ) { t |= POW2[k]; } } if ( !t ) { t = 0xffffffffffffffffULL; } LINK_ROOKS[i][j] = t; } } //DISTANCE for ( int i = 0; i < 64; i++ ) { for ( int j = 0; j < 64; j++ ) { DISTANCE[i][j] = max ( abs ( RANK_AT[i] - FILE_AT[j] ), abs ( RANK_AT[j] - FILE_AT[i] ) ); } } /// u64 MASK_BIT_SET[64][64]; memset ( MASK_BIT_SET, 0, sizeof ( MASK_BIT_SET ) ); for ( int i = 0; i < 64; i++ ) { for ( int j = 0; j < 64; j++ ) { int a = min ( i, j ); int b = max ( i, j ); MASK_BIT_SET[i][i] = 0; for ( int e = a; e <= b; e++ ) { u64 r = ( RANK[i] | POW2[i] ) & ( RANK[j] | POW2[j] ); if ( r ) { MASK_BIT_SET[i][j] |= POW2[e] & r; } else { r = ( FILE_[i] | POW2[i] ) & ( FILE_[j] | POW2[j] ); if ( r ) { MASK_BIT_SET[i][j] |= POW2[e] & r; } else { r = ( LEFT_DIAG[i] | POW2[i] ) & ( LEFT_DIAG[j] | POW2[j] ); if ( r ) { MASK_BIT_SET[i][j] |= POW2[e] & r; } else { r = ( RIGHT_DIAG[i] | POW2[i] ) & ( RIGHT_DIAG[j] | POW2[j] ); if ( r ) { MASK_BIT_SET[i][j] |= POW2[e] & r; } } } } } if ( i == j ) { MASK_BIT_SET[i][i] &= NOTPOW2[i]; } } } for ( int i = 0; i < 64; i++ ) { for ( int j = 0; j < 64; j++ ) { MASK_BIT_SET_NOBOUND[i][j] = MASK_BIT_SET[i][j]; MASK_BIT_SET_NOBOUND[i][j] &= NOTPOW2[i]; MASK_BIT_SET_NOBOUND[i][j] &= NOTPOW2[j]; MASK_BIT_SET[i][j] &= NOTPOW2[i]; } } for ( int i = 0; i < 64; i++ ) { for ( int j = 0; j < 64; j++ ) { MASK_BIT_SET_COUNT[i][j] = bitCount ( MASK_BIT_SET[i][j] ); MASK_BIT_SET_NOBOUND_COUNT[i][j] = bitCount ( MASK_BIT_SET_NOBOUND[i][j] ); } } }