tartan  1.2.1.0
tt::Piece::Turn Class Reference

Generic Piece Turn on Board. More...

#include <board.hpp>

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

Public Member Functions

 Turn (const Piece *tpiece, const Position &to, const Piece *cap=nullptr, bool possible=true)
 Construct new Turn object. More...
 
Position to () const
 Position where piece will end up after turn. More...
 
Position from () const
 Position the turn is started at. More...
 
const Piecepiece () const
 Turn Piece. More...
 
Piecepiece ()
 Turn Piece. More...
 
const Piececapture () const
 Captured piece. More...
 
Piececapture ()
 Captured piece. More...
 
bool possible () const
 Turn viability. More...
 
bool setPossible (bool c)
 Set the turn viability. More...
 
virtual std::string str () const
 String Turn representation. More...
 
virtual void apply (int mode=0)
 Apply turn. More...
 
virtual void undo ()
 Undo turn. More...
 
virtual bool isEqual (const Turn &rhs) const
 Compare turns. More...
 
virtual auto clone () const -> std::decay< decltype(*this)>::type *
 Clone current Turn. More...
 

Protected Attributes

Position t_from
 Turn piece starting position
 
Position t_to
 Turn piece finishing position
 
Piecet_piece
 Turn Piece inself
 
Piecet_capture
 Piece that is captured as the resul of turn.
 
bool t_possible
 Turn viability.
 

Friends

bool operator== (const Turn &lhs, const Turn &rhs)
 Comparison operator. More...
 
bool operator!= (const Turn &, const Turn &)
 Inverted comparison operator. More...
 
std::ostreamoperator<< (std::ostream &os, const Turn &t)
 std::ostream output More...
 

Detailed Description

Generic Piece Turn on Board.

Class should be defined as derived from Piece::Turn in every class derives from Piece.

Constructor & Destructor Documentation

◆ Turn()

tt::Turn::Turn ( const Piece tpiece,
const Position to,
const Piece cap = nullptr,
bool  possible = true 
)

Construct new Turn object.

Parameters
tpieceturn piece. Piece that performs turn
tofinal location. Location where the tpiece will end up after the turn is applied
capcaptured Piece. Should be provided if turn captures some pieces
possibletrue, if turn is possible, false otherwise

Member Function Documentation

◆ apply()

void tt::chess::Turn::apply ( int  mode = 0)
virtual

Apply turn.

Applies current turn. Should be reimplemented in child Piece class if it have to do something special on move.

This does the next:

You can define unscoped enum and use it with this fucntion to perform different applying logic on demand.

Parameters
modeoptional apply mode parameter

Reimplemented in tt::chess::King::Turn, and tt::chess::Pawn::Turn.

◆ capture() [1/2]

Piece* tt::Piece::Turn::capture ( )
inline

Captured piece.

Returns
piece that turn will be captured when turn is applied

◆ capture() [2/2]

const Piece* tt::Piece::Turn::capture ( ) const
inline

Captured piece.

Returns
piece that turn will be captured when turn is applied

◆ clone()

auto tt::Turn::clone ( ) const -> std::decay<decltype(*this)>::type*
virtual

Clone current Turn.

Returns
pointer to new memory with Turn object indentical to invoking object

◆ from()

Position tt::Piece::Turn::from ( ) const
inline

Position the turn is started at.

Returns
target turn position

◆ isEqual()

bool tt::chess::Turn::isEqual ( const Turn rhs) const
virtual

Compare turns.

Should be reimplemented in child Piece class if it's Turn logic differs.

Parameters
rhsTurn object compare to
Returns
true if rhs turn is the same as current object

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

◆ piece() [1/2]

Piece* tt::Piece::Turn::piece ( )
inline

Turn Piece.

Returns
piece whose turn current object describes

◆ piece() [2/2]

const Piece* tt::Piece::Turn::piece ( ) const
inline

Turn Piece.

Returns
piece whose turn current object describes

◆ possible()

bool tt::Piece::Turn::possible ( ) const
inline

Turn viability.

Returns
true, if turn is possible, false otherwise

◆ setPossible()

bool tt::Piece::Turn::setPossible ( bool  c)
inline

Set the turn viability.

Parameters
cnew viability value
Returns
old viability value

◆ str()

std::string tt::chess::Turn::str ( ) const
virtual

String Turn representation.

This function may be redefined in Piece::Turn that inherit from Piece depending on new piece implementation

Returns
string representation of current Turn object

Reimplemented in tt::chess::King::Turn.

◆ to()

Position tt::Piece::Turn::to ( ) const
inline

Position where piece will end up after turn.

Returns
starting turn position

◆ undo()

void tt::chess::Turn::undo ( )
virtual

Undo turn.

Opposite to apply(). Should be reimplemented in child Piece class if it's apply() function does something special on applying.

Reimplemented in tt::chess::King::Turn.

Friends And Related Function Documentation

◆ operator!=

bool operator!= ( const Turn lhs,
const Turn rhs 
)
friend

Inverted comparison operator.

Parameters
lhsleft object of == operator
rhsright object of == operator
Returns
the value of !lhs.isEqual(rhs)
See also
isEqual()

◆ operator<<

std::ostream& operator<< ( std::ostream os,
const Turn t 
)
friend

std::ostream output

Puts the t.str() in os object

Parameters
osinvoking std::ostream object
tTurn object for writting
Returns
invoking std::ostream os object

◆ operator==

bool operator== ( const Turn lhs,
const Turn rhs 
)
friend

Comparison operator.

Parameters
lhsleft object of == operator
rhsright object of == operator
Returns
the value of lhs.isEqual(rhs)
See also
isEqual()

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