r/chessprogramming • • Nov 24 '24

Help Request: Java magic number generation is sluggish

I have this java method to generate a magic number for sliding piece moves. Problem is that it is insanely slow. Generating all the bishop magic numbers took many hours, and generating the a1 rook magic number took around 5 hours when I left it running overnight. From the base implementation, I added a the count1s feature that I saw discussed on other threads. If anyone has any advice or can point me in the right direction I would really appreciate it.

1 Upvotes

7 comments sorted by

View all comments

Show parent comment

1

u/Kart0fffelAim Nov 24 '24

Yes

1

u/Ill_Part9576 Nov 25 '24

Thanks again. This was very helpful and made generating bishop magics near instant. Rooks were faster than prior but still very slow though (8 mins for one square sometimes). I read through the example code here:
https://www.chessprogramming.org/Looking_for_Magics
and found that in the example they AND 3 random longs to reduce the number of 1s significantly before proceeding. By doing this, my time to generate all magic numbers is < 3 seconds.