bitboard list of usable bitboards

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

Moderator: Andres Valverde

bitboard list of usable bitboards

Postby smcracraft » 16 Jan 2006, 19:23

Hi - I have added bitboarding to my evaluation routine capability,
using standard 64-bit representation.

Now I need a large set of representative #define's or variables
that have various bitboards set and I do not want to have
to calculate them myself.

I want to #include them from an existing file and then just use
them in my routines.

An example is all squares in front of a pawn at square e4 that
would have to not have enemy pawn in order for the above pawn
to classify as a passed pawn.

If such a "list of bitboards" exists, please let me know where I can get
it. It will save me much time.

Thanks,

Stuart
smcracraft
 
Posts: 65
Joined: 15 Jan 2006, 05:38

Re: bitboard list of usable bitboards

Postby Gerd Isenberg » 16 Jan 2006, 19:56

Hi Stuart,

well it is a nice lesson to define some const bitboards by your own, according to your mapping ;-)

I have for instance:
Code: Select all
const BitBoard  notA = 0xfefefefefefefefe;
const BitBoard  notH = 0x7f7f7f7f7f7f7f7f;

For front and attack spans for a paticular square of a white/black pawn, i suggest to define a const for a particular (say b2) square and to initialize the other 47 masks by a loop and some shifting/anding.

You may also use some fill-stuff to compute passers setwise.
Let say you are looking for white passers.
Simply take the set of black pawns with the union of black pawn attacks.
Shift them down one rank - or, two ranks - or, four ranks - or.

Code: Select all
blackdown  = blackPawns | blackPawnAttacks(blackPawns);
blackdown |= blackdown >> 8;
blackdown |= blackdown >> 16;
blackdown |= blackdown >> 32;

black pawns      black pawns and attacks shifted down:
0 0 0 0 0 0 0 0   0 0 0 0 0 0 0 0
0 1 0 0 0 0 0 0   0 1 0 0 0 0 0 0
0 0 0 1 0 0 0 0   1 1 1 1 0 0 0 0
0 0 0 0 0 0 0 0   1 1 1 1 1 0 0 0
0 0 1 0 0 0 0 0   1 1 1 1 1 0 0 0
0 0 0 0 0 0 0 0   1 1 1 1 1 0 0 0
0 0 0 0 0 0 0 0   1 1 1 1 1 0 0 0
0 0 0 0 0 0 0 0   1 1 1 1 1 0 0 0


Now, all white pawns inside the resulting one-set are _no_ passers.
White pawns anded with the complement of the black-down fill are passers.

Code: Select all
whitePassers = whitePawns & ~blackdown;

Cheers,
Gerd
Gerd Isenberg
 
Posts: 285
Joined: 31 Jan 2005, 20:31
Location: Hattingen, Germany

Re: bitboard list of usable bitboards

Postby smcracraft » 16 Jan 2006, 23:51

Gerd Isenberg wrote:Hi Stuart,

well it is a nice lesson to define some const bitboards by your own, according to your mapping ;-)

I have for instance:
Code: Select all
const BitBoard  notA = 0xfefefefefefefefe;
const BitBoard  notH = 0x7f7f7f7f7f7f7f7f;

For front and attack spans for a paticular square of a white/black pawn, i suggest to define a const for a particular (say b2) square and to initialize the other 47 masks by a loop and some shifting/anding.

You may also use some fill-stuff to compute passers setwise.
Let say you are looking for white passers.
Simply take the set of black pawns with the union of black pawn attacks.
Shift them down one rank - or, two ranks - or, four ranks - or.

Code: Select all
blackdown  = blackPawns | blackPawnAttacks(blackPawns);
blackdown |= blackdown >> 8;
blackdown |= blackdown >> 16;
blackdown |= blackdown >> 32;

black pawns      black pawns and attacks shifted down:
0 0 0 0 0 0 0 0   0 0 0 0 0 0 0 0
0 1 0 0 0 0 0 0   0 1 0 0 0 0 0 0
0 0 0 1 0 0 0 0   1 1 1 1 0 0 0 0
0 0 0 0 0 0 0 0   1 1 1 1 1 0 0 0
0 0 1 0 0 0 0 0   1 1 1 1 1 0 0 0
0 0 0 0 0 0 0 0   1 1 1 1 1 0 0 0
0 0 0 0 0 0 0 0   1 1 1 1 1 0 0 0
0 0 0 0 0 0 0 0   1 1 1 1 1 0 0 0


Now, all white pawns inside the resulting one-set are _no_ passers.
White pawns anded with the complement of the black-down fill are passers.

Code: Select all
whitePassers = whitePawns & ~blackdown;

Cheers,
Gerd


Hi Gerd - this is really quite elegant and was just what I was looking for:
a fairly fast, though not so fast as pure table lookup, to compute it
with bitboards. I am indebted for your providing and will use this in
my program. Many thanks.

If you are curious about the group (automated evaluation
tuning), please enjoy:

http://groups.yahoo.com/group/chesstune/

--Stuart
smcracraft
 
Posts: 65
Joined: 15 Jan 2006, 05:38

Re: bitboard list of usable bitboards

Postby Leen Ammeraal » 17 Jan 2006, 07:54

smcracraft wrote:Hi Gerd - this is really quite elegant and was just what I was looking for:
a fairly fast, though not so fast as pure table lookup, to compute it
with bitboards. I am indebted for your providing and will use this in
my program. Many thanks.
--Stuart


Since these bitboard values remain constant, they need to be computed
only once, that is, when your engine starts. So why bother about
these computations being fast? I compute many such bitboard values
during program initialization in straightforward, but not particularly fast
loops. If I could easily write them as initialized arrays, I would do this,
hoping that declaring these arrays as const would speed up
their use. However, using assignment statements, as Gerd does, makes
this use of const impossible, just like programming with loops does.
Leen Ammeraal
User avatar
Leen Ammeraal
 
Posts: 63
Joined: 14 Oct 2004, 19:46

Re: bitboard list of usable bitboards

Postby Gerd Isenberg » 17 Jan 2006, 08:17

Leen Ammeraal wrote:
smcracraft wrote:Hi Gerd - this is really quite elegant and was just what I was looking for:
a fairly fast, though not so fast as pure table lookup, to compute it
with bitboards. I am indebted for your providing and will use this in
my program. Many thanks.
--Stuart


Since these bitboard values remain constant, they need to be computed
only once, that is, when your engine starts. So why bother about
these computations being fast? I compute many such bitboard values
during program initialization in straightforward, but not particularly fast
loops. If I could easily write them as initialized arrays, I would do this,
hoping that declaring these arrays as const would speed up
their use. However, using assignment statements, as Gerd does, makes
this use of const impossible, just like programming with loops does.
Leen Ammeraal


Hi Leen,

well - of course, the fill-approach might me used to initialize "read only" bitboards for spans/attacks-spans for all potential pawn squares, to later determine whether a particular pawn is a passer or not by a simple "and" of the front-spans[sq] with opposite pawns

But my intention of the frontspan-filler is indeed to determine a set of all passers in parallel on the fly. With one additional "and" with precalculated "inside kingsquare-set" indexed by opposite king it is even possible to get all passers outside the opposite kingsquare.
Similar is also possible with candidate passers.

Of course, if you hash this stuff in a pawn-hashtable counting cycles is not so important here.

Gerd
Gerd Isenberg
 
Posts: 285
Joined: 31 Jan 2005, 20:31
Location: Hattingen, Germany

Re: bitboard list of usable bitboards

Postby Alessandro Scotti » 17 Jan 2006, 08:28

In Kiwi almost all values are initialized manually (Visual C++ 4.0 did not like 64-bit constants at the time). After struggling with bit masks for a while, I have written a very simple function to draw bit rectangles on a bitboard, sort of:

Code: Select all
static void drawBitRectangle( BitBoard & bb, int file1, int rank1, int file2, int rank2 );


For me, the great advantage of using this function is visualization: it makes it very easy to create a bitboard with what you have in mind. It also performs clipping just like a graphics primitive, so you don't have to worry about special cases at the edges...
User avatar
Alessandro Scotti
 
