Author: Johan Wessfeldt
Date: 10:38:49 08/13/03
Go up one level in this thread
On August 13, 2003 at 13:06:06, Mathieu Pagé wrote:
>On August 13, 2003 at 12:38:40, Johan Wessfeldt wrote:
>
>>Im developing a chess engine in java and Im done with the move-generation.
>>Ive run a couple of tests and so far so good. No perf-test failures yet! :]
>>
>>Ive discovered my Least significant Bit method is really slowing me down tho..
>>
>>The best Ive come up with so far goes like this:
>>
>>private int lsb(long a){
>>for(int i=63;i>0;i--){
>> if( (a & mask[i] ) == mask[i] ){
>> return i; }
>>}
>>return 0;
>>}
>>
>>where mask[] is a vector of all the combinations.. like mask[0] = 0001, mask[1]
>>= 00010, mask[3] = 00100 ... and so on.
>>
>>Ive tried some well known methods but with no results since Java's long(64 bits)
>>datatype is signed. It messes up the bits..
>>
>>(All datatypes in Java are signed)
>>
>>Anyone have any suggesitons on how to optimize this method?
>
>Here is (aproximately (i'dont have the code near)) what i do. It is in C++ but
>could probably be translated in Java easily.
>
>int GetLsb(BitBoard bit)
>{
> int lsb = 0;
>
> if (bit & 0xFFFFFFFF == 0)
> {
> lsb+=32;
> bit >>= 32;
> }
>
> if (bit & 0xFFFF == 0)
> {
> lsb+=16;
> bit >>= 16;
> }
>
> if (bit & 0xFF == 0)
> {
> lsb+=8;
> bit >>= 8;
> }
>
> return lookUpTable[bit] + lsb;
>}
>
>in this code lookUpTable is a table with the position of the lsb for each index
>from 0 to 255.
>
>hope it is clear and help
>
>Mathieu Pagé
>pagemathieu at hotmail dot com
Nice piece o hack, I'll try this one out. Thanks! :]
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.