Cute Chess  0.1
Classes | Public Types | Public Member Functions | Protected Types | Protected Member Functions | Protected Attributes | Static Protected Attributes | List of all members
Chess::WesternBoard Class Reference

A board for western chess variants. More...

#include <westernboard.h>

Inheritance diagram for Chess::WesternBoard:
Chess::Board Chess::AlmostBoard Chess::AmazonBoard Chess::AtomicBoard Chess::CapablancaBoard Chess::ChancellorBoard Chess::ChecklessBoard Chess::ChigorinBoard Chess::CoRegalBoard Chess::CrazyhouseBoard Chess::GryphonBoard Chess::GustavBoard Chess::HoppelPoppelBoard Chess::JanusBoard Chess::JesonMorBoard Chess::KnightMateBoard Chess::LosAlamosBoard Chess::LosersBoard Chess::ModernBoard Chess::NewZealandBoard Chess::PlacementBoard Chess::PocketKnightBoard Chess::RacingKingsBoard Chess::RestrictedMoveBoard Chess::RifleBoard Chess::SeirawanBoard Chess::ShatranjBoard Chess::StandardBoard Chess::ThreeKingsBoard Chess::TwoKingsEachBoard

Classes

struct  PawnStep
 

Public Types

enum  WesternPieceType {
  Pawn = 1, Knight, Bishop, Rook,
  Queen, King
}
 
- Public Types inherited from Chess::Board
enum  CoordinateSystem { NormalCoordinates, InvertedCoordinates }
 
enum  FenNotation { XFen, ShredderFen }
 
enum  MoveNotation { StandardAlgebraic, LongAlgebraic }
 

Public Member Functions

virtual int height () const
 
virtual Result result ()
 
virtual int reversibleMoveCount () const
 
 WesternBoard (WesternZobrist *zobrist)
 
virtual int width () const
 
- Public Member Functions inherited from Chess::Board
 Board (Zobrist *zobrist)
 
virtual CoordinateSystem coordinateSystem () const
 
virtual Boardcopy () const =0
 
virtual QString defaultFenString () const =0
 
QString fenString (FenNotation notation=XFen) const
 
GenericMove genericMove (const Move &move) const
 
void initialize ()
 
bool isLegalMove (const Move &move)
 
virtual bool isRandomVariant () const
 
bool isRepetition (const Move &move)
 
bool isValidSquare (const Square &square) const
 
quint64 key () const
 
QVector< MovelegalMoves ()
 
void makeMove (const Move &move, BoardTransition *transition=nullptr)
 
Move moveFromGenericMove (const GenericMove &move) const
 
Move moveFromString (const QString &str)
 
QString moveString (const Move &move, MoveNotation notation)
 
Piece pieceAt (const Square &square) const
 
Piece pieceFromSymbol (const QString &pieceSymbol) const
 
QStringList pieceList (Side side) const
 
QString pieceString (int pieceType) const
 
QString pieceSymbol (Piece piece) const
 
int plyCount () const
 
int repeatCount () const
 
QString representation (Piece piece) const
 
int reserveCount (Piece piece) const
 
virtual QList< PiecereservePieceTypes () const
 
void reset ()
 
bool setFenString (const QString &fen)
 
Side sideToMove () const
 
QString startingFenString () const
 
Side startingSide () const
 
virtual Result tablebaseResult (unsigned int *dtm=nullptr) const
 
void undoMove ()
 
virtual Side upperCaseSide () const
 
virtual QString variant () const =0
 
virtual bool variantHasDrops () const
 
virtual bool variantHasOptionalPromotions () const
 
virtual bool variantHasWallSquares () const
 
virtual ~Board ()
 

Protected Types

enum  CastlingSide { QueenSide, KingSide, NoCastlingSide }
 
enum  StepType { NoStep = 0, FreeStep = 1, CaptureStep = 2 }
 

Protected Member Functions

virtual void addPromotions (int sourceSquare, int targetSquare, QVarLengthArray< Move > &moves) const
 
virtual int captureType (const Move &move) const
 
virtual int castlingFile (CastlingSide castlingSide) const
 
int enpassantSquare () const
 
virtual void generateMovesForPiece (QVarLengthArray< Move > &moves, int pieceType, int square) const
 
virtual bool hasCastling () const
 
bool hasCastlingRight (Side side, CastlingSide castlingSide) const
 
virtual bool hasEnPassantCaptures () const
 
virtual bool inCheck (Side side, int square=0) const
 
virtual bool isLegalPosition ()
 
virtual bool kingCanCapture () const
 
virtual bool kingsCountAssertion (int whiteKings, int blackKings) const
 
int kingSquare (Side side) const
 
virtual QString lanMoveString (const Move &move)
 
virtual Move moveFromLanString (const QString &str)
 
virtual Move moveFromSanString (const QString &str)
 
virtual bool parseCastlingRights (QChar c)
 
int pawnAmbiguity (StepType type=FreeStep) const
 
virtual bool pawnHasDoubleStep () const
 
void removeCastlingRights (int square)
 
void removeCastlingRights (Side side)
 
virtual QString sanMoveString (const Move &move)
 
virtual bool variantHasChanneling (Side side, int square) const
 
virtual QString vFenIncludeString (FenNotation notation) const
 
virtual QString vFenString (FenNotation notation) const
 
virtual void vInitialize ()
 
virtual bool vIsLegalMove (const Move &move)
 
virtual void vMakeMove (const Move &move, BoardTransition *transition)
 
virtual bool vSetFenString (const QStringList &fen)
 
virtual void vUndoMove (const Move &move)
 
- Protected Member Functions inherited from Chess::Board
void addToReserve (const Piece &piece, int count=1)
 
int arraySize () const
 
bool canMove ()
 
Square chessSquare (int index) const
 
Square chessSquare (const QString &str) const
 
void generateDropMoves (QVarLengthArray< Move > &moves, int pieceType) const
 
void generateHoppingMoves (int sourceSquare, const QVarLengthArray< int > &offsets, QVarLengthArray< Move > &moves) const
 
void generateMoves (QVarLengthArray< Move > &moves, int pieceType=Piece::NoPiece) const
 
void generateSlidingMoves (int sourceSquare, const QVarLengthArray< int > &offsets, QVarLengthArray< Move > &moves) const
 
const MovelastMove () const
 
virtual int maxPieceSymbolLength () const
 
bool moveExists (const Move &move) const
 
Piece pieceAt (int square) const
 
bool pieceHasMovement (int pieceType, unsigned movement) const
 
void removeFromReserve (const Piece &piece)
 
virtual int reserveType (int pieceType) const
 
void setPieceType (int type, const QString &name, const QString &symbol, unsigned movement=0, const QString &gsymbol=QString())
 
void setSquare (int square, Piece piece)
 
int squareIndex (const Square &square) const
 
int squareIndex (const QString &str) const
 
QString squareString (int index) const
 
QString squareString (const Square &square) const
 
void xorKey (quint64 key)
 

Protected Attributes

QVarLengthArray< PawnStep, 8 > m_pawnSteps
 

Static Protected Attributes

static const unsigned BishopMovement = 4
 
static const unsigned KnightMovement = 2
 
static const unsigned RookMovement = 8
 

Detailed Description

A board for western chess variants.

WesternBoard serves as the overclass for all western variants. In addition to possibly unique pieces, a western variant has the same pieces as standard chess, the same rules for castling, en-passant capture, promotion, etc.

WesternBoard implements the rules of standard chess, including check, checkmate, stalemate, promotion, 3-fold repetition, 50 move rule and draws by insufficient material.

Member Enumeration Documentation

The king's castling side.

Enumerator
QueenSide 

Queen side (O-O-O)

KingSide 

King side (O-O)

NoCastlingSide 

No castling side.

Types of Pawn moves.

Enumerator
NoStep 

Cannot move here.

FreeStep 

May move if target is empty.

CaptureStep 

Capture opposing piece only.

Basic piece types for western variants.

Enumerator
Pawn 

Pawn.

Knight 

Knight.

Bishop 

Bishop.

Rook 

Rook.

Queen 

Queen.

King 

King.

Constructor & Destructor Documentation

Chess::WesternBoard::WesternBoard ( WesternZobrist zobrist)

Creates a new WesternBoard object.

Member Function Documentation

void Chess::WesternBoard::addPromotions ( int  sourceSquare,
int  targetSquare,
QVarLengthArray< Move > &  moves 
) const
protectedvirtual

Adds pawn promotions to a move list.

This function is called when a pawn can promote by moving from sourceSquare to targetSquare. This function generates all the possible promotions and adds them to moves.

Reimplemented in Chess::SittuyinBoard, Chess::ShatranjBoard, Chess::AseanBoard, Chess::AntiBoard, Chess::SeirawanBoard, Chess::CodrusBoard, Chess::ModernBoard, Chess::ExtinctionBoard, Chess::ChancellorBoard, Chess::JanusBoard, Chess::GustavBoard, Chess::ChigorinBoard, Chess::KnightMateBoard, Chess::RifleBoard, Chess::CapablancaBoard, and Chess::LosAlamosBoard.

int Chess::WesternBoard::captureType ( const Move move) const
protectedvirtual

Returns the type of piece captured by move. Returns Piece::NoPiece if move is not a capture.

Reimplemented from Chess::Board.

int Chess::WesternBoard::castlingFile ( CastlingSide  castlingSide) const
protectedvirtual

Defines the file a king may castle to on castlingSide. Defaults: 2 (c-file) and width() - 2 (normally g-file)

Reimplemented in Chess::JanusBoard, Chess::ModernBoard, Chess::ChancellorBoard, Chess::GustavBoard, and Chess::EmbassyBoard.

int Chess::WesternBoard::enpassantSquare ( ) const
protected

Returns the current en-passant square.

void Chess::WesternBoard::generateMovesForPiece ( QVarLengthArray< Move > &  moves,
int  pieceType,
int  square 
) const
protectedvirtual
bool Chess::WesternBoard::hasCastling ( ) const
protectedvirtual

Returns true if castling is allowed. The default value is true.

See also
ShatranjBoard

Reimplemented in Chess::ShatranjBoard, Chess::AntiBoard, Chess::GrandBoard, Chess::GiveawayBoard, and Chess::LosAlamosBoard.

bool Chess::WesternBoard::hasCastlingRight ( Side  side,
CastlingSide  castlingSide 
) const
protected

Returns true if side has a right to castle on castlingSide; otherwise returns false.

Note
Even if this function returns true, castling may not be a legal move in the current position.
bool Chess::WesternBoard::hasEnPassantCaptures ( ) const
protectedvirtual

Returns true if a pawn can be captured en passant after an initial double step. The default value is the value of pawnHasDoubleStep().

int Chess::WesternBoard::height ( ) const
virtual

Returns the height of the board in squares.

Implements Chess::Board.

Reimplemented in Chess::GrandBoard, Chess::ModernBoard, Chess::ChancellorBoard, Chess::GustavBoard, Chess::JesonMorBoard, and Chess::LosAlamosBoard.

bool Chess::WesternBoard::inCheck ( Side  side,
int  square = 0 
) const
protectedvirtual
bool Chess::WesternBoard::isLegalPosition ( )
protectedvirtual

Returns true if the current position is a legal position. If the position isn't legal it usually means that the last move was illegal.

Implements Chess::Board.

Reimplemented in Chess::ChangeOverBoard, Chess::SittuyinBoard, Chess::PlacementBoard, Chess::GryphonBoard, Chess::RacingKingsBoard, and Chess::ChecklessBoard.

bool Chess::WesternBoard::kingCanCapture ( ) const
protectedvirtual

Returns true if the king can capture opposing pieces. The default value is true.

See also
AtomicBoard

Reimplemented in Chess::AtomicBoard.

bool Chess::WesternBoard::kingsCountAssertion ( int  whiteKings,
int  blackKings 
) const
protectedvirtual

Returns true if both counts of kings given by whiteKings and blackKings are correct. WesternBoard expects exactly one king per side.

See also
AntiBoard
HordeBoard

Reimplemented in Chess::CircularGryphonBoard, Chess::SittuyinBoard, Chess::PlacementBoard, Chess::AntiBoard, Chess::CodrusBoard, Chess::ExtinctionBoard, Chess::HordeBoard, Chess::GryphonBoard, Chess::TwoKingsEachBoard, Chess::JesonMorBoard, and Chess::ThreeKingsBoard.

int Chess::WesternBoard::kingSquare ( Side  side) const
protected

Returns the king square of side.

QString Chess::WesternBoard::lanMoveString ( const Move move)
protectedvirtual

Converts a Move object into a string in Long Algebraic Notation (LAN)

Reimplemented from Chess::Board.

Reimplemented in Chess::SeirawanBoard.

Move Chess::WesternBoard::moveFromLanString ( const QString str)
protectedvirtual

Converts a string in LAN format into a Move object.

Reimplemented from Chess::Board.

Reimplemented in Chess::SeirawanBoard, and Chess::TwoKingsEachBoard.

Move Chess::WesternBoard::moveFromSanString ( const QString str)
protectedvirtual
bool Chess::WesternBoard::parseCastlingRights ( QChar  c)
protectedvirtual

Parse castling rights given by character c of the FEN token. Returns true if successful.

Reimplemented in Chess::SeirawanBoard, and Chess::OukBoard.

int Chess::WesternBoard::pawnAmbiguity ( StepType  type = FreeStep) const
protected

Helper function for Pawn moves. Returns the count of moves of the given type that are specified in pawnSteps.

bool Chess::WesternBoard::pawnHasDoubleStep ( ) const
protectedvirtual

Returns true if pawns have an initial double step option. The default value is true.

See also
ShatranjBoard

Reimplemented in Chess::ShatranjBoard, and Chess::LosAlamosBoard.

void Chess::WesternBoard::removeCastlingRights ( int  square)
protected

Removes castling rights at square.

If one of the players has a rook at square, the rook can't be used for castling. This function should be called when a capture happens at square.

void Chess::WesternBoard::removeCastlingRights ( Side  side)
protected

Removes all castling rights of side.

Result Chess::WesternBoard::result ( )
virtual
int Chess::WesternBoard::reversibleMoveCount ( ) const
virtual

Returns the number of consecutive reversible moves made.

The default implementation always returns -1.

Reimplemented from Chess::Board.

QString Chess::WesternBoard::sanMoveString ( const Move move)
protectedvirtual

Converts a Move object into a string in Standard Algebraic Notation (SAN).

Note
Specs: http://en.wikipedia.org/wiki/Algebraic_chess_notation

Implements Chess::Board.

Reimplemented in Chess::SeirawanBoard, Chess::CrazyhouseBoard, Chess::JanusBoard, Chess::AndernachBoard, and Chess::ModernBoard.

bool Chess::WesternBoard::variantHasChanneling ( Side  side,
int  square 
) const
protectedvirtual

Returns true if a rule provides side to insert a reserve piece at a vacated source square immediately after a move. The default value is false.

See also
SeirawanBoard

Reimplemented in Chess::SeirawanBoard.

QString Chess::WesternBoard::vFenIncludeString ( FenNotation  notation) const
protectedvirtual

Returns FEN extensions. The default is an empty string.

This function is called by fenString() via vFenString(). Returns additional parts of the current position's (extended) FEN string which succeed the en passant field.

Reimplemented in Chess::NCheckBoard.

QString Chess::WesternBoard::vFenString ( FenNotation  notation) const
protectedvirtual

Returns the latter part of the current position's FEN string.

This function is called by fenString(). The board state, side to move and hand pieces are handled by the base class. This function returns the rest of it, if any.

Implements Chess::Board.

Reimplemented in Chess::MakrukBoard, Chess::SeirawanBoard, Chess::OukBoard, and Chess::AseanBoard.

