-
Notifications
You must be signed in to change notification settings - Fork 2.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Avoid misuse of StepAttacksBB for pawns #1083
Conversation
Make it explicit that first index of StepAttacksBB is a piece, not a piece type. Non functional change.
@snicolet first, also KING should be changed to W_KING:
Second, this is definitely overkill for me. StepAttacksBB[] is an array, not a function. It can be indexed by a Piece, but why not by an int or a size_t? Indeed PieceType is a strict subset of Piece and indexing StepAttacksBB[] with PieceType is fully safe and at most a very small style nuance, but the proposed "fix" is clearly less readable and needlessly pedantic IMO. |
My reasoning is that for knight, bishop, rook, queen and king it doesn't matter if we access StepAttacksBB with a piece type rather than a piece, because these five pieces move backwards as well as forwards and the result will always be correct. For instance However, for pawns StepAttacksBB[W_PAWN] and StepAttacksBB[B_PAWN] are indeed subtly different. Hence the assert in position.h to protect newcomers from misuses (in master Having put the assert in position.h, it is then natural to be more precise in the only two cases in the code where we use StepAttacksBB[PAWN] :-) Hope this helps, |
@snicolet yes, it helps :-) You are correct! |
In bitboards.cpp, Would it make sense to
|
@Rocky640: Indeed, this |
Here is a first working version. Some possible improvements: b) Maybe we can get rid of the following inline in positions.h, and use directly the PawnAttacks where applicable |
And this version only use PieceType (and not Piece) for "attacks_from" |
@Rocky640 the alternative should be simpler than original. The fist one is not, the second one is a possible candidate but I have not looked at it deep enough. |
Hmm... I agree that StepAttacks array is misdesigned. |
Anyway this patch itself is fine, so I'm going to commit it. |
Make it explicit that first index of StepAttacksBB is a piece, not a piece type.
Non functional change.