Author: David Blackman
Date: 00:12:36 12/31/99
Go up one level in this thread
On December 30, 1999 at 18:53:04, Tom Kerrigan wrote: >Although I love C and I usually don't approve of object-oriented programming, I >think there are compelling reasons to use objects in a chess program. > >Specifically, I want to have a chess board class, which contains the data and >functions necessary to manipulate a chess board. I also want to have an engine >class, which extends the chess board class, and adds the functions necessary to >search the board. As a couple of other people mentioned, this design "feels bad". It implies that each chess engine has exactly one chess board, which might or might not be what you intended. By convention, it implies that a chess engine is a special kind of chess board with some of the same operations, although C++ doesn't enforce this. Using inheritence too much or in the wrong places can make a confusing design. But a chess program is fairly simple, so you can probably get away with it. It shouldn't be a performance issue either way. >I have two questions: >1. When I access the chess board class from the engine class, will there be a >performance hit? Probably not. There is an overhead for virtual methods, so don't use them unless they do something useful. A pointer to the object is included as a hidden parameter for every method call, so if the pointer to the object is not actually needed, write an ordinary function instead of a method. If you remember these points, there should be no performance hit with most compilers. In addition, you should put the really trivial methods inside the class declaration so they get inlined. That way you get OO clarity and safety combined with macro speed. >2. If I have multiple instances of the engine class, can each one run on a >different processor without a performance hit? That's really up to you, the operating system you have running under you, and the access into the operating system provided by your system libraries. C++ itself won't get in your way, but it won't help you much either. >Thanks, >Tom
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.