Author: Robert Hyatt
Date: 14:45:04 05/29/99
Go up one level in this thread
On May 29, 1999 at 14:43:24, Frank Phillips wrote:
>On May 29, 1999 at 11:33:56, James Swafford wrote:
>
>>On May 29, 1999 at 07:55:46, Frank Phillips wrote:
>>
>>>What is the best way to extract the squares pieces are on from a piece-bitboard?
>>> For example, if whiteKnights is the bitboard representing where white knights
>>>are, how do you find the square the knights are on. Looping through the 64 bits
>>>with a mask for each possible square on the board seems slow, even if you can
>>>break out once the bitboard is empty.
>>
>>
>>do something like this:
>>
>>my_board=position.whiteknights;
>>while (my_board) {
>> // get a square
>> sq=MSB(my_board); // gets the most significant bit
>> // clear that square from the board
>> my_board^=mask[sq]; // XOR operation
>> .
>> .
>> .
>>
>>}
>>
>>
>>If you know the squares you are extracting tend to be on
>>the low order side of the board, you may want to use
>>"LSB( )" to extract least significant bits.
>>
>>I've got some more information on this on my site:
>>
>>http://home.fda.net/~wzrdking/chessprg.htm
>>
>>Good luck! :-)
>>
>>--
>>James
>
>Thanks Jmaes. But where is the MSB function?
On Intel machines, there are two instructions for this, bsf/bsr (bit scan
forward/reverse). If you want to see the .asm code, get the source for Crafty,
and look at the file x86.s, and look for FirstOne.
There are other ways... check out the source again and look at 'boolean.c'
for FirstOne() done with 1-4 table lookups...
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.