Bitboard of squares between

Programming Topics (Computer Chess) and technical aspects as test techniques, book building, program tuning etc

Moderator: Andres Valverde

Re: Bitboard of squares between

Postby Sven Schüle » 21 Jun 2007, 09:57

Hi Chan,
Chan Rasjid wrote:I think most of us should easily know this is perfectly safe :-
Code: Select all
If (exprA && (w = bitboard1 | bitboard2)){
if (w & bb ){
....
}
}
I think this is perfectly unreadable :( I would prefer:
Code: Select all
if (exprA && (bitboard1 | bitboard2) && bb) {
    ....
}
or, if I really need to have 'w' separately, I would at least write:
Code: Select all
if (exprA) {
    w = bitboard1 | bitboard2;
    if (w && bb) {
        ....
    }
}
and let the optimizing compiler do its good job for me.

Putting the assignment into an expression does not give you any benefit but will introduce bugs sooner or later when using it too often.
Chan Rasjid wrote:
Code: Select all
a = b + (b = 1);//undefined
a = b + (c = c + 1);//ok
a = b + (c = c++);//undefined
You may find even more examples of the 'undefined' type, and I propose not to bother with it if your goal is writing good code.

Sven
User avatar
Sven Schüle
 
Posts: 240
Joined: 26 Sep 2004, 20:19
Location: Berlin, Germany

Re: Bitboard of squares between

Postby Gerd Isenberg » 21 Jun 2007, 12:12

Onno Garms wrote:
Gerd Isenberg wrote:to check whether a move is (pseudo) legal, one has to consider piece types anyway.


That's why I think now (having seen that squares between are difficult) that Chan's approach (with the required fixes) might be the best. In my code, queen attacks are created as rook attacks and bishop attacks anyway.


The obvious approach seems to use already existing ressources - to switch the piece-wise attack getter and to look whether their attacks intersect the target square(s). No need to waste additional memory or code for inbetween sets at all. With magic lookups for sliders it is almost a read of two cachelines for rooks/bishops and three cachelines for the queen.

A branchless solution according to your -1 idea combined with the 0x88-difference plus rotate takes nPieces*240 bitboards for the lookup tables:
Code: Select all
// is square sq2 attacked by piece on sq1?
// precondition: blocker != 0
bool isAttacked(u32 sq1, u32 sq2, u32 piece, u64 blocker)
{
    u32 x88diff = sq2 + (sq2&56) - sq1 - (sq1&56) + 120;
    blocker = _rotr64(blocker, sq1);
    return inbetweenByPieceAnd0x88Diff[piece][x88diff] & blocker == 0;
}

Gerd
Gerd Isenberg
 
Posts: 285
Joined: 31 Jan 2005, 20:31
Location: Hattingen, Germany

Re: Bitboard of squares between

Postby Chan Rasjid » 21 Jun 2007, 18:10

Code: Select all
Chan Rasjid wrote:
If (exprA && (w = bitboard1 | bitboard2)){
if (w & bb ){
....
}
}

if (exprA) {
    w = bitboard1 | bitboard2;
    if (w && bb) {
        ....
    }
}


Yes, the 2nd is the standard. Just my bad style (habit) with nothing gained.

Rasjid
Chan Rasjid
 
Posts: 73
Joined: 23 Feb 2005, 16:36
Location: Singapore

Previous

Return to Programming and Technical Discussions

Who is online

Users browsing this forum: No registered users and 18 guests