Computer Chess Club Archives


Search

Terms

Messages

Subject: Re: C or C++ for Chess Programming?

Author: Dan Newman

Date: 02:07:09 08/18/00

Go up one level in this thread


On August 16, 2000 at 20:46:10, Tom Kerrigan wrote:

>I wrote my chess engine in C.
>
>Then I renamed all my .c files to .cpp and dumped all my engine functions into a
>big class.
>
>This was so I could do pondering and MP without seriously complicating my code.
>
>I think the performance penalty was about 5%, but happily, my code is still very
>simple.
>
>-Tom

I would guess you also dumped your basic data structures into that class too
(the board and so forth) so that the engine functions could get to them.  So
data that was once globally available must now be gotten to through a "this"
pointer invisibly passed to the member functions.  I suspect this is where the
extra overhead is.  But this would have happened if you'd done the equivalent
in C.  And to support MP you'd likely have to do this anyway since you want
to be able to have multiple copies of those basic data structures.

I think the benefits of C++ far outweigh any necessary minuses.  That's not
to say I think full blown OOP is appropriate for a chess program.  What I
like is all the little "improvements" it makes to C.  In particular I like
being able to declare variables just ahead of their use and being able to
hide the actual implementation details of data structures by the use of
member functions for data access.  (This last lets me, for instance,
experiment with move representation, stuffing all the move bits into a
single int or parcelling them out to separate chars or whatever.)

OTOH, I have occasionally considered attempting a full blown OPP chess
program complete with pools of chess pieces with overloaded new so that
(for instance) on pawn promotion I could delete the pawn and new a queen...

-Dan.



This page took 0.04 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.