Computer Chess Club Archives


Search

Terms

Messages

Subject: Re: CountBits() Function

Author: James Robertson

Date: 09:41:59 01/07/99

Go up one level in this thread


On January 07, 1999 at 10:09:24, KarinsDad wrote:

>On January 07, 1999 at 09:44:39, KarinsDad wrote:
>
>>On January 07, 1999 at 02:30:08, James Robertson wrote:
>>
>>>On January 06, 1999 at 23:42:37, KarinsDad wrote:
>>>
>>>>I was reading all of the posts on the CountBits() function and couldn't for the
>>>>life of me, figure out where I would need it.
>>>>
>>>>As I was working on my evaluator tonight, I suddenly realized, DUH.
>>>>
>>>>Thanks for all of the good information there guys!
>>>>
>>>>Is there anywhere else that it is used?
>>>>
>>>>Thanks again,
>>>>
>>>>KarinsDad :)
>>>
>>>I also use BitCount() in my check evasion function. It counts the number of
>>>attackers attacking the king, which really helps decide my check evasion
>>>options. :)
>>>
>>>James
>
>James,
>
>Sorry, I posted that other message by mistake. For check evaluation, I take it
>you use this type of approach for BitCount() since only 2 bits can be set?
>
>unsigned int BitCount(unsigned_64 b)
>{
>    unsigned int n;
>    for (n = 0; b != 0; n++, b &= (b - 1));
>    return n;
>
>Or is your datastructure set up to determine x-raying pieces where a knight
>could move and then a queen puts the king in check and 2 rooks x-ray the queen
>(for a true count of how many pieces are attacking that square). If so, wouldn't
>the following code be faster?
>
>unsigned int in_multiple_check(unsigned_64 b)
>{
>    return ((b & (b - 1)) > 0);
>
>Where you do not return the count, you merely return whether you are in multiple
>checks. You could determine before you even called this routine whether you were
>in check by seeing if b > 0.
>
>KarinsDad

Good point. You just sped up my program.

James



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.