Computer Chess Club Archives


Search

Terms

Messages

Subject: Re: Computer chess schools of thought

Author: Russell Reagan

Date: 12:43:49 07/01/02

Go up one level in this thread


On July 01, 2002 at 13:32:15, Sune Fischer wrote:

>The only big difference between this and C is that your pieces become classes
>rather than just arrays.

My opinion is that if you're going to allow access to the "int type" in any way
(even an accesor method) then you're not creating a generic class, which is kind
of the point of doing OOP in the first place (I thought). So for example, if you
have

class piece {
  public:
    bool isPawn();
    bool isKnight();
    // etc.

    bool isWhite();
    bool isBlack();

    int  getIndex();

    bool isAlive();

    char toChar();

    // and so on...
  private:
    int type;
    int color;
    int index;
    bool alive;
};

Now you have a class that you can work with and if you change another part of
your program, your piece class will still work like a charm. If you add in an
int getType() method, and use that as an index into a mobility array (or
whatever) then if you change how the piece class works later on, or how the
mobility works, you might have potential problems.

I think that if you are allowed access to the "type" of the piece, then you are
defeating the purpose of OOP. Another example is if you had something like...

vector<int> pieceIndexes[2];

in your position class, then you could just do something like...

pieceIndexes[sideToMove];

when looping through the pieces to generate legal moves. If you don't allow
acces to the sideToMove data from another outside function (which you shouldn't
in OOP) then you can't do that kind of stuff.

What do you think?

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.