tartan 1.2.2.1
Chess API
Loading...
Searching...
No Matches
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.
 
Position to () const
 Position where piece will end up after turn.
 
Position from () const
 Position the turn is started at.
 
const Piecepiece () const
 Turn Piece.
 
Piecepiece ()
 Turn Piece.
 
const Piececapture () const
 Captured piece.
 
Piececapture ()
 Captured piece.
 
bool possible () const
 Turn viability.
 
bool setPossible (bool c)
 Set the turn viability.
 
virtual std::string str () const
 String Turn representation.
 
virtual void apply (int mode=0)
 Apply turn.
 
virtual void undo ()
 Undo turn.
 
virtual bool isEqual (const Turn &rhs) const
 Compare turns.
 
virtual auto clone () const -> std::decay< decltype(*this)>::type *
 Clone current Turn.
 

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.
 
bool operator!= (const Turn &, const Turn &)
 Inverted comparison operator.
 
std::ostreamoperator<< (std::ostream &os, const Turn &t)
 std::ostream output
 

Detailed Description

Generic Piece Turn on Board.

Class should be defined as derived from Piece::Turn in every class derived 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
tpiecepointer to Piece that performs turn
toLocation where of tpiece after the turn is applied
capcaptured Piece. Should be provided if turn captures some pieces
possibletrue, if turn is marked as 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::Pawn::Turn, and tt::chess::King::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::Pawn::Turn, tt::chess::Knight::Turn, tt::chess::Bishop::Turn, tt::chess::Rook::Turn, tt::chess::Queen::Turn, and tt::chess::King::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 Symbol 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: