Computer Chess Club Archives


Search

Terms

Messages

Subject: Re: Question about bitboards and crafty's code

Author: Vincent Diepeveen

Date: 10:00:01 12/03/99

Go up one level in this thread


On December 03, 1999 at 12:22:05, blass uri wrote:

>1)I am interested to know if bitboards help to do programs faster relative to
>arrays of attack.

To make an array of attacks to each square is a lot slower to do,
especially adding how many times you attack a square, as you need to
summarize each specific bitboard outcome (each type of piece has its own
bitboard).

>I started to try to write a chess program and
>I think to use arrays like rookattack[i]-the number of the attacking rooks of
>square i and I am interested to know if there is a way to be faster by
>bitboards.

Bitboards at a 32 bits machine is definitely slower for anything,
at 64 bits machines it can do some things within the registers,
however you need a machine with a large amount of registers then
and some things like:
   - mobility
   - attacktables

are near to impossible to do.

For a lot of pawny things bitboards are an option though.

>2)I found this piece of code in crafty at evaluate.c
>
>if (WhiteBishops) {
>    if (WhiteBishops&mask_A7H7) {
>      if (WhiteBishops&SetMask(A7) && SetMask(B6)&BlackPawns)
>        score-=BISHOP_TRAPPED;
>      else if (WhiteBishops&SetMask(H7) && SetMask(G6)&BlackPawns)
>        score-=BISHOP_TRAPPED;
>    }
>  }
>
>a)is it possible to save time by avoiding the first line
>if (WhiteBishops)?

crafty is very tricky. you need to write out each #define before you
actually know what it is.

i suspect here that mask_a7h7 has just a bit set at a7 and h7,
so here seemingly you can leave out the if ( ... whitebishops ... )

>b)I guess that whitebishops is a 64 digits number and that this number gets 1
>for every square with a white bishop.
>I guess that mask_a7h7 gets 1 only for WhiteBishops at a7 or h7 and that the
>other 62 digits of it are 0

>Am I right?

I have no reason to assume you are wrong :)

>c)what do the 64 bit numbers SetMask(A7),Setmask(B6) mean?

write out the define of SetMask(..)

>d)Do bitboards help to evaluate the trapped bishop faster relative to evaluating
>the same information without bitboards?

At a 32 bits processor not (assuming everything within the L1 cache),

I prefer writing more general code, instead of writing out both
black and white. Code reusability is a cool thing!

if( sqtrapped[sq] ) { ..
.. }

Ok please add now also whether the square at a7 is attacked.
In diep i just do:

   if( sqbishoptrapped[side][sq] ) {
     if( OpponentAttack[sq] ) {
       ..
     }
     else {
       ..
     }
   }

So at a 64 bits machine obviously
  if (WhiteBishops&mask_A7H7)

might be faster than
  sqbishoptrapped[side][sq]

However you win that back BIGTIME with:
  OpponentAttack[sq]

Where bitboards needs a special function to do that.
In case of pregenerated attackbitboards you need to
summarize it (sq is now a bit set to 1 at the square where the
bishop is located):

   if( WhiteBishop&(bpawnAtt|bknightAtt|bbishopAtt|bqueenatt|bkingatt|brookatt)
)

Now even more difficult is to get out of the bitboards the
NUMBER of attacks in a quick way. Bitboards are a handicap there!

To get in diep the number of attackers i just do:
    (OppAttack[sq]&15)

Try to do that in bitboards at the same speed :)

Another disadvantage also must be clear here: bitboards in crafty are not
general code. they are written out by both black and for white. In diep
i'm using general code. I wonder what in this area is preferred more.
I go for the general code...

>Uri



This page took 0 seconds to execute

Last modified: Thu, 15 Apr 21 08:11:13 -0700

Current Computer Chess Club Forums at Talkchess. This site by Sean Mintz.