sinandredemption/M42

Expected to find parallel generator functions (e.g. uint64_t rookMoves(uint64_t bbrooks, uint64_t occupation))

Closed this issue · 1 comments

With the current set of functions, one still has to iterate a (classic?!) board square by square, have a switch case over square value and call the bit board functions.
I cannot see how that is efficient, given a chess engine already has bit boards for Rooks,Queens, Kings, Bishops etc.
So, in addition to the existing functions of the form uint64_t xxx_attacks(int square, uint64_t occupation),
should there not be also functions of the form uint64_t rook_attacks(uint64_t rooks_bb, uint64_t occupation)?

Also, I wonder if there should be functions of the form xxx_attacks(uint64_t xxx_bb, uint64_t own_occupation, uint64_t opponent_occupation) in order to actually create pseudo legal moves without much post-processing. But maybe those are redundant and as such justified to not exist.

There can be overlap in attack bitboards of all similar pieces on the board, hence the need to iterate over each piece separately. For example, if two rooks are on the same file, the attack bitboard will have all squares between the two rooks set. For situations like that, it seems simpler to separate each pieces' attack bitboard, than to determine if a square is being attacked by more than one pieces.
Also, it's actually very efficient to iterate and get squares occupied by the piece given the piece bitboard.
while (piece_bb != 0) {

sq = lsb(piece_bb);

// do something with sq

piece_bb &= piece_bb - 1; // clear last set bit

}
Note that we didn't iterate over each square of the chess board.

Regarding your last proposal, let's call it pseudolegal_attacks(), it would be equivalent to piece_attacks() & ~own_occupation. So yes, it is kinda redundant :)

Please don't mind my formatting, I'm kinda new to github online :)