General query about bitboard

Code, algorithms, languages, construction...
Post Reply
jashwant
Posts: 4
Joined: Mon Oct 25, 2010 5:44 pm
Real Name: Jashwant

General query about bitboard

Post by jashwant » Sat Oct 30, 2010 5:19 am

I have got the concept of knight moves in bitboard. I need an array knight[64] in which all possible knight moves will be stored.
But how can I get the position of my knights in bitboard without looping through the bits of knight ??

i.e. How can I know , where my knights are placed in chessboard right now ?? And how many bitboards, I need for my chess engine ?

If someone is from C# , suggest me a good datatype for storing bitboards.

User avatar
Matthias Gemuh
Posts: 295
Joined: Wed Jun 09, 2010 2:48 pm
Contact:

Re: General query about bitboard

Post by Matthias Gemuh » Sun Oct 31, 2010 7:36 am

jashwant wrote: But how can I get the position of my knights in bitboard without looping through the bits of knight ??
If you want to avoid scanning for bits, use piece lists (updating their locations as the pieces move around).
Aided by engines, GMs can be very strong.
http://www.hylogic.de

jashwant
Posts: 4
Joined: Mon Oct 25, 2010 5:44 pm
Real Name: Jashwant

Re: General query about bitboard

Post by jashwant » Sun Oct 31, 2010 7:46 am

If you want to avoid scanning for bits, use piece lists (updating their locations as the pieces move around).
Can you explain piece list algo a little bit ? I am not getting any idea about this .

RobertP
Posts: 8
Joined: Tue Jun 22, 2010 8:36 am
Real Name: Robert Purves
Location: New Zealand

Re: General query about bitboard

Post by RobertP » Sun Oct 31, 2010 12:18 pm

I have got the concept of knight moves in bitboard. I need an array knight[64] in which all possible knight moves will be stored.
But how can I get the position of my knights in bitboard without looping through the bits of knight ??
i.e. How can I know , where my knights are placed in chessboard right now ?? And how many bitboards, I need for my chess engine ?
You need a bitscan function.
http://chessprogramming.wikispaces.com/BitScan
Its speed is critical for good performance, but you can start with something simple and optimize later. Ultimately it can be a single machine instruction.

Code: Select all

typedef struct Position {
  Bitboard      pawns, knights, bishops, rooks, queens; // required
  Bitboard      occupied; // union of above + king-square bits; used by slider attack generator
  ...
  signed char  contentOfSquare[64]; // a useful complement to the Bitboards
  ...
}

Bitboard  tempBits = thePosition.knights;
while ( tempBits ) {
  int sq = GetLowestBit( tempBits ); // bitscan
  ...there is a knight on sq...
  ClearLowestBit( &tempBits );
}

Post Reply