Computer Chess Club Archives


Search

Terms

Messages

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

Author: Uri Blass

Date: 05:48:19 06/26/01


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



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.