ChessPlusPlus
WIP
cplusplus.com Community Project
|
Manages pieces on a chess board. More...
#include <Board.hpp>
Classes | |
class | Movements |
Holds the valid movements for all pieces on the board. More... | |
Public Types | |
using | BoardSize_t = config::BoardConfig::BoardSize_t |
using | Position_t = config::BoardConfig::Position_t |
using | Suit = config::BoardConfig::SuitClass_t |
using | Pieces_t = std::set< std::unique_ptr< piece::Piece >> |
using | Movements_t = std::multimap< Pieces_t::const_iterator, Position_t, Pieces_t_const_iterator_compare > |
using | Factory_t = std::map< config::BoardConfig::PieceClass_t, std::function< Pieces_t::value_type(Board &, Position_t const &, Suit const &)>> |
using | MovementsRange = util::Range< Movements_t::const_iterator > |
Public Member Functions | |
Board (config::BoardConfig const &conf) | |
Constructs the Board from the given chesspp::config::BoardConfig. More... | |
bool | occupied (Position_t const &pos) const noexcept |
Check if a location on the board is occupied by at least one piece. More... | |
auto | find (piece::Piece const &p) const noexcept-> Pieces_t::const_iterator |
Given a Piece, obtain its iterator. More... | |
auto | begin () const noexcept-> Pieces_t::const_iterator |
Get the beginning iterator of the board pieces. More... | |
auto | end () const noexcept-> Pieces_t::const_iterator |
Get the end iterator of the board pieces. More... | |
Movements const & | pieceTrajectories () const noexcept |
Movements & | pieceTrajectories () noexcept |
Movements const & | pieceCapturings () const noexcept |
Movements & | pieceCapturings () noexcept |
Movements const & | pieceCapturables () const noexcept |
Movements & | pieceCapturables () noexcept |
MovementsRange | pieceTrajectory (piece::Piece const &p) noexcept |
MovementsRange | pieceCapturing (piece::Piece const &p) noexcept |
MovementsRange | pieceCapturable (piece::Piece const &p) noexcept |
bool | capture (Pieces_t::iterator source, Movements_t::const_iterator target, Movements_t::const_iterator capturable) |
Capture a capturable piece. More... | |
bool | move (Pieces_t::iterator source, Movements_t::const_iterator target) |
Move a piece without capturing. More... | |
bool | valid (Position_t const &pos) const noexcept |
Check if a position is a valid position that exists on the board. More... | |
Static Public Member Functions | |
static auto | registerPieceClass (Factory_t::key_type const &type, Factory_t::mapped_type ctor) -> Factory_t::iterator |
Register a new type of chess piece. More... | |
Public Attributes | |
config::BoardConfig const & | config |
The chesspp::config::BoardConfig currently in use. More... | |
Manages pieces on a chess board.
Can be iterated over with a range-based for-loop.
using chesspp::board::Board::Factory_t = std::map<config::BoardConfig::PieceClass_t, std::function<Pieces_t::value_type (Board &, Position_t const &, Suit const &)>> |
using chesspp::board::Board::Movements_t = std::multimap<Pieces_t::const_iterator, Position_t, Pieces_t_const_iterator_compare> |
using chesspp::board::Board::MovementsRange = util::Range<Movements_t::const_iterator> |
using chesspp::board::Board::Pieces_t = std::set<std::unique_ptr<piece::Piece>> |
chesspp::board::Board::Board | ( | config::BoardConfig const & | conf | ) |
Constructs the Board from the given chesspp::config::BoardConfig.
conf | The BoardConfig, must outlive this instance. |
|
inlinenoexcept |
Get the beginning iterator of the board pieces.
bool chesspp::board::Board::capture | ( | Pieces_t::iterator | source, |
Movements_t::const_iterator | target, | ||
Movements_t::const_iterator | capturable | ||
) |
Capture a capturable piece.
source | The piece performing the capture. |
target | The new location of the source piece. |
capturable | The location being captured. |
|
inlinenoexcept |
Get the end iterator of the board pieces.
|
noexcept |
Given a Piece, obtain its iterator.
p | The Piece to search for. |
bool chesspp::board::Board::move | ( | Pieces_t::iterator | source, |
Movements_t::const_iterator | target | ||
) |
Move a piece without capturing.
source | The piece being moved. |
target | The new location of the source piece. |
|
noexcept |
Check if a location on the board is occupied by at least one piece.
pos | The position to check. |
|
noexcept |
|
inlinenoexcept |
|
inlinenoexcept |
|
noexcept |
|
inlinenoexcept |
|
inlinenoexcept |
|
inlinenoexcept |
|
inlinenoexcept |
|
noexcept |
|
inlinestatic |
Register a new type of chess piece.
This should be called via assignment to a global variable in the source file of the chess piece implementation.
type | The unique type of the chess piece. |
ctor | The function used to construct new instances of the chess piece. |
|
inlinenoexcept |
Check if a position is a valid position that exists on the board.
pos | The position to check for validity. |
config::BoardConfig const& chesspp::board::Board::config |
The chesspp::config::BoardConfig currently in use.