Code: Select all
else if (sq == pos->ep_sq && p == PAWN)
{
occ ^= (1ULL << (sq ^ 8));
gain[0] = piece_value[PAWN];
}
Can someone explain this
Code: Select all
occ ^= (1ULL << (sq ^ 8));
Thanks
Moderators: hgm, Rebel, chrisw
Code: Select all
else if (sq == pos->ep_sq && p == PAWN)
{
occ ^= (1ULL << (sq ^ 8));
gain[0] = piece_value[PAWN];
}
Code: Select all
occ ^= (1ULL << (sq ^ 8));
For me this is not so much about bitboards but about 6-bit square numbering (although you may state that this numbering system is most common in bitboard engines ...). In a system where squares are numbered from 0 to 63 rank by rank (so that bits 0-2 contain the file part and bits 3-5 the rank part) the operation "sq ^ 8" toggles the rank betwen 0 and 1, 2 and 3, 4 and 5, or 6 and 7, which can be useful in some areas, one of them being the manipulation of square numbers related to en passant.xr_a_y wrote: ↑Mon Dec 31, 2018 4:11 pm That was of course what I suspected but now I understand, this is toggling the fourth bit ... so between 24 (b01000) and 31(b11111) this removes the 1 in the fourth bit so it gives the number minus 8 and between 32 (b100000) and 39 (b100111) this add a 1 in the fourth bit so it gives the number plus 8.
Tricky ... Bitboards are amazing ...
The line better has been a named function, so you can comprehend what it is doing.xr_a_y wrote: ↑Mon Dec 31, 2018 2:13 pm In xiphos SEE, one can read
about the case where the destination square (sq) of the initial move is the ep move.Code: Select all
else if (sq == pos->ep_sq && p == PAWN) { occ ^= (1ULL << (sq ^ 8)); gain[0] = piece_value[PAWN]; }
Can someone explain this, I don't get it.Code: Select all
occ ^= (1ULL << (sq ^ 8));
Thanks
No, is ordinary.D Sceviour wrote: ↑Mon Dec 31, 2018 5:51 pm This a very fast way of finding the en passant square for either move color. I have never seen the use of XOR (sq ^ 8) in any other code before. Is Xiphos the first to use this?
I also found (sq ^ 8) at one place in Rodent 1.6. Since I do not have many open-source chess engine versions on my harddisk I guess this is sort of a random hit and probably many others have already used that trick.D Sceviour wrote: ↑Mon Dec 31, 2018 5:51 pm This a very fast way of finding the en passant square for either move color. I have never seen the use of XOR (sq ^ 8) in any other code before. Is Xiphos the first to use this?
Micro-Max (which is a mailbox engine) has used it from the beginning (i.e. the first version that implemented e.p.):D Sceviour wrote: ↑Mon Dec 31, 2018 5:51 pm This a very fast way of finding the en passant square for either move color. I have never seen the use of XOR (sq ^ 8) in any other code before. Is Xiphos the first to use this?
Code: Select all
if(p<3&y==E)H=y^16; /* shift capt.sqr. H if e.p.*/
Code: Select all
if(PieceType<3 & ToSqr==epSqr)
CaptSqr = ToSqr^16; /* shift CaptSqr if e.p. */