The API of this "another object" is strictly tied to the logic of the game. It will be different for chess and different for say... civilization clone.
For chess I would define something like:
class ChessPieceLogic {
public:
virtual ~ChessPieceLogic(){}
virtual QList<QPoint> possibleMoves
(const QPoint &from,
const BoardState
&state
) const = 0;
virtual QList<QPoint>attackedFields
(const QPoint &from,
const BoardState
&state
) const = 0;
virtual isValidMove
(const QPoint &from,
const QPoint &to,
const BoardState
&state
) const = 0;
virtual bool isUnderAttackBy
(const QPoint &source,
const QPoint &target
) const;
// to check for check/mate virtual QList<QPair<QPoint,QPoint> > makeMove
(const QPoint &from,
const QPoint &to,
const BoardState
&state
) const = 0;
// to allow en passant and castles virtual void commitMove
(const QPoint &from,
const QPoint &to
) = 0;
};
class ChessPieceLogic {
public:
virtual ~ChessPieceLogic(){}
virtual QList<QPoint> possibleMoves(const QPoint &from, const BoardState &state) const = 0;
virtual QList<QPoint>attackedFields(const QPoint &from, const BoardState &state) const = 0;
virtual isValidMove(const QPoint &from, const QPoint &to, const BoardState &state) const = 0;
virtual bool isUnderAttackBy(const QPoint &source, const QPoint &target) const; // to check for check/mate
virtual QList<QPair<QPoint,QPoint> > makeMove(const QPoint &from, const QPoint &to, const BoardState &state) const = 0; // to allow en passant and castles
virtual void commitMove(const QPoint &from, const QPoint &to) = 0;
};
To copy to clipboard, switch view to plain text mode
Bookmarks