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

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

Moderator: Andres Valverde

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

Postby lbjvg » 19 Sep 2011, 18:18

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
lbjvg
 
Posts: 2
Joined: 19 Sep 2011, 17:13

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

Postby Harald Lüßen » 20 Sep 2011, 08:47

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
User avatar
Harald Lüßen
 
Posts: 29
Joined: 09 Oct 2004, 22:39

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

Postby lbjvg » 20 Sep 2011, 18:49

Thanks Harald - it is reassuring to know I'm not on the wrong track from the start. :) - Jim
lbjvg
 
Posts: 2
Joined: 19 Sep 2011, 17:13


Return to Programming and Technical Discussions

Who is online

Users browsing this forum: No registered users and 24 guests