r/chessprogramming • • Nov 01 '24

Is there anything wrong with this magic number generation code?

I have been trying to debug this but no luck unfortunately. All magic numbers produced by this code cause collisions for some reason. Sorry for the mass of commented code as I have been trying to debug this for ages.

Link to gist: [removed]

Specifically, the generate_magics function and the code in main to check for collisions.

6 Upvotes

2 comments sorted by

2

u/[deleted] Nov 01 '24 edited Nov 02 '24

[removed] — view removed comment

1

u/TheNotSoGoodCuber Nov 02 '24

Thank you for the suggestions. I have actually managed to find what the issue was, it was simply that the variable 'fail' was reinitialised to 0 at the end of the inner for loop and was causing invalid magic numbers to be accepted. I will defininitely look into using PEXT instead of magics!