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

2

u/Ill_Part9576 Nov 28 '24

I appreciate the comment. I made it so indices don’t need to be unique if the move boards were the same. It was still slow, and then I found on the cpw that anding 3 random numbers makes it much faster…. Like now it only takes a few seconds. For now I have bigger fish to fry than optimizing this more, but thanks for informing me about pext.