Cute Chess 0.1
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 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 (const QString &str) const
Square chessSquare (int index) 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 QString &str) const
int squareIndex (const Square &square) const
QString squareString (const Square &square) const
QString squareString (int index) 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

◆ CastlingSide

The king's castling side.

Enumerator
QueenSide 

Queen side (O-O-O).

KingSide 

King side (O-O).

NoCastlingSide 

No castling side.

◆ StepType

Types of Pawn moves.

Enumerator
NoStep 

Cannot move here.

FreeStep 

May move if target is empty.

CaptureStep 

Capture opposing piece only.

◆ WesternPieceType

Basic piece types for western variants.

Enumerator
Pawn 

Pawn.

Knight 

Knight.

Bishop 

Bishop.

Rook 

Rook.

Queen 

Queen.

King 

King.

Constructor & Destructor Documentation

◆ WesternBoard()

Chess::WesternBoard::WesternBoard ( WesternZobrist * zobrist)

Creates a new WesternBoard object.

Member Function Documentation

◆ addPromotions()

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::AntiBoard, Chess::AseanBoard, Chess::CapablancaBoard, Chess::ChancellorBoard, Chess::ChigorinBoard, Chess::CodrusBoard, Chess::ExtinctionBoard, Chess::GustavBoard, Chess::JanusBoard, Chess::KnightMateBoard, Chess::LosAlamosBoard, Chess::ModernBoard, Chess::RifleBoard, Chess::SeirawanBoard, Chess::ShatranjBoard, and Chess::SittuyinBoard.

◆ captureType()

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.

◆ castlingFile()

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::ChancellorBoard, Chess::EmbassyBoard, Chess::GustavBoard, Chess::JanusBoard, and Chess::ModernBoard.

◆ enpassantSquare()

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

Returns the current en-passant square.

◆ generateMovesForPiece()

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

◆ hasCastling()

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

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

See also
ShatranjBoard

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

◆ hasCastlingRight()

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.

◆ hasEnPassantCaptures()

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().

◆ height()

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

Returns the height of the board in squares.

Implements Chess::Board.

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

◆ inCheck()

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

◆ isLegalPosition()

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::ChecklessBoard, Chess::GryphonBoard, Chess::PlacementBoard, Chess::RacingKingsBoard, and Chess::SittuyinBoard.

◆ kingCanCapture()

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.

◆ kingsCountAssertion()

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::AntiBoard, Chess::CircularGryphonBoard, Chess::CodrusBoard, Chess::ExtinctionBoard, Chess::GryphonBoard, Chess::HordeBoard, Chess::JesonMorBoard, Chess::PlacementBoard, Chess::SittuyinBoard, Chess::ThreeKingsBoard, and Chess::TwoKingsEachBoard.

◆ kingSquare()

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

Returns the king square of side.

◆ lanMoveString()

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.

◆ moveFromLanString()

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.

◆ moveFromSanString()

Move Chess::WesternBoard::moveFromSanString ( const QString & str)
protectedvirtual

◆ parseCastlingRights()

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::OukBoard, and Chess::SeirawanBoard.

◆ pawnAmbiguity()

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.

◆ pawnHasDoubleStep()

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::LosAlamosBoard, and Chess::ShatranjBoard.

◆ removeCastlingRights() [1/2]

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.

◆ removeCastlingRights() [2/2]

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

Removes all castling rights of side.

◆ result()

◆ reversibleMoveCount()

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

Returns the number of consecutive reversible moves made.

The default implementation always returns -1.

Reimplemented from Chess::Board.

◆ sanMoveString()

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::AndernachBoard, Chess::CrazyhouseBoard, Chess::JanusBoard, Chess::ModernBoard, and Chess::SeirawanBoard.

◆ variantHasChanneling()

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.

◆ vFenIncludeString()

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.

◆ vFenString()

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::AseanBoard, Chess::MakrukBoard, Chess::OukBoard, and Chess::SeirawanBoard.

◆ vInitialize()

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::AtomicBoard, Chess::CourierBoard, Chess::GryphonBoard, Chess::MakrukBoard, Chess::NCheckBoard, Chess::ShatranjBoard, and Chess::TwoKingsEachBoard.

◆ vIsLegalMove()

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::AntiBoard, Chess::AtomicBoard, Chess::CodrusBoard, Chess::GrandBoard, Chess::HordeBoard, Chess::LosersBoard, Chess::RestrictedMoveBoard, Chess::ShootBoard, and Chess::SittuyinBoard.

◆ vMakeMove()

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::AndernachBoard, Chess::AtomicBoard, Chess::CrazyhouseBoard, Chess::GiveawayBoard, Chess::GryphonBoard, Chess::MakrukBoard, Chess::NCheckBoard, Chess::OukBoard, Chess::PlacementBoard, Chess::PocketKnightBoard, Chess::RifleBoard, Chess::SeirawanBoard, Chess::SimplifiedGryphonBoard, and Chess::SittuyinBoard.

◆ vSetFenString()

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::AntiBoard, Chess::AseanBoard, Chess::AtomicBoard, Chess::LosersBoard, Chess::MakrukBoard, Chess::NCheckBoard, Chess::OukBoard, Chess::PlacementBoard, Chess::SeirawanBoard, and Chess::SittuyinBoard.

◆ vUndoMove()

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::AndernachBoard, Chess::AtomicBoard, Chess::CrazyhouseBoard, Chess::GryphonBoard, Chess::MakrukBoard, Chess::NCheckBoard, Chess::OukBoard, Chess::PlacementBoard, Chess::PocketKnightBoard, Chess::RifleBoard, Chess::SeirawanBoard, Chess::SimplifiedGryphonBoard, and Chess::SittuyinBoard.

◆ width()

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

Member Data Documentation

◆ BishopMovement

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

Movement mask for Bishop moves.

◆ KnightMovement

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

Movement mask for Knight moves.

◆ m_pawnSteps

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} }

◆ RookMovement

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

Movement mask for Rook moves.


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