Computer Chess Club Archives


Search

Terms

Messages

Subject: Re: what classes all the serious C++ chess programs have?

Author: Alessandro Scotti

Date: 07:08:59 08/10/04

Go up one level in this thread


On August 10, 2004 at 09:06:59, Álvaro Begué wrote:

>I once made a very basic chess program with a single global board and an
>identical program in which the pointer to the board had to be passed around. >The first one was about 15% faster. You can avoid the indirection using templates,
>but it's a little tricky, and not much cleaner than having a global board.

Hey, 15% is a lot faster! I'm using pointers right now but tonight I'll replace
them with a global board and see what happens...

>>3) A really good point and I like to keep my stuff well organized too. For this,
>>I find the "static" keyword very handy, for example:
>>
>>struct Score {
>>    static int bishopValue;
>>};
>>
>>It behaves like a global (there is no need to have an instance of Score) but I
>>find it more readable and less error prone as code must then explicitly state
>>where the variable comes from:
>>
>>if( material >= Score::bishopValue ) ...
>
>If you are never going to have an instance of "Score", it shouldn't be a class.
>Use a namespace for that:
>
>namespace Score {
>    const int bishopValue=315;
>};

The reason I don't like namespaces here is that they allow an "escape" mechanism
with the "using" keyword, thus potentially avoiding the whole point. I might be
oversuspicious though... :-)

>>If needed (say, when done with experiments) static variables can also be
>>replaced with compile time constants by declaring them with enum inside the
>>class: that could speed up things a little.
>
>const variables are as fast as enums.

You are right, and in this case I think they are actually better. Thanks for
reminding that!




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.