Kindergarten Bitboard Approach by Gerd Isenberg

Discussion of chess software programming and technical issues.

Moderators: hgm, Rebel, chrisw

Edsel Apostol
Posts: 803
Joined: Mon Jul 17, 2006 5:53 am
Full name: Edsel Apostol

Kindergarten Bitboard Approach by Gerd Isenberg

Post by Edsel Apostol »

I noticed that in my 32 bit engine, Kindergarten Bitboard Approach is a little bit faster compared to that of Olithink bitboard method. It is more elegant and uses less memory. But what I like about the Olithink method is that it has X-ray attacks and it makes my routines for pinned and discovered pieces faster.

Is there a way to modify Kindergarten Bitboard Approach to support X-ray attacks just like the Olithink bitboard method?
Gerd Isenberg
Posts: 2250
Joined: Wed Mar 08, 2006 8:47 pm
Location: Hattingen, Germany

Re: Kindergarten Bitboard Approach by Gerd Isenberg

Post by Gerd Isenberg »

Edsel Apostol wrote:I noticed that in my 32 bit engine, Kindergarten Bitboard Approach is a little bit faster compared to that of Olithink bitboard method. It is more elegant and uses less memory. But what I like about the Olithink method is that it has X-ray attacks and it makes my routines for pinned and discovered pieces faster.

Is there a way to modify Kindergarten Bitboard Approach to support X-ray attacks just like the Olithink bitboard method?
Hi Edsel,

yes, see X-ray Attacks, chapter X-rays with one Lookup.
I is only a matter to initialize the lookup tables accordantly.

Gerd
Edsel Apostol
Posts: 803
Joined: Mon Jul 17, 2006 5:53 am
Full name: Edsel Apostol

Re: Kindergarten Bitboard Approach by Gerd Isenberg

Post by Edsel Apostol »

Thanks Gerd.

CPW is a great resource indeed. I should have browse it first before asking here.

By the way, I found this code in one of your posts in the links:

Code: Select all

rookWise  = rookAttacks(occ, kiSq);
potPinned = rookWise & ownPieces;
xrays     = rookWise ^ rookAttacks(occ ^ potPinned, kiSq);
pinners   = xrays    & oppoRookOrQueen;

pinned    = 0;
while ( pinners )
{
    pinnerSq = bitScanForward(pinners);
    pinned  |= potPinned & obstructed[pinnerSq][kiSq]);
    pinners &= pinners - 1;
}
... same for bishops/queens 
Is your code above faster than my implementation below?

Code: Select all

u64 pinnedPieces(const position_t *pos, u32 c) {
    u64 b, pin, pinners; int t, ksq;
	pin = 0ULL;
	ksq = pos->kpos[c];
	pinners = pos->color[c^1] & (pos->queens|pos->rooks);
	if(pinners){
    	b = rookAttacksBBX(ksq, pos->occupied) & pinners;
    	while (b) {
    		t = popFirstBit(&b);
    		pin |= InBetween[t][ksq] & pos->color[c];
    	}
    }
	pinners = pos->color[c^1] & (pos->queens|pos->bishops);
	if(pinners){
    	b = bishopAttacksBBX(ksq, pos->occupied) & pinners;
    	while (b) {
    		t = popFirstBit(&b);
    		pin |= InBetween[t][ksq] & pos->color[c];
    	}
    }
	return pin;
}
rookAttacksBBX and bishopAttacksBBX are xray attacks using Olithink method. That's why I'm asking if there's an equivalent routine for that in Kindergarten Bitboard method as I want my engine to use less memory and have an elegant code.
Gerd Isenberg
Posts: 2250
Joined: Wed Mar 08, 2006 8:47 pm
Location: Hattingen, Germany

Re: Kindergarten Bitboard Approach by Gerd Isenberg

Post by Gerd Isenberg »

Edsel Apostol wrote:Thanks Gerd.

CPW is a great resource indeed. I should have browse it first before asking here.

By the way, I found this code in one of your posts in the links:

Code: Select all

rookWise  = rookAttacks(occ, kiSq);
potPinned = rookWise & ownPieces;
xrays     = rookWise ^ rookAttacks(occ ^ potPinned, kiSq);
pinners   = xrays    & oppoRookOrQueen;

pinned    = 0;
while ( pinners )
{
    pinnerSq = bitScanForward(pinners);
    pinned  |= potPinned & obstructed[pinnerSq][kiSq]);
    pinners &= pinners - 1;
}
... same for bishops/queens 
Is your code above faster than my implementation below?

Code: Select all

u64 pinnedPieces(const position_t *pos, u32 c) {
    u64 b, pin, pinners; int t, ksq;
	pin = 0ULL;
	ksq = pos->kpos[c];
	pinners = pos->color[c^1] & (pos->queens|pos->rooks);
	if(pinners){
    	b = rookAttacksBBX(ksq, pos->occupied) & pinners;
    	while (b) {
    		t = popFirstBit(&b);
    		pin |= InBetween[t][ksq] & pos->color[c];
    	}
    }
	pinners = pos->color[c^1] & (pos->queens|pos->bishops);
	if(pinners){
    	b = bishopAttacksBBX(ksq, pos->occupied) & pinners;
    	while (b) {
    		t = popFirstBit(&b);
    		pin |= InBetween[t][ksq] & pos->color[c];
    	}
    }
	return pin;
}
rookAttacksBBX and bishopAttacksBBX are xray attacks using Olithink method. That's why I'm asking if there's an equivalent routine for that in Kindergarten Bitboard method as I want my engine to use less memory and have an elegant code.
Hard to say - I neither use the one or the other, but fill algorithms with intersection of dir attacks of sliding pieces with opposite dir of king as slider. The mentioned routines can not been considered isolated, but together with surrounding code, and whether sub-expressions are reused or explicitly cached, also in the context of dicovered checks and whether kings are vulnerable to distant checks in eval and check move-generation etc ...

As I already said, in your mentioned post, the X-ray lookup seems the faster precondition for

Code: Select all

opponentSlider -> anyPiece -> ownKing 
while the other approach already determines the pinners but no discovered checks by the opponent

Code: Select all

opponentSlider -> ownPiece -> ownKing 
and may postpone the loop to get pinned pieces, since each pinner implies one pinned piece.