Magic...what's that?

Programming Topics (Computer Chess) and technical aspects as test techniques, book building, program tuning etc

Moderator: Andres Valverde

Magic...what's that?

Postby Andrew Wagner » 22 Feb 2007, 22:03

So, I've been out of the chess programming community mainstream for a year or two now, getting my degree. Now I'm getting back into reading more about it, and everyone's talking about magic bitboards. Could someone give me a summary of what they are and how they work? There seem to be a number of scattered posts that talk about different aspects, but I'm pretty confused overall...
Andrew Wagner
 
Posts: 2
Joined: 22 Feb 2007, 20:00

Re: Magic...what's that?

Postby H.G.Muller » 22 Feb 2007, 23:36

'magic' refers to a particular kind of table lookup, where all bits in a long (usually 64-bit) word that are relevant for the quantity to be looked up (e.g. the bits giving the occupancy state of a certain ray on a bitboard, for looking up to where a sider can move along this ray, represented as a bitboard of target squares) are collected by a single multiplication.

So usually it goes like this:

Code: Select all
u64 a;       /* bitboard containing scatterered relevant bits */
int index;

index = MAGIC_MULTIPLIER * a >> 52; /* leaves 12 bits */
result = Table[index];


That's really all. Usually the bits one wants to collect depend on the square on which a piece for which moves are calculated is positioned. Each square then needs its own MAGIC_MULTIPLIER, so there will be tables of multipliers indexed by square number, and berhaps also tables of result tables, as
Table[sqr][index].
User avatar
H.G.Muller
 
Posts: 3453
Joined: 16 Nov 2005, 12:02
Location: Diemen, NL

Re: Magic...what's that?

Postby Andrew Wagner » 23 Feb 2007, 00:00

So then...all move generation just becomes static look-ups? And all these magic tables are pre-generated?
Andrew Wagner
 
Posts: 2
Joined: 22 Feb 2007, 20:00

Re: Magic...what's that?

Postby Pradu » 23 Feb 2007, 03:18

Andrew Wagner wrote:So then...all move generation just becomes static look-ups? And all these magic tables are pre-generated?
Yes.
User avatar
Pradu
 
Posts: 343
Joined: 12 Jan 2005, 19:17
Location: Chandler, Arizona, USA


Return to Programming and Technical Discussions

Who is online

Users browsing this forum: No registered users and 18 guests