tartan 1.2.2.1
Chess API
Loading...
Searching...
No Matches
tt::Piece Class Referenceabstract

Generic board memeber API. More...

#include <board.hpp>

Inheritance diagram for tt::Piece:
[legend]
Collaboration diagram for tt::Piece:
[legend]

Classes

class  Position
 Piece position at the Board. More...
 
class  Turn
 Generic Piece Turn on Board. More...
 
class  TurnMap
 List of Turn objects. More...
 

Public Types

enum class  Color { Black = 0 , White = 1 }
 Piece color. More...
 

Public Member Functions

Color color () const
 Piece color.
 
Color setColor (Color col)
 Set the color.
 
const Positionposition () const
 Piece Position.
 
Positionposition ()
 Piece Position.
 
Position setPosition (const Position &)
 Set Piece position.
 
virtual Position move (const Position &to)
 Move piece.
 
virtual TurnMap moveMap (int mode=0) const =0
 Generic moves.
 
const Boardboard () const
 Piece board.
 
Boardboard ()
 Piece board.
 
BoardsetBoard (Board *b)
 Set Piece Board.
 
std::size_t movesMade () const
 Moves count.
 
std::size_t turnIndex () const
 Current turn index.
 
 Piece (const Position &pos={1, 1}, Color col=Color::White)
 Construct new Piece.
 

Static Public Member Functions

static TurnMap diagonalMoves (const Piece *p)
 Construct diagonal moves TurnMap.
 
static TurnMap straightMoves (const Piece *p)
 Construct straight moves (up, down, left, right) TurnMap.
 

Protected Attributes

Color p_color
 Piece color.
 
Position p_position
 Piece Position.
 
Boardp_board = nullptr
 Piece Board.
 
std::size_t p_movesMade = 0
 Turns count Count of turns Piece have made.
 
std::size_t p_turnIndex = 0
 Last turn index.
 

Detailed Description

Generic board memeber API.

This class should be inherited and used to describe piece in new board.

Member Enumeration Documentation

◆ Color

enum class tt::Piece::Color
strong

Piece color.

See also
setColor(), color()

Constructor & Destructor Documentation

◆ Piece()

tt::Piece::Piece ( const Position pos = {1,1},
Color  col = Color::White 
)

Construct new Piece.

Parameters
posPiece Position
colPiece Color
See also
color(), position()

Member Function Documentation

◆ board() [1/2]

Board * tt::Piece::board ( )
inline

Piece board.

Returns
Board to which current Piece belongs

◆ board() [2/2]

const Board * tt::Piece::board ( ) const
inline

Piece board.

Returns
Board to which current Piece belongs

◆ color()

Color tt::Piece::color ( ) const
inline

Piece color.

Returns
current Piece color value

◆ diagonalMoves()

Piece::TurnMap tt::Piece::diagonalMoves ( const Piece p)
static

Construct diagonal moves TurnMap.

Constructs new TurnMap object where the TurnMap::piece() is set to p. It is defined that piece that performs moves can not step on or over other Piece objects at the Board.

Returns
TurnMap object with p as turn piece

◆ move()

Position tt::Piece::move ( const Position to)
virtual

Move piece.

Changes the position() value, uses board() interface to move piece to new location at the underlying Board.

Parameters
tonew Position value
Returns
old Position vlaue

◆ moveMap()

virtual TurnMap tt::Piece::moveMap ( int  mode = 0) const
pure virtual

Generic moves.

Note
Developer had and intention that You will define unscoped enumeration for mode in Your Board class. It's value will be passed to function and influence it's behaivor in some way.
Parameters
modeoptional mode constant to influence the moveMap() behaivor in child classes.
Returns
TurnMap object filled with Turn objects. May not contain turns that are not possible because of piece placement

Implemented in tt::chess::Pawn, tt::chess::Knight, tt::chess::Bishop, tt::chess::Rook, tt::chess::Queen, and tt::chess::King.

◆ movesMade()

std::size_t tt::Piece::movesMade ( ) const
inline

Moves count.

Returns
total count of moves Piece has made
See also
p_movesMade

◆ position() [1/2]

Position & tt::Piece::position ( )
inline

Piece Position.

Returns
current Piece position
See also
Position, p_position

◆ position() [2/2]

const Position & tt::Piece::position ( ) const
inline

Piece Position.

Returns
current Piece position
See also
Position, p_position

◆ setBoard()

Board * tt::Piece::setBoard ( Board b)

Set Piece Board.

Parameters
bnew Board
Returns
old board
See also
p_board

◆ setColor()

Piece::Color tt::Piece::setColor ( Color  col)

Set the color.

Parameters
colnew Piece color value
Returns
old color value
See also
Color, p_color

◆ setPosition()

Position tt::Piece::setPosition ( const Position p)

Set Piece position.

Returns
old Position value
See also
Position, p_position

◆ straightMoves()

Piece::TurnMap tt::Piece::straightMoves ( const Piece p)
static

Construct straight moves (up, down, left, right) TurnMap.

Constructs new TurnMap object where the TurnMap::piece() is set to p. It is defined that piece that performs moves can not step on or over other Piece objects at the Board.

Returns
TurnMap object with p as turn piece

◆ turnIndex()

std::size_t tt::Piece::turnIndex ( ) const
inline

Current turn index.

Returns
turn index of board() when current piece were performing it's move
See also
p_turnIndex

Member Data Documentation

◆ p_board

Board* tt::Piece::p_board = nullptr
protected

Piece Board.

Board, to which current piece belongs to

See also
board()

◆ p_color

Color tt::Piece::p_color
protected

Piece color.

See also
color(), setColor()

◆ p_position

Position tt::Piece::p_position
protected

◆ p_turnIndex

std::size_t tt::Piece::p_turnIndex = 0
protected

Last turn index.

Board::turnIndex() value at the moment when Piece performed some Turn


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