Author: Russell Reagan
Date: 10:13:26 07/01/02
Go up one level in this thread
On July 01, 2002 at 05:46:58, Sven Reichard wrote:
>let me offer a third approach. I don't mean to be preaching OO practices, I just
>want to describe how I work
I tried to use an OO approach recently, but I found it to not be very good for
my chess program. For example, let's take my Piece class. In a classic approach,
you would have some method to determine what type of piece it was. In the OO
approach, I had to have 6 methods to determine what kind of piece it was. For
example...
class Piece {
public:
bool isPawn();
bool isKnight();
bool isBishop();
bool isRook();
bool isQueen();
bool isKing();
// ...
};
I didn't find this approach to be the "simplest". The approach I have found to
be the simplest is to use an array of int's for the board, and then using
COLOR() and TYPE() macros. Maybe there is a better way of doing my class. For
example, in my class approach, you couldn't do a switch(pieceType) { ... },
you'd have to do a string of if(piece.isPawn() { ... } else if
(piece.isKnight()) { ... } and so on. I guess it's not so bad, and this might be
where some of the performance hits come in. Another example I can think of is
that with a straight binary value for a piece you can do quick attacks, but with
a class like this I'm not sure how you would accomplish that. Perhaps I'm just
not a very experienced OO programmer.
Russell
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.