I am currently making a chess game that will include a chess bot that players can play against. However, I am stuck on the move generation function for the chess bot. I am trying to make the move generation function as optimized and as fast as possible, so I am trying to use things like bitboards and pre-computed moves to generate legal moves. Since the bit32 library supports only 32-bit integers while there are 64 squares on the chess board, I split the board in half with the default white side being the “lower” half. With this setup, I have already pre-computed the bitboards for the knight and king, but I am experiencing difficulties with the sliding pieces. For the sliding pieces, it becomes a bit more complex than the knight and king because they can have various possible moves while on the same square depending on the boards position (less moves if its blocked close to the piece, but most moves if all directions are not blocked). So, I am pre-computing moves for all possible positions for every square a sliding piece can be on (all possible blocking pieces positions). I was already able to achieve this, but I am having difficulties with storing and looking up these moves (as the blocking pieces are spread across all 64 squares, but I can’t have 64-bit indices).

What I am currently trying to implement is generating magic numbers which will be multiplied with the pieces on the board to get a smaller index that will be used to lookup a pre-computed move. I do understand the concept of this with 64-bit bitboards, but I am very confused with implementing it with the split bitboards. My current ideas are generating 2 magic numbers for each square (one for each half of the board). Does anyone have any ideas or suggestions?

I’m sorry if my explanation is hard to understand. If you are familiar with Sebastian Lague’s chess bot, I am basically trying to implement a move generator similar to his (he implemented these bitboards and magic bitboards).