Computer Chess Club Archives


Search

Terms

Messages

Subject: Re: A question about varaibles that I should give to functions in C++

Author: Gerd Isenberg

Date: 13:39:15 08/01/04

Go up one level in this thread


On August 01, 2004 at 15:45:10, Uri Blass wrote:

>On August 01, 2004 at 06:12:03, Gerd Isenberg wrote:
>
>>On August 01, 2004 at 01:07:10, Uri Blass wrote:
>>
>>>My code until today used a lot of global varaibles and I decided based on advice
>>>of Dann Corbit to use a class for time management.
>>>
>>>I have a many varaibles in class for time management and
>>>I hesitate which parameters to give to the functions.
>>>
>>>I will give an example:
>>>
>>>I want to have a procedure to update the remaining number of moves to the time
>>>control in the beginning of every search(this varaible is used for other
>>>varaibles like the target time.
>>>
>>>The procedure is using the following varaibles:
>>>1)num_moves_1(number of moves in the first time control)
>>>2)num_moves_2(number of moves in the second time control)
>>>3)num_moves_3(number of moves in the third time control)
>>>4)hply(history ply of the game)
>>>
>>>I think to call the procedure not inside the class so it cannot get directly
>>>num_moves_1 or num_moves_2 or num_moves_3
>>>
>>>I can write seperate functions to return num_moves_1 inside the class and use
>>>these functions outside of the class but I am not sure if it is a good idea(no
>>>experience in C++).
>>>
>>>Another possibility is not to give the functions the parameters of
>>>num_moves_1,num_moves_2,num_moves_3 because their value is known inside the
>>>class so it is not needed.
>>>
>>>What do you suggest?
>>>
>>>Uri
>>
>>Hi Uri,
>>
>>yes, putting time control variables and services into a struct/class is a good
>>idea.
>>
>>Basically you hide your n num_moves and n times_to_num_moves, which got
>>initialized at construction time or via some setters with appropriate
>>parameters.
>>
>>I suggest not to keep track of elapsed time and history of the game inside this
>>class, but to have a memberfunction with hply and elapsed time parameter to get
>>the average and maximum thinking time (or some vector of suggested times for
>>different cases incapsulated in some other class) for the next move.
>
>hply is of course not time varaible and it is today a global varaible(it is used
>in other places like makemove that update the history stake and I do not see an
>idea how not to use it as global varaible).
>
>I do not see the advantage of having elapsed time as a global varaible(I thought
>to have all the only time related varaibles in the same class).
>

I like to have elapsed time as well as move count and the whole game history
(played moves with time used for both sides) not as a global, but as members of
a GameControl object, which is most likely allocated on the heap with new.

The GameControl object knows (points to or is member from) the rootNode as well
and may start it's search routine or thread. The search- or rootNode object also
references (or has a pointer to) the GameControl object to ask inside the search
whether it is time to interrupt it. It's a matter of taste, one may even put
alltogether in one class (rootNode,searchControl and gameControl) but splitting
in exchangable, functional units with consistent interfaces is more flexible and
maintainable. Monster classes are awful ;-)

OTOH num_moves_i and time_for_num_moves_i and playing mode (blitz, several
tournament modes) are rather const after initialization and may be shared by
several gameControl objects. Therefore the idea with a separate class
(namespace) with static members of a shared timeControl object like a global
variable - only to have one central instance to calculate the allocated time for
the next move with some actual parameters.

Gerd

>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.