Computer Chess Club Archives


Search

Terms

Messages

Subject: Re: boundschecking

Author: Severi Salminen

Date: 02:57:42 11/04/02

Go up one level in this thread


>>More information the fact that the function is in a different files change
>>nothing here
>>
>>I tried transferring the function to the same file and even not using the
>>function but
>>having
>>
>>for (fil=0;fil<6;fil++)
>>		for (i=0;i<2;i++)
>>			for (j=0;j<64;j++)
>>				zobrist[fil][i][j]=rand()^((__int64)rand()<<15)^((__int64)rand()<<30)^
>>		((__int64)rand()<<45)^((__int64)rand()<<60);
>>
>>It does not help and I get different numbers in compile mode and in release
>>mode.
>
>Correction I mean debug and release.

Yes, and the reason for this odd behaviour is that the order of which the above
is executed differs between debug and release modes. In debug it is more or less
from left to right and in release it is more or less the opposite (didn't test
that much). If I'm not mistaken, the order of XOR operations is not defined in C
standard - only OR and AND are (i might remember wrong, though). And when the
direction (or the order) differs, different random numbers get to different
position in the final random number -> different zobrist keys. So either:

1. Make a function in which you can be sure about the order of which the rand()
functions are executed. (This is about "sequence point", read C++ docs for more
info):

int a,b,c;

a=rand();
b=rand()<<15;
c=rand()<<30;

or something more elegant with loop or whatever.

2. Or make a random function which is not dependant of the order. You should
remember that it is allways a bad idea to put things in the same statement that
are dependant of each other. You can never be sure about the order of which
these are executed. Or at least it is easy to forget the right order...

Severi



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.