Understanding magic bitboards

Code, algorithms, languages, construction...

Understanding magic bitboards

Postby daz12 » Wed Feb 25, 2015 9:43 pm

Hi I'm a beginner and I am still trying to get my head around magic bitboards so excuse me if answers to my questions are obvious to you.

How can I tell if a magic number is suitable e.g. a 'magic' number? I assume it is if it gives a unique index it is suitable? Will a square only ever need a single magic number or does it have to have one for each piece type i.e. one for rook and another for bishop. Does each square have to have the same magic number :? ?

Where you right shift >> 64 - bits I assume bits relates to the mask for particular square e.g. for rook on A1 bits would equal 12?
Can any one explain in a simple way what the actual multiplication by magic numbers and the shift actually achieves? I assume it is about getting uniform distribution of indexes and avoiding collisions with respect to indexes.

Jaco on his Vicki blog talks about having to consider all the attack variations for a given square and putting it through hashing process http://vicki-chess.blogspot.co.uk/. I assume this to mean, taking a rook on square A1 as an example, all the squares the rook could move to horizontally and vertically from there before it stops - considering each permutation for this sort as a separate bitboard and putting it through the hashing/magic process?

So taking a Bishop on A1 as another example:

1. Bishop can't move at all as it is blocked at b2
2. Bishop can move to b2 before being blocked at b3
3. Bishop can only move up to c3 before being blocked at d4
4. Bishop can only move d4 before being blocked at e5 etc
etc...I'd have to represent these scenarios as separate bitboards before multiplying by magic, shifting etc

It's starting to feel like magic bitboards are more trouble than they are worth :| but it is interesting.


Posts: 13
Joined: Wed Feb 25, 2015 7:19 am

Return to Programming and Technical Discussions

Who is online

Users browsing this forum: No registered users and 1 guest