Computer Chess Club Archives


Search

Terms

Messages

Subject: Re: Problem with Object Oriented Design (programming issue)

Author: Pat King

Date: 16:14:24 09/17/03

Go up one level in this thread


On September 16, 2003 at 11:45:37, Daniel Clausen wrote:
>On September 16, 2003 at 10:57:30, Pat King wrote:
>>By the way, I DO use abstract piece classes and a lot of the fancy C++ stuff.
>If you don't mind talking about the internals of your engine, I would like to
>know what functionality your piece classes provide.
>
>Sargon

It's not all pretty, but here's a textual/pseudocode description of how it goes.

class Apiece; //abstract

class Position contains/uses Apiece; // Contains a static board and piece
//lists full of apiece pointers. Has methods which iterate over piece lists
//to generate or check legality of moves, print positions, etc.
//This is the interface that most of the program deals with.

class Piece: public Apiece, Position; // implements default apiece methods
//(MakeMove(move), UndoMove(move)), has access to position for this purpose.

// Helper classes
class PromotePiece: public Piece; // provides UndoMove behaviour for pieces
// born of pawns
class StepPiece: public Piece; // One square at a time, kings and knights
class RayPiece: public PromotePiece; // All ray pieces exhibit promote
// behaviour

// Leaf classes
class King: public StepPiece; // Adds castling behaviour
class Queen: public RayPiece; // Only static data for move directions
class Bishop: public RayPiece; // Ditto
class Rook: public Raypiece; // Adds castling behaviour
class Knight: public StepPiece, PromotePiece; // It really does move just like
// a king
class Pawn: public Piece; // Not enough like anything for reuse, pawns are
// in a class by themselves.

There are more classes that help store castling and enpassant info, but the
above expresses the tough stuff.

Hope this is interesting/helpful.

Pat



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.