Posts: 306
Joined: 20 Nov 2004, 00:10
Location: Rome, Italy

Re: bitboard list of usable bitboards

Postby Gerd Isenberg » 17 Jan 2006, 08:29

smcracraft wrote:Hi Gerd - this is really quite elegant and was just what I was looking for:
a fairly fast, though not so fast as pure table lookup, to compute it
with bitboards. I am indebted for your providing and will use this in
my program. Many thanks.

If you are curious about the group (automated evaluation
tuning), please enjoy:

http://groups.yahoo.com/group/chesstune/
--Stuart


"not so fast" is relativ - the fillstuff has three 64-bit mov,shift,or and one final not/and for all pawns at once. In 64-bit mode rather cheap.
Otherwise you have up to eight ands with memory lookup for one side to determine whether one particular pawn is a passer or not...

Working setwise implements a kind of loop hoisting.

Gerd
Gerd Isenberg
 
Posts: 285
Joined: 31 Jan 2005, 20:31
Location: Hattingen, Germany

Re: bitboard list of usable bitboards

Postby Tony van Roon-Werten » 17 Jan 2006, 09:23

Alessandro Scotti wrote:In Kiwi almost all values are initialized manually (Visual C++ 4.0 did not like 64-bit constants at the time). After struggling with bit masks for a while, I have written a very simple function to draw bit rectangles on a bitboard, sort of:

Code: Select all
static void drawBitRectangle( BitBoard & bb, int file1, int rank1, int file2, int rank2 );


For me, the great advantage of using this function is visualization: it makes it very easy to create a bitboard with what you have in mind. It also performs clipping just like a graphics primitive, so you don't have to worry about special cases at the edges...


I've found this little code to be VERY important

void ShowBB(unsigned __int64 bb)
{
int x,y,nr;
unsigned __int64 temp;

fprintf(stdout,"\n");
for (y=7;y>=0;y--)
{
for (x=0;x<8;x++)
{
nr=(y*8)+x;
temp=(unsigned __int64)1 <<nr;
if (bb & temp) fprintf(stdout,"1");
else fprintf(stdout,"0");
}
fprintf(stdout,"\n");
}
}


Tony
Tony van Roon-Werten
 
Posts: 99
Joined: 02 Oct 2004, 15:31
Location: 's Hertogenbosch, Netherlands

Re: bitboard list of usable bitboards

Postby Leen Ammeraal » 17 Jan 2006, 09:34

Gerd Isenberg wrote:
Hi Leen,

well - of course, the fill-approach might me used to initialize "read only" bitboards for spans/attacks-spans for all potential pawn squares, to later determine whether a particular pawn is a passer or not by a simple "and" of the front-spans[sq] with opposite pawns

But my intention of the frontspan-filler is indeed to determine a set of all passers in parallel on the fly. With one additional "and" with precalculated "inside kingsquare-set" indexed by opposite king it is even possible to get all passers outside the opposite kingsquare.
Similar is also possible with candidate passers.

Of course, if you hash this stuff in a pawn-hashtable counting cycles is not so important here.

Gerd


Hi Gerd,
Reading your reaction, it took me some time to understand what
you are talking about. But reading also your first message about
passers more carefully, I saw that, as usual, these idea of yours
are not only clever but also useful. So far, I looped through
all my white pawns to see if there is a passer, but I will now also
try your method to see if that is faster.
By the way, your answers always remind me of someone explaining
differential equations to someone who asks how to solve a simple
linear equation.
Leen
User avatar
Leen Ammeraal
 
Posts: 63
Joined: 14 Oct 2004, 19:46

Re: bitboard list of usable bitboards

Postby Gerd Isenberg » 17 Jan 2006, 19:05

Leen Ammeraal wrote:Hi Gerd,
Reading your reaction, it took me some time to understand what
you are talking about. But reading also your first message about
passers more carefully, I saw that, as usual, these idea of yours
are not only clever but also useful. So far, I looped through
all my white pawns to see if there is a passer, but I will now also
try your method to see if that is faster.
By the way, your answers always remind me of someone explaining
differential equations to someone who asks how to solve a simple
linear equation.
Leen


