Computer Chess Club Archives


Search

Terms

Messages

Subject: Re: How to do the following in the fastest way?

Author: Uri Blass

Date: 07:32:22 06/26/01

Go up one level in this thread


On June 26, 2001 at 10:08:31, Leen Ammeraal wrote:

>On June 26, 2001 at 08:48:19, Uri Blass wrote:
>
>>This question is important for my move generator
>>
>>dirnow is a 16 bit non negative integer and I want to translate it to an array
>>that include the place of it's digit.
>>example:
>>Suppose dirnow=131=2^7+2^1+2^0
>>I want to get from dirnow the following information:
>> directionsq[0]=7
>> directionsq[1]=1
>> directionsq[2]=0
>>
>>In most of the cases dirnow is a number with a lot of 0's and only few 1's.
>>
>>How to do it in the fastest way?
>>
>>one possible way is to use big arrays
>>a[65536][16]
>>weight[65536];
>>
>>This arrays should be calculated only one time and I get
>>
>>a[131][0]=7
>>a[131][1]=1
>>a[131][2]=0
>>weight[131]=3
>>
>>in this case I only need to do
>>i=0;
>>while (i<weight[dirnow])
>>  directionsq[i]==a[dirnow][i];
>>
>>The number of commands seem to be very small but I am afraid that big arrays may
>>do the program slower.
>>
>>Another way  is to use the following small arrays
>>a[256][8]
>>weight[256]
>>
>>In this case I need to do something like
>>i=0;
>>While (i<weight[dirnow&(1<<16-1<<8)>>8])
>>  directionsq[i]=8+a[(dirnow&(1<<16-1<<8))>>8][i];
>>j=0;
>>While (j<weight[dirnow&255])
>> directionsq[i+j]=a[(dirnow&255)][j];
>>
>>I decided to write 1<<16-1<<8 to do it more simple to understand and I think to
>>use an exact number in my move generator.
>>
>>Uri
>
>
>Is this what you mean? And would it be
>fast enough?
>
>int n = 0;
>for (int i=15; i>=0; --i)
>   if (dirnow & (1 << i))
>      directions[n++] = i;
>
>Leen Ammeraal

Yes
It is what I mean.

I am not sure if it is fast enough because usually dirnow has only few 1's
and in this case I do the loop 16 times.

This seems to be good if dirnow is a random number and has 8 1's but I believe
that practically my dirnow has usually less 1's.

There are 16 possible directions that a square can be attacked in chess
and dirnow&(1<<i)=1<<i only if the square is attacked from direction i

Usually the number of these directions is small and in a lot of cases the square
is attacked from only 1 or 2 directions.

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.