Page 1 of 1

Who's on d4? Help me understand bitboards...

PostPosted: 19 Sep 2011, 18:18
by lbjvg
Hi - I am just starting the process of writing my own chess engine in Python. I want to use bitboard representations and want to make sure I am clear on one point before I go any further: and that is how to tell which piece is on which square. As best I can tell, maintaining a table of which piece is on which square is how its done. I can't come up with any better solution. (a possible alternative would be to AND all my piece bitboards together with each board position). If there is a better method please rely and let me know. Thanks.


//edited to make shorter

Re: Who's on d4? Help me understand bitboards...

PostPosted: 20 Sep 2011, 08:47
by Harald Lüßen
There are the typical bitboard variables like
unsigned long long wpawns, bpawns, wknights, bknights, ...; // or uint64_t
You can do almost everything you need with these alone.
But there are situations like: what is the opponent piece that I capture on d4?
The typical solution for this is indeed an array
char pieces[64]; // filled with piece types WPawn=1, BPawn=-1, ...
Many chess engines do this.

The idea
bb1bit = makeBitboard1Bit[sq];
if (bb1bit & bpawns) ... else if (bb1bit & bknights) ...
is far too slow and unreadable.

Harald

Re: Who's on d4? Help me understand bitboards...

PostPosted: 20 Sep 2011, 18:49
by lbjvg
Thanks Harald - it is reassuring to know I'm not on the wrong track from the start. :) - Jim