void Chess::WesternBoard::vInitialize ( )
protectedvirtual

Initializes the variant.

This function is called by initialize(). Subclasses shouldn't generally call it by themselves.

Implements Chess::Board.

Reimplemented in Chess::MakrukBoard, Chess::ShatranjBoard, Chess::CourierBoard, Chess::NCheckBoard, Chess::GryphonBoard, Chess::TwoKingsEachBoard, and Chess::AtomicBoard.

bool Chess::WesternBoard::vIsLegalMove ( const Move move)
protectedvirtual

Returns true if move is a legal move.

This function is called by isLegalMove() after making sure that there is a pseudo-legal move same as move. This function shouldn't check for the existence of move by generating moves.

The default implementation only checks if the position after move is legal.

Reimplemented from Chess::Board.

Reimplemented in Chess::SittuyinBoard, Chess::ShootBoard, Chess::AntiBoard, Chess::CodrusBoard, Chess::GrandBoard, Chess::HordeBoard, Chess::AtomicBoard, Chess::LosersBoard, and Chess::RestrictedMoveBoard.

void Chess::WesternBoard::vMakeMove ( const Move move,
BoardTransition transition 
)
protectedvirtual

Makes move on the board.

This function is called by makeMove(), and should take care of everything except changing the side to move and updating the move history.

Details about piece movement, promotions, captures, drops, etc. should be stored in transition. If transition is 0 then it should be ignored.

Implements Chess::Board.

Reimplemented in Chess::MakrukBoard, Chess::SimplifiedGryphonBoard, Chess::SittuyinBoard, Chess::OukBoard, Chess::SeirawanBoard, Chess::CrazyhouseBoard, Chess::PlacementBoard, Chess::AndernachBoard, Chess::NCheckBoard, Chess::GryphonBoard, Chess::GiveawayBoard, Chess::PocketKnightBoard, Chess::AtomicBoard, and Chess::RifleBoard.

bool Chess::WesternBoard::vSetFenString ( const QStringList fen)
protectedvirtual

Sets the board according to a FEN string.

This function is called by setFenString(). The board state, side to move and hand pieces are handled by the base class. This function reads the rest of the string, if any.

Implements Chess::Board.

Reimplemented in Chess::MakrukBoard, Chess::SittuyinBoard, Chess::OukBoard, Chess::AseanBoard, Chess::SeirawanBoard, Chess::PlacementBoard, Chess::AntiBoard, Chess::NCheckBoard, Chess::AtomicBoard, and Chess::LosersBoard.

void Chess::WesternBoard::vUndoMove ( const Move move)
protectedvirtual

Reverses move on the board.

This function is called by undoMove() after changing the side to move to the side that made it.

Note
Unlike vMakeMove(), this function doesn't require subclasses to update the zobrist position key.

Implements Chess::Board.

Reimplemented in Chess::MakrukBoard, Chess::SimplifiedGryphonBoard, Chess::SittuyinBoard, Chess::OukBoard, Chess::SeirawanBoard, Chess::CrazyhouseBoard, Chess::PlacementBoard, Chess::AndernachBoard, Chess::NCheckBoard, Chess::GryphonBoard, Chess::PocketKnightBoard, Chess::AtomicBoard, and Chess::RifleBoard.

int Chess::WesternBoard::width ( ) const
virtual

Member Data Documentation

const unsigned Chess::WesternBoard::BishopMovement = 4
staticprotected

Movement mask for Bishop moves.

const unsigned Chess::WesternBoard::KnightMovement = 2
staticprotected

Movement mask for Knight moves.

QVarLengthArray<PawnStep, 8> Chess::WesternBoard::m_pawnSteps
protected

Movement mask for Pawn moves. Lists pawn move types and relative files

See also
BerolinaBoard

Default: A Pawn can step straight ahead onto a free square or capture diagonally forward. So initialise this as { {CaptureStep, -1}, {FreeStep, 0}, {CaptureStep, 1} }

const unsigned Chess::WesternBoard::RookMovement = 8
staticprotected

Movement mask for Rook moves.


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