Author: Jens Kahlenberg
Date: 09:49:27 06/29/03
Go up one level in this thread
On June 29, 2003 at 12:16:42, Uri Blass wrote:
>On June 29, 2003 at 11:15:09, Jens Kahlenberg wrote:
>
>>On June 29, 2003 at 10:43:39, Uri Blass wrote:
>>
>>>On June 29, 2003 at 10:36:28, Uri Blass wrote:
>>>
>>>>On June 29, 2003 at 10:05:36, Jens Kahlenberg wrote:
>>>>
>>>>>... my advice is to use the assert-macro to state boolean expression at
>>>>>aproppriate positions in source (see header-file assert.h for details)
>>>>>
>>>>>On June 29, 2003 at 08:23:44, Uri Blass wrote:
>>>>>
>>>>>>I found that my latest version show different analysis when I give it the same
>>>>>>position again.
>>>>>>
>>>>>>It is not supposed to happen because I did not implement positional learning and
>>>>>>after setboard command it should forget everything.
>>>>>>
>>>>>>The most logical reason that I can think about it is if
>>>>>>an important global varaible is changed.
>>>>>
>>>>>Perhaps variables are not reinitialized and an appropriate assert-macro might
>>>>>help you ... e. g.: assert( GLOBAL == 42 );
>>>>>
>>>>>>
>>>>>>My question is if there is a simple way to check the global varaibles or global
>>>>>>arrays that have different values.
>>>>>
>>>>>Global arrays are a little bit trickier to assert. I have to think a while about
>>>>>the problem. I fear, that you need some extra looping-code embraced by #ifndef
>>>>>NDEBUG ... #endif (see below)
>>>>>
>>>>>>
>>>>>>I can generate a copy for every global varaible and later compare the global
>>>>>>varaibles with their copies that are not used but this is not a general solution
>>>>>>because this means that I need to add more debugging code when I add more
>>>>>>varaibles.
>>>>>>
>>>>>>Uri
>>>>>
>>>>>You're right ... that would mess up your code and you would have to clean it
>>>>>later ... errorprone :-( In contrast assertions are turned off by compiler-flag:
>>>>>-DNDEBUG and can reside in your code _forever_
>>>>>
>>>>>Best regards,
>>>>>Jens
>>>>
>>>>Thanks
>>>>
>>>>I guess that I will have a special function checkvaraibles to check the
>>>>varaibles and arrays(I can disable the function by compiler flag)
>>>>
>>>>In order to check an array I will have in checkvaraibles something like this for
>>>>every array:
>>>>
>>>>
>>>>for (i=-8;i<0;i++)
>>>>if (info[i]!=-1)
>>>>{
>>>> printf("mistake in the board");
>>>> printf(" %d ",i);
>>>>}
>>>>for (i=0;i<64;i++)
>>>>if (info[i]!=22)
>>>>{
>>>> printf("mistake in the board");
>>>> printf(" %d ",i);
>>>>}
>>>>for (i=64;i<72;i++)
>>>>if (info[i]!=-1)
>>>>{
>>>> printf("mistake in the board");
>>>> printf(" %d ",i);
>>>>}
>>>>
>>>>
>>>>Note that info[i] when i=-8 is not a mistake because I used the following
>>>>definitions
>>>>int PADDED_info[80];
>>>>int * const info = PADDED_info+8;
>>>>
>>>>Uri
>>>
>>>Note that I may use constant instead of 22(I already have constant that I use in
>>>the program but there are cases when I forget about it and use the number)
>>>
>>>22 means empty square.
>>>-1 means square that is not in the board.
>>>
>>>Uri
>>
>>Constants are _always_ better than pure numbers (even for sizes of array and so
>>on). If your compiler has problems you can workaround by (little bit ugly)
>>#define for the constant.
>>
>>#define PAD_BEGIN -8
>>#define INFO_BEGIN 0
>>#define INFO_END 64
>>#define PAD_END 72
>
>or maybe
>
>enum {
>
>I read that it is better to use enum and not define(see page 20 of The practise
>of programming.
>
>Uri
Must be a good book :-) ... But if compiler is doing a really bad job on
optimizing code you might run into some (performance) problems if you start
calculating with "constants". You have to make some experiments on your system,
but normally i use enums too without any problems :-)
BTW: "good" way to declare your PADDED_info array might be:
int PADDED_info[ PAD_END - PAD_BEGIN ]; // no need to "invent" an name for size
You can get rid of nearly _every_ pure number and your code will get more
readable and maintainable and you can save lots of debugging hours just by
inspecting your code.
Jens
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.