Computer Chess Club Archives


Search

Terms

Messages

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

Author: Álvaro Begué

Date: 10:35:39 08/10/04

Go up one level in this thread


On August 10, 2004 at 10:08:59, Alessandro Scotti wrote:

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

Well, in a serious program I would expect much less of an effect. The program
were I tested it was a really fast program with a very simple evaluation
function. That's why the extra argument in many calls was a big performance hit.

A colleague of mine proposed a way of getting rid of the indirection and the
extra argument, without forcing you to use a single board. It is a little
twisted, but interesting. You just make your engine a template class that gets a
pointer to Board in the template:

class Board {
  //...
};

template <Board *b>
class Engine {
  //...use the board *b for everything.
};

Board my_board;
Engine<&my_board> my_engine;

Board my_other_board;
Engine<&my_other_board> my_other_engine;

This gives you performance that is as good as using a single global board, but
you can have more than one board. Of course this duplicates all the code
internally and your binary ends up being very large, but you can't get
everything.




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.