bitboard of queening squares

Discussion of chess software programming and technical issues.

Moderator: Ras

User avatar
rvida
Posts: 481
Joined: Thu Apr 16, 2009 12:00 pm
Location: Slovakia, EU

bitboard of queening squares

Post by rvida »

I'm looking for a (fast) way to get a bitboard of queening squares from pawn occupancy bitboard.

Code: Select all

get_queening_squares<Colour c>(Bitboard pawns);


input:          output (for white):

00000000        01010011
00000000        00000000
00000000        00000000
00000000        00000000
00010000  ->    00000000
00000011        00000000
01000000        00000000
00000000        00000000

Any ideas?

Richard
bob
Posts: 20943
Joined: Mon Feb 27, 2006 7:30 pm
Location: Birmingham, AL

Re: bitboard of queening squares

Post by bob »

rvida wrote:I'm looking for a (fast) way to get a bitboard of queening squares from pawn occupancy bitboard.

Code: Select all

get_queening_squares<Colour c>(Bitboard pawns);


input:          output (for white):

00000000        01010011
00000000        00000000
00000000        00000000
00000000        00000000
00010000  ->    00000000
00000011        00000000
01000000        00000000
00000000        00000000

Any ideas?

Richard
The most obvious is to take the 64 bit value, split it in half, and OR the results together. Do this two more times and you are done. Or you can do as I do and wait until you extract a pawn's square from that array of bits, and then compute that pawn's queening square directly.

Without any thought, assuming p_square=0-63 where 56-63 are the squares white pawns queen on, this would work:

queen_square = (side) p_square | 070 : p_square & 007;

side=1 is white pawn, 0 for black.
User avatar
rvida
Posts: 481
Joined: Thu Apr 16, 2009 12:00 pm
Location: Slovakia, EU

Re: bitboard of queening squares

Post by rvida »

bob wrote: The most obvious is to take the 64 bit value, split it in half, and OR the results together. Do this two more times and you are done.
Thanks Bob, this is exactly what I wanted.

Not tried it yet, but I think the following should do the job:

Code: Select all

Bitboard queening_squares<Colour c>(Bitboard pawns) {

  Bitboard b;
  if (c == WHITE) {
    b = pawns | pawns << 32;
    b |= b << 16;
    b |= b << 8;
    return (b & BB_RANK_8);
  }
  else {
    b = pawns | pawns >> 32;  
    b |= b >> 16;             
    b |= b >> 8;              
    return (b & BB_RANK_1);
  }
}
Gerd Isenberg
Posts: 2251
Joined: Wed Mar 08, 2006 8:47 pm
Location: Hattingen, Germany

Re: bitboard of queening squares

Post by Gerd Isenberg »

rvida wrote:
bob wrote: The most obvious is to take the 64 bit value, split it in half, and OR the results together. Do this two more times and you are done.
Thanks Bob, this is exactly what I wanted.

Not tried it yet, but I think the following should do the job:

Code: Select all

Bitboard queening_squares<Colour c>(Bitboard pawns) {

  Bitboard b;
  if (c == WHITE) {
    b = pawns | pawns << 32;
    b |= b << 16;
    b |= b << 8;
    return (b & BB_RANK_8);
  }
  else {
    b = pawns | pawns >> 32;  
    b |= b >> 16;             
    b |= b >> 8;              
    return (b & BB_RANK_1);
  }
}
Yep, it is worth to even keep the pawn fills a while, for spans, passers, half open files, etc..