Hehe, really? Maybe too much thinking bitboards ;-)
The Kogge-Stone fill stuff ideas are from Steffan Westcott. There are also occluded versions, on 64-bit architectures nice to generate sliding attacks - all setwise:

Code: Select all
BitBoard fillDownOccl(BitBoard gen, BitBoard pro) {
   gen |= pro & (gen >>  8);
   pro  = pro & (pro >>  8);
   gen |= pro & (gen >> 16);
   pro  = pro & (pro >> 16);
   gen |= pro & (gen >> 32);
   return gen;
}
 
BitBoard down (BitBoard b) {return  b>>8;}

BitBoard getDownAttacks (BitBoard rooks, BitBoard empty) {
   return down (fillDownOccl(rooks, empty));
}


Cheers,
Gerd
Gerd Isenberg
 
Posts: 285
Joined: 31 Jan 2005, 20:31
Location: Hattingen, Germany

Re: bitboard list of usable bitboards

Postby smcracraft » 17 Jan 2006, 20:21

Gerd's suggestion is now implemented in my program TeeDee and
provides passed pawn knowledge for terminal nodes. It is the first
passed pawn knowledge the program has. The pawn hashing
lookup is typically 90%-99% so the knowledge has to be "worked"
only 1%-10% of the terminal nodes. (I don't use lazy eval currently.)

This was verified with a series of runs where the passed pawns are listed
on the chess board in 1/0 bitmaps that correspond to the 8x8
traditional boards (printed the same way for easy reference.)

I have not yet tied the passers to rank but this will be a minor
effort (with significant advantage) but it is currently tied to game stage
with later-game passed pawns getting increasingly more value..

I also should probably tie it to which file the passer is on as well.

So something like

difference_of_file_of_passer_from_de_columns * <= max of 3
rank_of_passer * <= max of 7
game_stage * <= this is 1 through 10
passed_pawn_base_bonus <= probably start with 25

So the maximum award would be about 5 millipawns (5250)
(3*7*10*25) for a passed pawn on the a/h files on the 7th rank
in the final game stage (pretty much only pawns and kings.

Anyway, that's what I'm thinking of...

Stuart
smcracraft
 
Posts: 65
Joined: 15 Jan 2006, 05:38

Re: bitboard list of usable bitboards

Postby smcracraft » 25 Jan 2006, 19:47

Gerd Isenberg wrote:
smcracraft wrote:Hi Gerd - this is really quite elegant and was just what I was looking for:
a fairly fast, though not so fast as pure table lookup, to compute it
with bitboards. I am indebted for your providing and will use this in
my program. Many thanks.

If you are curious about the group (automated evaluation
tuning), please enjoy:

http://groups.yahoo.com/group/chesstune/
--Stuart


"not so fast" is relativ - the fillstuff has three 64-bit mov,shift,or and one final not/and for all pawns at once. In 64-bit mode rather cheap.
Otherwise you have up to eight ands with memory lookup for one side to determine whether one particular pawn is a passer or not...

Working setwise implements a kind of loop hoisting.

Gerd


No problem - the goal of my program is not high speed efficiency.

Just a practical program to use for automated learning.
smcracraft
 
Posts: 65
Joined: 15 Jan 2006, 05:38

Pins

Postby milix » 25 Jan 2006, 21:58

I use the following code for statically detecting black pinned pieces by white bishops:

Code: Select all
if (sq < bking && SameDiag(sq,bking)) {
   bb = a1h8atcks(bking);
   if (!(bb & mask[sq])) bb = a8h1atcks(bking);
   bb &= (pieces & ~allpawns & BoardInFront[Rank(sq)]);
   if (bb && !(bb & (bb-1))) {
      // there is a pin, handle it
   }
}


where
sq=bishop's square
bking = black's king square
pieces = black's pieces
BoardInFront for example of rank 4 is the bitboard of ranks 5 through 8.
In my implementation, A8 is 0 and H1 is 63
Anastasios Milikas
milix
 
Posts: 54
Joined: 04 Nov 2004, 19:36
Location: Greece


Return to Programming and Technical Discussions

Who is online

Users browsing this forum: No registered users and 21 guests