Looking for Magics

Home * Board Representation * Bitboards * Sliding Piece Attacks * Magic Bitboards * Looking for Magics

Magic Bitboards is probably the fastest approach to generate sliding piece attacks on recent architectures with fast 64-bit multiplication. It performs a mask/mul/shift->lookup to gain all the attacked squares of a bishop or rook.

=Trial and Error= So far the only approach to find 64-bit magic factors is trial and error. One has the idea, how many bits are needed for a perfect hashing - and about constrains of least and most significant one-bit inside the magic factor. In September 2017, Niklas Fiekas introduced a technique based on the least common multiple of the periods for all relevant occupancies to reduce the range for magic candidates, specially to find magics with one bit less than the number of relevant occupancies to half the individual tables sizes as mentioned in Best Magics so far. any consecutive relevant occupancy                     combination of bishop b1, 5 bits                       the masked bits . . . . . . . .    . . . . . . . .     . . .[C D E F G] .. . . . . . .    . 1 . . . . . .     . . . . . . . . . . . . . . G. . 1 . . . . . .    . . . . . . . . . . . . . F. .    . 1 . . . . . .     . . . . . . . . . . . . E. . . *  . 1 . . . . . .  =  . . garbage. .   >> (64- 5) . . . D. . . .    . 1 . . . . . .     . . . . . . . . . . C. . . . .    . . . . . . . .     . . . . . . . . . . . . . . . .     . . . . . . . .     . . . . . . ..

any consecutive relevant occupancy                     combination of bishop d4, 9 bits                       the masked bits . . . . . . . .    . . . . . . . .     2 4 5 B C E F G] .. . . . . G. . . .some. . .    . . . . . . .[1 . 5 . . . F. .    . . . . . . . .     . . . . . . . . . . 4 . E. . .    . . .magic. . .    . . . . . . . . . . . . . . . .  *  . . . . . . . .  =  . . garbage. .   >> (64- 9) . . C. 2 . . .    . . .bits. . .    . . . . . . . . . B. . . 1 . .    . . . . . . . .     . . . . . . . . . . . . . . . .     . . . . . . . .     . . . . . . ..

any consecutive relevant occupancy                     combination of rook d4, 10 bits                        the masked bits . . . . . . . .    . . . . . . . .     4 5 6 B C E F G] .. . 6 . . . .    . . .some. . .    . . . . . .[1 2 . . . 5 . . . .     . . . . . . . .     . . . . . . . . . . . 4 . . . .     . . .magic. . .    . . . . . . . . . B C. E F G. * . . . . . . . .  =  . . garbage. .   >> (64-10) . . . 2 . . . .     . . .bits. . .    . . . . . . . . . . . 1 . . . .     . . . . . . . .     . . . . . . . . . . . . . . . .     . . . . . . . .     . . . . . . ..

any consecutive relevant occupancy                     combination of rook a1, 12 bits                        the masked bits . . . . . . . .    . . . . . . . .     5 6 B C D E F G] 6. . . . . . .    . . .some. . .    . . . .[1 2 3 4 5 . . . . . . .     . . . . . . . .     . . . . . . . . 4 . . . . . . .     . . .magic. . .    . . . . . . . . 3 . . . . . . .  *  . . . . . . . .  =  . . garbage. .   >> (64-12) 2 . . . . . . .     . . .bits. . .    . . . . . . . . 1 . . . . . . .     . . . . . . . .     . . . . . . . . . B C D E F G. . . . . . . . .    . . . . . . . . =Feeding in Randoms= Tord Romstad's proposal to find magics :

=Fixed Shift Magics= Another application is Looking for overlapping Magics for a fixed shift approach, as recently proposed by Volker Annuss.

=See also=
 * Best Magics so far
 * Traversing Subsets of a Set

=Forum Posts=
 * Magic Move Generation by Colin, CCC, February 18, 2008
 * Magics revisited by Richard Pijl, CCC, January 04, 2009
 * magic search by Daniel Shawul, CCC, March 19, 2010
 * Build magics on the fly by Marco Costalba, CCC, June 07, 2011
 * Super Fast 'Looking for magics' 1.0 by Syed Fahad, CCC, October 25, 2014
 * question about magic keys generation time by Fermin Serrano, CCC, March 19, 2015
 * Magic number generation taking 17 seconds or more by Kalyankumar Ramaseshan, CCC, November 29, 2015
 * Re: Some questions from a beginner by Tim Hagen, CCC, April 04, 2016
 * Re: Some questions from a beginner by Gerd Isenberg, CCC, April 05, 2016
 * Re: Some questions from a beginner by Mincho Georgiev, CCC, April 06, 2016


 * Looking for dense magics by Lucas Braesch, CCC, July 11, 2017
 * Disproving the existence of some magics by Niklas Fiekas, CCC, September 16, 2017
 * No bishop magics with fixed shift 8 by Niklas Fiekas, CCC, April 09, 2018

=External Links=
 * Chess Programming | Generating Magic Multipliers by Steve Maughan

=References=

Up one level