Mar 22, 2007

[Other] Working with evaluation

I am planning to implement Ed Schröder's setup with piece attacks to get a solid foundation to build the evaluation on.

Since I am recreating the evaluation from the ground up it is easy to see what causes slowdowns and one thing I found was the arrays needed to store the attack information.

We need two 128 slot arrays (one for each color) and these need to be reset at the start of the evaluation. Unfortunately Java does not have a good (fast) way of resetting an array (i.e. filling it with zeros).

The choices are using a loop to set every slot to zero, use the Java method Arrays.fill(), or simply create a new array (which always starts with zeros in all slots).

As it turns out all these are fairly equal in speed, and hence rather slow. I lost about 5-10% of the total evaluation speed by just setting up the attack arrays.

At first I wanted the arrays to consist of type 'int' (32-bit numbers), since I find Ed's implementation a bit restricting, but creating a 128 slot array with integers is about 3 times slower than creating an array with type 'byte' (8-bits). I guess byte will have to do.


Anonymous said...

Have you tried maintaining a separate "zero-array" and using System.arraycopy() to fill the attack table with zeroes?

Jonatan Pettersson said...

Ah forgot about that one. I read about this on the Java forums at Sun's website and it seems the three I mentioned are about the same speed while the array copy is supposed to be a bit slower.

I actually haven't tested it, perhaps I should.