void InitBitboards() { int i, j, from, to; U64 x, y; // Bit scan for (i = 1; i < 65536; ++i) { int x = 0x8000; for (j = 0; j < 16; ++j) { if (i & x) { MSB_16[i] = static_cast<U8>(j); break; } x >>= 1; } } x = ((U64) 1) << 63; for (i = 0; i < 64; i++) { BB_SINGLE[i] = x; x >>= 1; } for (from = 0; from < 64; from++) { for (to = 0; to < 64; ++to) { BB_BETWEEN[from][to] = 0; } #define TRACE_DIR(dir, Shift, delta) \ x = Shift(BB_SINGLE[from]); \ y = 0; \ to = from + (delta); \ while (x) \ { \ BB_BETWEEN[from][to] = y; \ y |= x; \ x = Shift(x); \ to += (delta); \ } \ BB_DIR[from][dir] = y; TRACE_DIR (DIR_R, Right, 1) TRACE_DIR (DIR_UR, UpRight, -7) TRACE_DIR (DIR_U, Up, -8) TRACE_DIR (DIR_UL, UpLeft, -9) TRACE_DIR (DIR_L, Left, -1) TRACE_DIR (DIR_DL, DownLeft, 7) TRACE_DIR (DIR_D, Down, 8) TRACE_DIR (DIR_DR, DownRight, 9) x = BB_SINGLE[from]; y = 0; y |= Right(UpRight(x)); y |= Up(UpRight(x)); y |= Up(UpLeft(x)); y |= Left(UpLeft(x)); y |= Left(DownLeft(x)); y |= Down(DownLeft(x)); y |= Down(DownRight(x)); y |= Right(DownRight(x)); BB_KNIGHT_ATTACKS[from] = y; x = BB_SINGLE[from]; y = 0; y |= UpRight(x); y |= Up(x); y |= UpLeft(x); y |= Left(x); y |= DownLeft(x); y |= Down(x); y |= DownRight(x); y |= Right(x); BB_KING_ATTACKS[from] = y; x = BB_SINGLE[from]; y = 0; y |= UpRight(x); y |= UpLeft(x); BB_PAWN_ATTACKS[from][WHITE] = y; x = BB_SINGLE[from]; y = 0; y |= DownRight(x); y |= DownLeft(x); BB_PAWN_ATTACKS[from][BLACK] = y; BB_BISHOP_ATTACKS[from] = BB_DIR[from][DIR_UR] | BB_DIR[from][DIR_UL] | BB_DIR[from][DIR_DL] | BB_DIR[from][DIR_DR]; BB_ROOK_ATTACKS[from] = BB_DIR[from][DIR_R] | BB_DIR[from][DIR_U] | BB_DIR[from][DIR_L] | BB_DIR[from][DIR_D]; BB_QUEEN_ATTACKS[from] = BB_ROOK_ATTACKS[from] | BB_BISHOP_ATTACKS[from]; } // pawn squares for (int f = 0; f < 64; f++) { x = BB_DIR[f][DIR_U] | BB_SINGLE[f]; for (j = 0; j < Row(f); j++) { x |= Right(x); x |= Left(x); } BB_PAWN_SQUARE[f][WHITE] = x; x = BB_DIR[f][DIR_D] | BB_SINGLE[f]; for (j = 0; j < 7 - Row(f); j++) { x |= Right(x); x |= Left(x); } BB_PAWN_SQUARE[f][BLACK] = x; } #ifdef MAGIC int offset; offset = 0; for (int f = 0; f < 64; ++f) { B_OFFSET[f] = offset; offset += (1 << B_BITS[f]); } B_DATA = new U64[offset]; for (int f = 0; f < 64; ++f) { U64 mask = B_MASK[f]; int bits = B_BITS[f]; for (int n = 0; n < (1 << bits); ++n) { U64 occ = EnumBits(mask, n); U64 att = BishopAttacksTrace(f, occ); int index = B_OFFSET[f]; index += int((occ * B_MULT[f]) >> (64 - bits)); B_DATA[index] = att; } } offset = 0; for (int f = 0; f < 64; ++f) { R_OFFSET[f] = offset; offset += (1 << R_BITS[f]); } R_DATA = new U64[offset]; for (int f = 0; f < 64; ++f) { U64 mask = R_MASK[f]; int bits = R_BITS[f]; for (int n = 0; n < (1 << bits); ++n) { U64 occ = EnumBits(mask, n); U64 att = RookAttacksTrace(f, occ); int index = R_OFFSET[f]; index += int((occ * R_MULT[f]) >> (64 - bits)); R_DATA[index] = att; } } #endif }
void Bitboard::InitBitboards() { int i, j, from, to; U64 x, y; // Bit scan for (i = 1; i < 65536; ++i) { int x = 0x8000; for (j = 0; j < 16; ++j) { if (i & x) { m_msb16[i] = static_cast<U8>(j); break; } x >>= 1; } } x = ((U64) 1) << 63; for (i = 0; i < 64; i++) { m_single[i] = x; x >>= 1; } for (from = 0; from < 64; from++) { for (to = 0; to < 64; ++to) { m_between[from][to] = 0; } #define TRACE_DIR(dir, Shift, delta) \ x = Shift(m_single[from]); \ y = 0; \ to = from + (delta); \ while (x) \ { \ m_between[from][to] = y; \ y |= x; \ x = Shift(x); \ to += (delta); \ } \ m_dir[from][dir] = y; TRACE_DIR (DIR_R, Right, 1) TRACE_DIR (DIR_UR, UpRight, -7) TRACE_DIR (DIR_U, Up, -8) TRACE_DIR (DIR_UL, UpLeft, -9) TRACE_DIR (DIR_L, Left, -1) TRACE_DIR (DIR_DL, DownLeft, 7) TRACE_DIR (DIR_D, Down, 8) TRACE_DIR (DIR_DR, DownRight, 9) x = m_single[from]; y = 0; y |= Right(UpRight(x)); y |= Up(UpRight(x)); y |= Up(UpLeft(x)); y |= Left(UpLeft(x)); y |= Left(DownLeft(x)); y |= Down(DownLeft(x)); y |= Down(DownRight(x)); y |= Right(DownRight(x)); m_knightAttacks[from] = y; x = m_single[from]; y = 0; y |= UpRight(x); y |= Up(x); y |= UpLeft(x); y |= Left(x); y |= DownLeft(x); y |= Down(x); y |= DownRight(x); y |= Right(x); m_kingAttacks[from] = y; x = m_single[from]; y = 0; y |= UpRight(x); y |= UpLeft(x); m_pawnAttacks[from][WHITE] = y; x = m_single[from]; y = 0; y |= DownRight(x); y |= DownLeft(x); m_pawnAttacks[from][BLACK] = y; m_bishopAttacks[from] = m_dir[from][DIR_UR] | m_dir[from][DIR_UL] | m_dir[from][DIR_DL] | m_dir[from][DIR_DR]; m_rookAttacks[from] = m_dir[from][DIR_R] | m_dir[from][DIR_U] | m_dir[from][DIR_L] | m_dir[from][DIR_D]; m_queenAttacks[from] = m_rookAttacks[from] | m_bishopAttacks[from]; } // pawn squares for (int f = 0; f < 64; f++) { x = m_dir[f][DIR_U] | m_single[f]; for (j = 0; j < Row(f); j++) { x |= Right(x); x |= Left(x); } m_pawnSquare[f][WHITE] = x; x = m_dir[f][DIR_D] | m_single[f]; for (j = 0; j < 7 - Row(f); j++) { x |= Right(x); x |= Left(x); } m_pawnSquare[f][BLACK] = x; } #ifdef MAGIC int offset = 0; for (int f = 0; f < 64; ++f) { m_bOffset[f] = offset; offset += (1 << m_bBits[f]); } m_bData = new U64[offset]; for (int f = 0; f < 64; ++f) { U64 mask = m_bMask[f]; int bits = m_bBits[f]; for (int n = 0; n < (1 << bits); ++n) { U64 occ = EnumBits(mask, n); U64 att = BishopAttacksTrace(f, occ); int index = m_bOffset[f]; index += int((occ * m_bMult[f]) >> (64 - bits)); m_bData[index] = att; } } offset = 0; for (int f = 0; f < 64; ++f) { m_rOffset[f] = offset; offset += (1 << m_rBits[f]); } m_rData = new U64[offset]; for (int f = 0; f < 64; ++f) { U64 mask = m_rMask[f]; int bits = m_rBits[f]; for (int n = 0; n < (1 << bits); ++n) { U64 occ = EnumBits(mask, n); U64 att = RookAttacksTrace(f, occ); int index = m_rOffset[f]; index += int((occ * m_rMult[f]) >> (64 - bits)); m_rData[index] = att; } } #endif }
//////////////////////////////////////////////////////////// // TViewBitmapDialog // ----------------- // Load the DOOM palette and add the sprite names in list box void TViewBitmapDialog::SetupWindow () { TDialog::SetupWindow(); ::CenterWindow (this); // Setup control window size TRect cRect = pSizeStatic->GetClientRect (); BitmapControlW = cRect.right; BitmapControlH = cRect.bottom; TPoint UpLeft(cRect.left, cRect.top); pSizeStatic->ClientToScreen (UpLeft); ScreenToClient (UpLeft); BitmapControlX = UpLeft.x; BitmapControlY = UpLeft.y; // // Create zoom slider with same size as the its frame // TRect wRect; TPoint TopLeft; pZoomFrame->GetWindowRect (wRect); TopLeft = TPoint (wRect.left, wRect.top); ScreenToClient (TopLeft); pZoomSlider = new TVSlider (this, IDC_ZOOM_SLIDER, TopLeft.x+1, TopLeft.y+1, wRect.Width()-2, wRect.Height()-2); // Hide the slider frame pZoomFrame->ShowWindow (SW_HIDE); // Create the slider pZoomSlider->Create(); pZoomSlider->SetRange (1, 16); pZoomSlider->SetRuler (3, FALSE); pZoomSlider->SetPosition (1); // // Create Gamma Level slider with same size as the its frame // pGammaFrame->GetWindowRect (wRect); TopLeft = TPoint (wRect.left, wRect.top); ScreenToClient (TopLeft); pGammaSlider = new TVSlider (this, IDC_GAMMA_SLIDER, TopLeft.x+1, TopLeft.y+1, wRect.Width()-2, wRect.Height()-2); // Hide the slider frame pGammaFrame->ShowWindow (SW_HIDE); // Create the slider pGammaSlider->Create(); pGammaSlider->SetRange (0, 120); pGammaSlider->SetRuler (10, TRUE); pGammaSlider->SetPosition (0); // Creates bitmap control (virtual function of derived classes) InitBitmapControl (); CHECK (pBitmapControl != NULL); // Create the control window pSizeStatic->ShowWindow (SW_HIDE); pBitmapControl->Create(); // Draw and set position of zoom and gamma slider char zoomtext[5]; sprintf (zoomtext, "%u", pBitmapControl->GetZoomFactor()); pZoomStatic->SetText (zoomtext); pZoomSlider->SetPosition (pBitmapControl->GetZoomFactor()); char gtext[5]; sprintf (gtext, "%u", pBitmapControl->GetGammaLevel()); pGammaStatic->SetText (gtext); pGammaSlider->SetPosition (pBitmapControl->GetGammaLevel()); // Realize palette in window /* if ( UseSystemPalette ) { TScreenDC dc; dc.SetSystemPaletteUse (SYSPAL_NOSTATIC); dc.SelectObject (*pDoomPalette); dc.RealizePalette (); SaveSystemPalette(); } */ }