Answers.Body: <p>This is a very well known problem in chess programming. You should consider use the numbers generated by Pradyumna Kannan. Dr Kannan had kindly produced open-source the magic numbers. It is being used by Crafty and a few other chess engines including my own.</p>
  
  <p>You can read more by google "Crafty magic number".</p>
  
  <p>I've prepared a zipped file for you <a href="http://smallchess.com/MagicMoves.zip">here</a>. This is the same files being used in the SmallChess chess engine app. Please read the documentation. Basically, you'll need to call <em>Rmagic(square, occupancy)</em> for rooks and <em>Bmagic(square, occupancy)</em> for bishops. You can XOR those into a queen mask.</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-05-08T19:26:17.587Z
Answers.Text: Thanks it works well. Can I freely use/modify this code in my chess engine?
Answers.UserDisplayName: Romain
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-05-09T00:44:05.430Z
Answers.Text: There is no licence restriction. Use as you pleased. It wasn't me who did it, it was a contribution by Dr Kannan. Please accept my answer if it helps!
Answers.UserDisplayName: SmallChess
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-10-31T13:40:34.917Z
Answers.Text: @AryanParekh It wasn't me who wrote it.
Answers.UserDisplayName: SmallChess
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-10-31T17:50:32.620Z
Answers.Text: @AryanParekh Please post a new question. We can't provide individual level help here.
Answers.UserDisplayName: SmallChess
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-10-31T19:50:47.420Z
Answers.Text: @AryanParekh stackoverflow is a free service for all of us. I am not paid for offering expert level advice. I can’t help you one to one. Please start a new question so everybody can help.
Answers.UserDisplayName: SmallChess
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-03-23T04:59:07.307Z
Answers.Text: Hi, can you upload the file MagicMoves.zip to GoogleDrive? I can't download it at smallchess (I got some error). Thanks.
Answers.UserDisplayName: 123iamking
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-03-23T04:59:22.677Z
Answers.Text: @123iamking The link is still working. I am not going to remove it.
Answers.UserDisplayName: SmallChess
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-03-23T09:12:19.950Z
Answers.Text: @SmallChess - I don't ask about removing it, can you provide a mirror with Google Drive? Thanks.
Answers.UserDisplayName: 123iamking
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-05-07T23:49:38.090Z
Answers.LastActivityDate: 2015-05-07T23:49:38.090Z
Answers.UserDisplayName: SmallChess
Body: <p>I am writing a C++ chess <a href="https://github.com/RomainGoussault/Deepov">engine</a> and I am looking for magic numbers for <a href="https://chessprogramming.wikispaces.com/Square+Mapping+Considerations#LittleEndianRankFileMapping">Little-Endian Rank-File Mapping</a> bitboards to generate moves for sliding pieces.</p>
  
  <p>The rival chess <a href="http://www.rivalchess.com/magic-bitboards/">website</a> gives magic numbers but not for the same board mapping.</p>
  
  <p>The chess programming wiki gives <a href="https://chessprogramming.wikispaces.com/Best+Magics+so+far">some of the best magic numbers so far</a> but is not exhaustive.</p>
  
  <p>At the end I am looking for four things:</p>
  
  <ul>
  <li>occupancy mask for each square</li>
  <li>magic number for each square</li>
  <li>magic shifts for each square</li>
  <li>moves database array for each square</li>
  </ul>
  
  <p>So I can use the following <a href="http://www.rivalchess.com/magic-bitboards/">code</a> to find the moves of the Rook on C3 (for instance):</p>
  
  <pre><code>bbBlockers = bbAllPieces &amp; occupancyMaskRook[C3]
  
  databaseIndex = (int)((bbBlockers * magicNumberRook[C3]) &gt;&gt; rookMagicShifts[C3])
  
  bbMoveSquares = magicMovesRook[C3][databaseIndex] &amp; ~bbFriendlyPieces
  </code></pre>
  
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2015-05-07T22:01:29.713Z
Comments.Text: I believe this question will be better suited and answered at http://programmers.stackexchange.com/ or http://stackoverflow.com/ .
Comments.UserDisplayName: Pavan Nadig
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2015-05-07T23:36:09.963Z
Comments.Text: Not really. This is still answerable here. BTW, programmers focus more on high-level abstraction. stackoverflow.com would have been better.
Comments.UserDisplayName: SmallChess
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2015-05-08T16:58:06.147Z
Comments.Text: @PeteBecker You are right, I changed it
Comments.UserDisplayName: Romain
Tags: <engines><software><programming><bitboard>
Title: Find magic numbers for bitboards
ThreadText: # Find magic numbers for bitboards
  
  (Asked by: username_0 on 2015-05-07)
  
  I am writing a C++ chess engine and I am looking for magic numbers for Little-Endian Rank-File Mapping bitboards to generate moves for sliding pieces.
  The rival chess website gives magic numbers but not for the same board mapping.
  The chess programming wiki gives some of the best magic numbers so far but is not exhaustive.
  At the end I am looking for four things:
  
  occupancy mask for each square
  magic number for each square
  magic shifts for each square
  moves database array for each square
  
  So I can use the following code to find the moves of the Rook on C3 (for instance):
  bbBlockers = bbAllPieces & occupancyMaskRook[C3]
  
  databaseIndex = (int)((bbBlockers * magicNumberRook[C3]) >> rookMagicShifts[C3])
  
  bbMoveSquares = magicMovesRook[C3][databaseIndex] & ~bbFriendlyPieces
  
  **Tags:** engines, software, programming, bitboard
  
  > **Comments:**
  > **username_1**: I believe this question will be better suited and answered at http://programmers.stackexchange.com/ or http://stackoverflow.com/ .  
  > **username_2**: Not really. This is still answerable here. BTW, programmers focus more on high-level abstraction. stackoverflow.com would have been better.  
  > **username_0**: @PeteBecker You are right, I changed it  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_2 on 2015-05-07. Score: 9 | Accepted answer
  
  This is a very well known problem in chess programming. You should consider use the numbers generated by Pradyumna Kannan. Dr Kannan had kindly produced open-source the magic numbers. It is being used by Crafty and a few other chess engines including my own.
  
  You can read more by google "Crafty magic number".
  
  I've prepared a zipped file for you [here](http://smallchess.com/MagicMoves.zip). This is the same files being used in the username_2 chess engine app. Please read the documentation. Basically, you'll need to call *Rmagic(square, occupancy)* for rooks and *Bmagic(square, occupancy)* for bishops. You can XOR those into a queen mask.
  
  > **Comments:**
  > **username_0**: Thanks it works well. Can I freely use/modify this code in my chess engine?  
  > **username_2**: There is no licence restriction. Use as you pleased. It wasn't me who did it, it was a contribution by Dr Kannan. Please accept my answer if it helps!  
  > **username_3**: Hi, can you upload the file MagicMoves.zip to GoogleDrive? I can't download it at smallchess (I got some error). Thanks.  
  > **username_2**: @username_3 The link is still working. I am not going to remove it.  
  > **username_3**: @username_2 - I don't ask about removing it, can you provide a mirror with Google Drive? Thanks.  
  > **username_2**: @AryanParekh It wasn't me who wrote it.  
  > **username_2**: @AryanParekh Please post a new question. We can't provide individual level help here.  
  > **username_2**: @AryanParekh stackoverflow is a free service for all of us. I am not paid for offering expert level advice. I can’t help you one to one. Please start a new question so everybody can help.  
  
  ---
  
  