|
Cute Chess
0.1
|
An internal chessboard class. More...
#include <board.h>
Public Types | |
| enum | CoordinateSystem { NormalCoordinates, InvertedCoordinates } |
| enum | FenNotation { XFen, ShredderFen } |
| enum | MoveNotation { StandardAlgebraic, LongAlgebraic } |
Public Member Functions | |
| Board (Zobrist *zobrist) | |
| virtual CoordinateSystem | coordinateSystem () const |
| virtual Board * | copy () const =0 |
| virtual QString | defaultFenString () const =0 |
| QString | fenString (FenNotation notation=XFen) const |
| GenericMove | genericMove (const Move &move) const |
| virtual int | height () const =0 |
| 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< Move > | legalMoves () |
| 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< Piece > | reservePieceTypes () const |
| void | reset () |
| virtual Result | result ()=0 |
| virtual int | reversibleMoveCount () const |
| 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 int | width () const =0 |
| virtual | ~Board () |
Protected Member Functions | |
| void | addToReserve (const Piece &piece, int count=1) |
| int | arraySize () const |
| bool | canMove () |
| virtual int | captureType (const Move &move) const |
| 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 |
| virtual void | generateMovesForPiece (QVarLengthArray< Move > &moves, int pieceType, int square) const =0 |
| void | generateSlidingMoves (int sourceSquare, const QVarLengthArray< int > &offsets, QVarLengthArray< Move > &moves) const |
| virtual bool | isLegalPosition ()=0 |
| virtual QString | lanMoveString (const Move &move) |
| const Move & | lastMove () const |
| virtual int | maxPieceSymbolLength () const |
| bool | moveExists (const Move &move) const |
| virtual Move | moveFromLanString (const QString &str) |
| virtual Move | moveFromSanString (const QString &str)=0 |
| Piece | pieceAt (int square) const |
| bool | pieceHasMovement (int pieceType, unsigned movement) const |
| void | removeFromReserve (const Piece &piece) |
| virtual int | reserveType (int pieceType) const |
| virtual QString | sanMoveString (const Move &move)=0 |
| 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 |
| virtual QString | vFenString (FenNotation notation) const =0 |
| virtual void | vInitialize ()=0 |
| virtual bool | vIsLegalMove (const Move &move) |
| virtual void | vMakeMove (const Move &move, BoardTransition *transition)=0 |
| virtual bool | vSetFenString (const QStringList &fen)=0 |
| virtual void | vUndoMove (const Move &move)=0 |
| void | xorKey (quint64 key) |
Friends | |
| LIB_EXPORT QDebug | operator<< (QDebug dbg, const Board *board) |
An internal chessboard class.
This is the base class for all chess variants. Board's main purposes are:
Coordinate system for the notation of the squares.
Notation for FEN strings.
| Enumerator | |
|---|---|
| XFen |
X-FEN notation.
|
| ShredderFen |
Shredder FEN notation. |
| Chess::Board::Board | ( | Zobrist * | zobrist | ) |
|
virtual |
Destructs the Board object.
|
protected |
Adds count pieces of type piece to the reserve.
|
inlineprotected |
Returns the size of the board array, including the padding (the inaccessible wall squares).
|
protected |
Returns true if the side to move has any legal moves.
|
protectedvirtual |
Returns the type of piece captured by move. Returns Piece::NoPiece if move is not a capture.
Reimplemented in Chess::WesternBoard.
|
protected |
Converts a square index into a Square object.
Converts a string into a Square object.
|
virtual |
Returns the coordinate system used in the variant.
|
pure virtual |
Creates and returns a deep copy of this board.
Implemented in Chess::ChangeOverBoard, Chess::CircularGryphonBoard, Chess::BerolinaGridBoard, Chess::SlippedGridBoard, Chess::KarOukBoard, Chess::SuperAndernachBoard, Chess::SimplifiedGryphonBoard, Chess::FiveCheckBoard, Chess::TwoKingsSymmetricalBoard, Chess::KingletBoard, Chess::ThreeCheckBoard, Chess::AntiAndernachBoard, Chess::DisplacedGridBoard, Chess::MakrukBoard, Chess::ShootBoard, Chess::SittuyinBoard, Chess::NewZealandBoard, Chess::AseanBoard, Chess::CourierBoard, Chess::ShatranjBoard, Chess::CodrusBoard, Chess::GrandBoard, Chess::AntiBoard, Chess::ExtinctionBoard, Chess::PlacementBoard, Chess::SuicideBoard, Chess::HordeBoard, Chess::OukBoard, Chess::GiveawayBoard, Chess::AndernachBoard, Chess::GryphonBoard, Chess::ModernBoard, Chess::SeirawanBoard, Chess::ChancellorBoard, Chess::JanusBoard, Chess::NCheckBoard, Chess::ChigorinBoard, Chess::BerolinaBoard, Chess::ChessgiBoard, Chess::CoRegalBoard, Chess::GustavBoard, Chess::TwoKingsEachBoard, Chess::GridBoard, Chess::KingOfTheHillBoard, Chess::LoopBoard, Chess::PocketKnightBoard, Chess::AlmostBoard, Chess::EmbassyBoard, Chess::HoppelPoppelBoard, Chess::RacingKingsBoard, Chess::RifleBoard, Chess::AmazonBoard, Chess::ChecklessBoard, Chess::FrcBoard, Chess::StandardBoard, Chess::LosAlamosBoard, Chess::ThreeKingsBoard, Chess::CaparandomBoard, Chess::JesonMorBoard, Chess::CrazyhouseBoard, Chess::GothicBoard, Chess::KnightMateBoard, Chess::LosersBoard, Chess::AiWokBoard, Chess::AtomicBoard, Chess::CapablancaBoard, and Chess::RestrictedMoveBoard.
|
pure virtual |
Returns the variant's default starting FEN string.
Implemented in Chess::ChangeOverBoard, Chess::CircularGryphonBoard, Chess::BerolinaGridBoard, Chess::SlippedGridBoard, Chess::KarOukBoard, Chess::SimplifiedGryphonBoard, Chess::TwoKingsSymmetricalBoard, Chess::DisplacedGridBoard, Chess::MakrukBoard, Chess::SittuyinBoard, Chess::NewZealandBoard, Chess::AseanBoard, Chess::CourierBoard, Chess::GrandBoard, Chess::ShatranjBoard, Chess::AntiBoard, Chess::ExtinctionBoard, Chess::PlacementBoard, Chess::HordeBoard, Chess::OukBoard, Chess::GiveawayBoard, Chess::FrcBoard, Chess::GryphonBoard, Chess::ModernBoard, Chess::SeirawanBoard, Chess::ChancellorBoard, Chess::JanusBoard, Chess::CaparandomBoard, Chess::NCheckBoard, Chess::ChigorinBoard, Chess::CoRegalBoard, Chess::GustavBoard, Chess::PocketKnightBoard, Chess::TwoKingsEachBoard, Chess::GridBoard, Chess::LoopBoard, Chess::RacingKingsBoard, Chess::AlmostBoard, Chess::EmbassyBoard, Chess::HoppelPoppelBoard, Chess::LosAlamosBoard, Chess::RifleBoard, Chess::AmazonBoard, Chess::ChecklessBoard, Chess::JesonMorBoard, Chess::StandardBoard, Chess::CrazyhouseBoard, Chess::ThreeKingsBoard, Chess::CapablancaBoard, Chess::GothicBoard, Chess::KnightMateBoard, Chess::LosersBoard, Chess::AiWokBoard, and Chess::AtomicBoard.
| QString Chess::Board::fenString | ( | FenNotation | notation = XFen | ) | const |
Returns the FEN string of the current board position in X-Fen or Shredder FEN notation
|
protected |
Generates piece drops for pieces of type pieceType.
|
protected |
Generates hopping moves for a piece.
| sourceSquare | The source square of the hopping piece |
| offsets | An array of offsets for the target square |
|
protected |
Generates pseudo-legal moves for pieces of type pieceType.
|
protectedpure virtual |
Generates pseudo-legal moves for a piece of pieceType at square square.
Implemented in Chess::WesternBoard, Chess::ChangeOverBoard, Chess::MakrukBoard, Chess::SimplifiedGryphonBoard, Chess::SittuyinBoard, Chess::ShatranjBoard, Chess::CourierBoard, Chess::NewZealandBoard, Chess::SeirawanBoard, Chess::CrazyhouseBoard, Chess::OukBoard, Chess::PlacementBoard, Chess::GrandBoard, Chess::GryphonBoard, Chess::PocketKnightBoard, Chess::TwoKingsEachBoard, Chess::KnightMateBoard, and Chess::HoppelPoppelBoard.
|
protected |
Generates sliding moves for a piece.
| sourceSquare | The source square of the sliding piece |
| offsets | An array of offsets for the target square |
| GenericMove Chess::Board::genericMove | ( | const Move & | move | ) | const |
Converts a Move into a GenericMove.
|
pure virtual |
Returns the height of the board in squares.
Implemented in Chess::GrandBoard, Chess::WesternBoard, Chess::ModernBoard, Chess::ChancellorBoard, Chess::GustavBoard, Chess::JesonMorBoard, and Chess::LosAlamosBoard.
| void Chess::Board::initialize | ( | ) |
Initializes the board. This function must be called before a game can be started on the board.
| bool Chess::Board::isLegalMove | ( | const Move & | move | ) |
Returns true if move is legal in the current position.
|
protectedpure virtual |
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.
Implemented in Chess::WesternBoard, Chess::ChangeOverBoard, Chess::SittuyinBoard, Chess::PlacementBoard, Chess::GryphonBoard, Chess::RacingKingsBoard, and Chess::ChecklessBoard.
|
virtual |
Returns true if the variant uses randomized starting positions. The default value is false.
Reimplemented in Chess::FrcBoard, and Chess::CaparandomBoard.
| bool Chess::Board::isRepetition | ( | const Move & | move | ) |
Returns true if move repeats a position that was reached earlier in the game.
| bool Chess::Board::isValidSquare | ( | const Square & | square | ) | const |
Returns true if square is on the board.
|
inline |
Returns the zobrist key for the current position.
Converts a Move object into a string in Long Algebraic Notation (LAN)
Reimplemented in Chess::WesternBoard, and Chess::SeirawanBoard.
|
inlineprotected |
Returns the last move made in the game.
Returns a vector of legal moves in the current position.
| void Chess::Board::makeMove | ( | const Move & | move, |
| BoardTransition * | transition = nullptr |
||
| ) |
Makes a chess move on the board.
All details about piece movement, promotions, captures, drops, etc. are stored in transition. These details are useful mainly for updating a graphical representation of the board.
|
protectedvirtual |
Returns the maximal length of a piece symbol
Reimplemented in Chess::LoopBoard.
|
protected |
Returns true if a pseudo-legal move move exists.
| Move Chess::Board::moveFromGenericMove | ( | const GenericMove & | move | ) | const |
Converts a GenericMove into a Move.
Converts a string in LAN format into a Move object.
Reimplemented in Chess::WesternBoard, Chess::SeirawanBoard, and Chess::TwoKingsEachBoard.
Converts a string in SAN format into a Move object.
Implemented in Chess::WesternBoard, Chess::SeirawanBoard, Chess::CrazyhouseBoard, Chess::JanusBoard, Chess::AndernachBoard, Chess::TwoKingsEachBoard, Chess::KnightMateBoard, and Chess::ModernBoard.
Converts a move string into a Move.
| QString Chess::Board::moveString | ( | const Move & | move, |
| MoveNotation | notation | ||
| ) |
Converts a Move into a string.
|
inlineprotected |
Returns the piece at square.
Converts pieceSymbol into a Piece object.
|
inlineprotected |
Returns true if pieceType can move like movement.
| QStringList Chess::Board::pieceList | ( | Side | side | ) | const |
Returns list of the pieces of side in current position.
| QString Chess::Board::pieceString | ( | int | pieceType | ) | const |
Returns the internationalized name of pieceType.
|
inline |
Returns the number of halfmoves (plies) played.
|
protected |
Removes a piece of type piece from the reserve.
| int Chess::Board::repeatCount | ( | ) | const |
Returns the number of times the current position was reached previously in the game.
Returns symbol for graphical representation of piece.
| int Chess::Board::reserveCount | ( | Piece | piece | ) | const |
Returns the number of reserve pieces of type piece.
On variants that don't have piece drops this function always returns 0.
Returns a list of piece types that can be in the reserve, ie. captured pieces that can be dropped on the board.
The default implementation returns an empty list.
Reimplemented in Chess::SittuyinBoard, Chess::SeirawanBoard, Chess::PlacementBoard, Chess::PocketKnightBoard, and Chess::CrazyhouseBoard.
|
protectedvirtual |
Returns the reserve piece type corresponding to pieceType.
The returned value is the type of piece a player receives (in variants that have piece drops) when he captures a piece of type pieceType.
The default value is pieceType.
Reimplemented in Chess::CrazyhouseBoard, and Chess::PocketKnightBoard.
| void Chess::Board::reset | ( | ) |
Sets the board position to the default starting position of the chess variant.
|
pure virtual |
Returns the result of the game, or Result::NoResult if the game is in progress.
Implemented in Chess::SittuyinBoard, Chess::KarOukBoard, Chess::MakrukBoard, Chess::AseanBoard, Chess::ShatranjBoard, Chess::AntiBoard, Chess::CodrusBoard, Chess::ExtinctionBoard, Chess::PlacementBoard, Chess::WesternBoard, Chess::HordeBoard, Chess::NCheckBoard, Chess::TwoKingsEachBoard, Chess::KingOfTheHillBoard, Chess::JesonMorBoard, Chess::RacingKingsBoard, Chess::ThreeKingsBoard, Chess::LosersBoard, and Chess::AtomicBoard.
|
virtual |
Returns the number of consecutive reversible moves made.
The default implementation always returns -1.
Reimplemented in Chess::WesternBoard.
Converts a Move object into a string in Standard Algebraic Notation (SAN).
Implemented in Chess::WesternBoard, Chess::SeirawanBoard, Chess::CrazyhouseBoard, Chess::JanusBoard, Chess::AndernachBoard, and Chess::ModernBoard.
| bool Chess::Board::setFenString | ( | const QString & | fen | ) |
Sets the board position according to a FEN string.
The fen string can be in standard FEN, X-FEN or Shredder FEN notation.
Returns true if successful; otherwise returns false.
|
protected |
Defines a piece type used in the variant. If the piece isn't already defined, it's gets added here. Unlike other initialization which happens in vInitialize(), all piece types should be defined in the constructor.
| type | Type of the piece in integer format |
| name | The piece's name (internationalized string) |
| symbol | Short piece name or piece symbol |
| movement | A bit mask for the kinds of moves the piece can make. |
| gsymbol | Select the piece's graphical representation. If not set the symbol will be used (default). |
|
inlineprotected |
Sets square to contain piece.
This function also updates the zobrist position key, so subclasses shouldn't mess with it directly.
|
inline |
Returns the side to move.
|
protected |
Converts a Square object into a square index.
|
protected |
Converts a string into a square index.
|
protected |
Converts a square index into a string.
Converts a Square object into a string.
|
inline |
Returns the FEN string of the starting position.
|
inline |
Returns the side that made/makes the first move.
|
virtual |
Returns the expected game result according to endgame tablebases.
If the position is a win for either player, dtm is set to the distance to mate, ie. the number of plies it takes to force a mate.
The default implementation always returns a null result.
Reimplemented in Chess::StandardBoard.
| void Chess::Board::undoMove | ( | ) |
Reverses the last move.
|
virtual |
Returns the side whose pieces are denoted by uppercase letters. The default value is White.
|
pure virtual |
Returns the name of the chess variant.
Implemented in Chess::ChangeOverBoard, Chess::CircularGryphonBoard, Chess::BerolinaGridBoard, Chess::SlippedGridBoard, Chess::KarOukBoard, Chess::SuperAndernachBoard, Chess::SimplifiedGryphonBoard, Chess::TwoKingsSymmetricalBoard, Chess::KingletBoard, Chess::AntiAndernachBoard, Chess::DisplacedGridBoard, Chess::MakrukBoard, Chess::ShootBoard, Chess::SittuyinBoard, Chess::NewZealandBoard, Chess::AseanBoard, Chess::CourierBoard, Chess::ShatranjBoard, Chess::CodrusBoard, Chess::GrandBoard, Chess::AntiBoard, Chess::ExtinctionBoard, Chess::PlacementBoard, Chess::SuicideBoard, Chess::HordeBoard, Chess::OukBoard, Chess::GiveawayBoard, Chess::AndernachBoard, Chess::GryphonBoard, Chess::ModernBoard, Chess::SeirawanBoard, Chess::ChancellorBoard, Chess::JanusBoard, Chess::NCheckBoard, Chess::ChigorinBoard, Chess::BerolinaBoard, Chess::ChessgiBoard, Chess::CoRegalBoard, Chess::GustavBoard, Chess::PocketKnightBoard, Chess::TwoKingsEachBoard, Chess::GridBoard, Chess::KingOfTheHillBoard, Chess::LoopBoard, Chess::AlmostBoard, Chess::EmbassyBoard, Chess::HoppelPoppelBoard, Chess::RacingKingsBoard, Chess::RifleBoard, Chess::AmazonBoard, Chess::ChecklessBoard, Chess::FrcBoard, Chess::StandardBoard, Chess::LosAlamosBoard, Chess::ThreeKingsBoard, Chess::CaparandomBoard, Chess::CrazyhouseBoard, Chess::JesonMorBoard, Chess::GothicBoard, Chess::KnightMateBoard, Chess::LosersBoard, Chess::AiWokBoard, Chess::AtomicBoard, and Chess::CapablancaBoard.
|
virtual |
Returns true if the variant allows piece drops. The default value is false.
Reimplemented in Chess::SittuyinBoard, Chess::SeirawanBoard, Chess::PlacementBoard, Chess::PocketKnightBoard, and Chess::CrazyhouseBoard.
|
virtual |
Returns true if the variant allows to skip a promotion (or a move treated as promotion) and make a normal move instead. The default value is false, i.e. mandatory promotions.
Reimplemented in Chess::SittuyinBoard, Chess::SeirawanBoard, and Chess::GrandBoard.
|
virtual |
Returns true if the board accepts wall squares, else false. The default value is false.
Reimplemented in Chess::GustavBoard.
|
protectedpure virtual |
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.
Implemented in Chess::WesternBoard, Chess::MakrukBoard, Chess::SeirawanBoard, Chess::OukBoard, and Chess::AseanBoard.
|
protectedpure virtual |
Initializes the variant.
This function is called by initialize(). Subclasses shouldn't generally call it by themselves.
Implemented in Chess::WesternBoard, Chess::MakrukBoard, Chess::ShatranjBoard, Chess::CourierBoard, Chess::NCheckBoard, Chess::GryphonBoard, Chess::TwoKingsEachBoard, and Chess::AtomicBoard.
|
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 in Chess::WesternBoard, Chess::SittuyinBoard, Chess::ShootBoard, Chess::AntiBoard, Chess::CodrusBoard, Chess::GrandBoard, Chess::HordeBoard, Chess::AtomicBoard, Chess::LosersBoard, and Chess::RestrictedMoveBoard.
|
protectedpure virtual |
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.
Implemented in Chess::WesternBoard, 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.
|
protectedpure virtual |
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.
Implemented in Chess::WesternBoard, Chess::MakrukBoard, Chess::SittuyinBoard, Chess::OukBoard, Chess::AseanBoard, Chess::SeirawanBoard, Chess::PlacementBoard, Chess::AntiBoard, Chess::NCheckBoard, Chess::AtomicBoard, and Chess::LosersBoard.
|
protectedpure virtual |
Reverses move on the board.
This function is called by undoMove() after changing the side to move to the side that made it.
Implemented in Chess::WesternBoard, 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.
|
pure virtual |
Returns the width of the board in squares.
Implemented in Chess::CourierBoard, Chess::WesternBoard, Chess::ModernBoard, Chess::ChancellorBoard, Chess::JanusBoard, Chess::GustavBoard, Chess::LosAlamosBoard, Chess::JesonMorBoard, and Chess::CapablancaBoard.
|
inlineprotected |
Updates the zobrist position key with key.
1.8.11