ChessPlusPlus  WIP
cplusplus.com Community Project
chesspp::piece::Piece Class Referenceabstract

A chess piece. More...

#include <Piece.hpp>

Inheritance diagram for chesspp::piece::Piece:
chesspp::piece::Archer chesspp::piece::Bishop chesspp::piece::King chesspp::piece::Knight chesspp::piece::Pawn chesspp::piece::Queen chesspp::piece::Rook

Public Types

using Position_t = config::BoardConfig::Position_t
 
using Suit_t = config::BoardConfig::SuitClass_t
 
using Class_t = config::BoardConfig::PieceClass_t
 

Public Member Functions

 Piece (board::Board &b, Position_t const &pos, Suit_t const &s, Class_t const &pc)
 Construct onto a board at the given position with the given suit and class. More...
 
virtual ~Piece ()=default
 
void makeTrajectory ()
 Update movement information. More...
 

Public Attributes

board::Boardboard
 The chesspp::board::Board in which the Piece exists. More...
 
Position_t const & pos = p
 The position of this piece. More...
 
Suit_t const & suit = s
 The display suit of this piece (e.g. Black or White). More...
 
Class_t const & pclass = c
 The display class of this piece (e.g. Pawn, Rook, etc). More...
 
std::size_t const & moves = m
 The number of moves this piece has made. More...
 

Protected Member Functions

virtual void calcTrajectory ()=0
 Called by makeTrajectory() to calculate movement information. More...
 
void addTrajectory (Position_t const &tile)
 Mark a position as a valid position to move to without capturing. More...
 
void removeTrajectory (Position_t const &tile)
 Unmark a position as a valid position to move to without capturing. More...
 
void addCapturing (Position_t const &tile)
 Mark a position as a valid position to move to when capturing. More...
 
void removeCapturing (Position_t const &tile)
 Unmark a position as a valid position to move to when capturing. More...
 
void addCapturable (Position_t const &tile)
 Mark a position as a valid position to capture this piece from. More...
 
void removeCapturable (Position_t const &tile)
 Unmark a position as a valid position to capture this piece from. More...
 

Friends

class ::chesspp::board::Board
 
std::ostream & operator<< (std::ostream &os, Piece const &p)
 Outputs a basic human-readable description of this piece to an output stream. More...
 

Detailed Description

A chess piece.

Member Typedef Documentation

Constructor & Destructor Documentation

chesspp::piece::Piece::Piece ( board::Board b,
Position_t const &  pos,
Suit_t const &  s,
Class_t const &  pc 
)

Construct onto a board at the given position with the given suit and class.

Parameters
bThe chesspp::board::Board on which this piece is to live, must outlive this instance.
posThe initial position of this piece.
sThe display suit of the piece.
pcThe display class of the piece.
virtual chesspp::piece::Piece::~Piece ( )
virtualdefault

Member Function Documentation

void chesspp::piece::Piece::addCapturable ( Position_t const &  tile)
protected

Mark a position as a valid position to capture this piece from.

Parameters
tileThe position to mark.
void chesspp::piece::Piece::addCapturing ( Position_t const &  tile)
protected

Mark a position as a valid position to move to when capturing.

Parameters
tileThe position to mark.
void chesspp::piece::Piece::addTrajectory ( Position_t const &  tile)
protected

Mark a position as a valid position to move to without capturing.

Parameters
tileThe position to mark.
virtual void chesspp::piece::Piece::calcTrajectory ( )
protectedpure virtual

Called by makeTrajectory() to calculate movement information.

Implementations should call addTrajectory(), addCapturing(), and addCapturable(), as well as their remove counterparts if necessary. By default, addCapturable() is called with the current position of the piece before this member function is called.

Implemented in chesspp::piece::Pawn, chesspp::piece::Archer, chesspp::piece::Bishop, chesspp::piece::King, chesspp::piece::Knight, chesspp::piece::Queen, and chesspp::piece::Rook.

void chesspp::piece::Piece::makeTrajectory ( )
inline

Update movement information.

Note
Should not be overridden or shadowed by deriving classes.
void chesspp::piece::Piece::removeCapturable ( Position_t const &  tile)
protected

Unmark a position as a valid position to capture this piece from.

Parameters
tileThe position to mark.
void chesspp::piece::Piece::removeCapturing ( Position_t const &  tile)
protected

Unmark a position as a valid position to move to when capturing.

Parameters
tileThe position to unmark.
void chesspp::piece::Piece::removeTrajectory ( Position_t const &  tile)
protected

Unmark a position as a valid position to move to without capturing.

Parameters
tileThe position to unmark.

Friends And Related Function Documentation

friend class ::chesspp::board::Board
friend
std::ostream& operator<< ( std::ostream &  os,
Piece const &  p 
)
friend

Outputs a basic human-readable description of this piece to an output stream.

Parameters
osThe stream to which to describe this piece.
pThe piece to describe.

Member Data Documentation

board::Board& chesspp::piece::Piece::board

The chesspp::board::Board in which the Piece exists.

std::size_t const& chesspp::piece::Piece::moves = m

The number of moves this piece has made.

Class_t const& chesspp::piece::Piece::pclass = c

The display class of this piece (e.g. Pawn, Rook, etc).

Note
This cannot be used to determine what kind of piece this is, as this value is only for display purposes and may not match the actual type.
Position_t const& chesspp::piece::Piece::pos = p

The position of this piece.

Suit_t const& chesspp::piece::Piece::suit = s

The display suit of this piece (e.g. Black or White).


The documentation for this class was generated from the following files: