Cute Chess 0.1
Chess::MakrukBoard Class Reference

A board for Makruk (Thai Chess). More...

#include <makrukboard.h>

Inheritance diagram for Chess::MakrukBoard:
Chess::ShatranjBoard Chess::WesternBoard Chess::Board Chess::AiWokBoard Chess::AseanBoard Chess::OukBoard Chess::SittuyinBoard Chess::KarOukBoard

Public Member Functions

virtual Boardcopy () const
virtual QString defaultFenString () const
 MakrukBoard ()
virtual Result result ()
virtual QString variant () const
Public Member Functions inherited from Chess::ShatranjBoard
 ShatranjBoard ()
Public Member Functions inherited from Chess::WesternBoard
virtual int height () const
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
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 bool variantHasDrops () const
virtual bool variantHasWallSquares () const
virtual ~Board ()

Protected Types

enum  CountingRules { Makruk , BareKing }
enum  MakrukPieceType {
  Bia = Pawn , Ma = Knight , Khon = Bishop , Rua = Rook ,
  Met = Queen , Khun = King
}
Protected Types inherited from Chess::ShatranjBoard
enum  ShatranjPieceType { Ferz = Queen , Alfil = Bishop }
Protected Types inherited from Chess::WesternBoard
enum  CastlingSide { QueenSide , KingSide , NoCastlingSide }
enum  StepType { NoStep = 0 , FreeStep = 1 , CaptureStep = 2 }

Protected Member Functions

virtual int countingLimit () const
virtual CountingRules countingRules () const
virtual void generateMovesForPiece (QVarLengthArray< Move > &moves, int pieceType, int square) const
virtual void generatePawnMoves (int sourceSquare, QVarLengthArray< Move > &moves) const
virtual bool inCheck (Side side, int square=0) const
void initHistory ()
virtual bool insufficientMaterial () const
int pieceCount (Side side=Side::NoSide, int pieceType=Piece::NoPiece) const
virtual int promotionRank (int file=0) const
Result resultFromCounting () const
void setAllPieceCounters ()
virtual QString vFenString (FenNotation notation) const
virtual void vInitialize ()
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::ShatranjBoard
virtual void addPromotions (int sourceSquare, int targetSquare, QVarLengthArray< Move > &moves) const
virtual bool canBareOpponentKing ()
virtual bool hasCastling () const
virtual bool pawnHasDoubleStep () const
Protected Member Functions inherited from Chess::WesternBoard
virtual int captureType (const Move &move) const
virtual int castlingFile (CastlingSide castlingSide) const
int enpassantSquare () const
bool hasCastlingRight (Side side, CastlingSide castlingSide) const
virtual bool hasEnPassantCaptures () 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
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 bool vIsLegalMove (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)

Static Protected Attributes

static const unsigned SilverGeneralMovement = 256
Static Protected Attributes inherited from Chess::ShatranjBoard
static const unsigned AlfilMovement = 32
static const unsigned FerzMovement = 16
Static Protected Attributes inherited from Chess::WesternBoard
static const unsigned BishopMovement = 4
static const unsigned KnightMovement = 2
static const unsigned RookMovement = 8

Additional Inherited Members

Public Types inherited from Chess::WesternBoard
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 }
Protected Attributes inherited from Chess::WesternBoard
QVarLengthArray< PawnStep, 8 > m_pawnSteps

Detailed Description

A board for Makruk (Thai Chess).

Makruk Chess is a variant of chess popular and with a long tradition in Thailand. It is very similar to Ouk Cha Trang (Cambodian Chess).

The Pawn, Knight, Rook, Ferz, and King are all traditional pieces with movements known from Chaturanga and Shatranj. In Makruk these pieces are named differently (with other meanings).

The Elephant (Gaja, Alfil) was replaced by the Khon (Base) which moves like Shogi's Silver General: 1 square diagonally or 1 square forward. Met is the Thai name of the Ferz which only moves 1 square diagonally.

Makruk has no Pawn double step option and no castling. When reaching the own sixth rank a Pawn (Bia, shell) is promoted to Ferz (Met, grain).

Like in standard chess giving mate wins, stalemate is a draw, and two bare kings is a draw. If there is (obviously) not enough material to force a win, the game will be drawn.

There is no fifty-move rule. When the last Pawn on the board is captured or promoted the game must be won within 64 moves else the game is drawn.

A new counting overrides when there are no Pawns on the board and a side is left with no pieces besides their "bare" King. The starting count equals 1 plus the number of pieces.

The counting limit depends on the stronger side: If they have 2 Rooks (with or without other pieces) it is 8 moves, 1 Rook: 16 moves, 2 Khons: 22 moves, 2 Knights: 32 moves, 1 Khon: 44 moves, else 64 moves. When the count exceeds the limit the game is drawn. There is no counting as long as there are any unpromoted pawns on the board.

Example: For KRRNP vs K the weaker side will count their moves 7 (= 1 + 6) and 8 (the limit defined by 2 Rooks), and if they have a legal move at count 9 the game will end in a draw.

Note
Rules: http://en.wikipedia.org/wiki/Makruk_chess
See also
ShatranjBoard
OukBoard
Note
This implementation can read and write positions in FEN standard notation and per default an adapted FEN notation where the fields have Makruk/Ouk specific meanings to support the counting rules: The castling field is present but unused in Makruk - it is used for initial move status in Ouk. The en passant field "-" is replaced by the active Makruk counting limit in plies. The half move count gives a ply count according to endgame counting rules instead of the reversible ply count of standard chess.

Member Enumeration Documentation

◆ CountingRules

Rule sets of Thai and Cambodian Chess

◆ MakrukPieceType

Piece types for Makruk

Enumerator
Bia 

Shell, Chip.

Ma 

Horse.

Khon 

Base, replaces Alfil.

Rua 

Boat.

Met 

Grain: Mantri, Ferz, Advisor.

Khun 

Leader, Chief.

Constructor & Destructor Documentation

◆ MakrukBoard()

Chess::MakrukBoard::MakrukBoard ( )

Creates a new MakrukBoard object.

Cowry Shell, Chip

Horse

Khon (Base) replaces Alfil (Bishop): moves as Shogi's Silver General

Boat

Grain: Advisor

Leader, Lord

Member Function Documentation

◆ copy()

Board * Chess::MakrukBoard::copy ( ) const
virtual

Creates and returns a deep copy of this board.

Reimplemented from Chess::ShatranjBoard.

Reimplemented in Chess::AiWokBoard, Chess::AseanBoard, Chess::KarOukBoard, Chess::OukBoard, and Chess::SittuyinBoard.

◆ countingLimit()

int Chess::MakrukBoard::countingLimit ( ) const
protectedvirtual

Returns maximum count of plies allowed to finish the game: Limit for Board's Honour or Pieces' Honour counting.

Reimplemented in Chess::AseanBoard, and Chess::SittuyinBoard.

◆ countingRules()

MakrukBoard::CountingRules Chess::MakrukBoard::countingRules ( ) const
protectedvirtual

Returns type of counting rules to apply. Default: Makruk.

See also
OukBoard

Reimplemented in Chess::AseanBoard, Chess::OukBoard, and Chess::SittuyinBoard.

◆ defaultFenString()

QString Chess::MakrukBoard::defaultFenString ( ) const
virtual

Returns the variant's default starting FEN string.

Reimplemented from Chess::ShatranjBoard.

Reimplemented in Chess::AiWokBoard, Chess::AseanBoard, Chess::KarOukBoard, Chess::OukBoard, and Chess::SittuyinBoard.

◆ generateMovesForPiece()

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

Generates pseudo-legal moves for a piece of pieceType at square square.

Note
It doesn't matter if square doesn't contain a piece of pieceType, the move generator ignores it.

Reimplemented from Chess::ShatranjBoard.

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

◆ generatePawnMoves()

void Chess::MakrukBoard::generatePawnMoves ( int sourceSquare,
QVarLengthArray< Move > & moves ) const
protectedvirtual

Appends generated pseudo-legal pawn moves to moves

Reimplemented in Chess::SittuyinBoard.

◆ inCheck()

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

Returns true if side is under attack at square. If square is 0, then the king square is used.

Reimplemented from Chess::ShatranjBoard.

Reimplemented in Chess::OukBoard.

◆ initHistory()

void Chess::MakrukBoard::initHistory ( )
protected

Initialize counter history

◆ insufficientMaterial()

bool Chess::MakrukBoard::insufficientMaterial ( ) const
protectedvirtual

Returns true if material on board is known to be not sufficient to enforce mate, else false.

Reimplemented in Chess::AiWokBoard.

◆ pieceCount()

int Chess::MakrukBoard::pieceCount ( Side side = Side::NoSide,
int pieceType = Piece::NoPiece ) const
protected

Returns the number of pieces of side and of pieceType. NoPiece as pieceType counts all pieces of side. This is the default. If side is set to NoSide then the count of all pieces of pieceType is given. A call without arguments returns the total piece count.

◆ promotionRank()

int Chess::MakrukBoard::promotionRank ( int file = 0) const
protectedvirtual

Returns the relative rank of pawn promotions counting from 0 for the first rank. The default returns 5 for promotions on the sixth rank. The formal file parameter is unused. Override this method if the promotion rank is not uniform.

See also
SittuyinBoard

Reimplemented in Chess::AseanBoard, and Chess::SittuyinBoard.

◆ result()

Result Chess::MakrukBoard::result ( )
virtual

Returns the result of the game, or Result::NoResult if the game is in progress.

Reimplemented from Chess::ShatranjBoard.

Reimplemented in Chess::AseanBoard, Chess::KarOukBoard, and Chess::SittuyinBoard.

◆ resultFromCounting()

Result Chess::MakrukBoard::resultFromCounting ( ) const
protected

Returns game result based on specific counting rules

◆ setAllPieceCounters()

void Chess::MakrukBoard::setAllPieceCounters ( )
protected

Counts all pieces on the board and updates all counters of last MoveData entry in move history.

◆ variant()

QString Chess::MakrukBoard::variant ( ) const
virtual

Returns the name of the chess variant.

Reimplemented from Chess::ShatranjBoard.

Reimplemented in Chess::AiWokBoard, Chess::AseanBoard, Chess::KarOukBoard, Chess::OukBoard, and Chess::SittuyinBoard.

◆ vFenString()

QString Chess::MakrukBoard::vFenString ( Board::FenNotation notation) const
protectedvirtual

When using Makruk counting rules (no Western counting)

  • This method sets the castling rights field to "-" for Makruk.
  • The ep field is replaced by the counting limit (in plies).
  • Makruk ply counting replaces the reversible move count.
  • This method uses an own total ply counter to keep track of the full move count.

    Examples: Default FEN: rnsmksnr/8/pppppppp/8/8/PPPPPPPP/8/RNSKMSNR w - 0 0 1 KSSMvK black mates: 8/8/2m5/s7/8/1k6/1s6/1K6 w - 44 38 182

Reimplemented from Chess::WesternBoard.

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

◆ vInitialize()

void Chess::MakrukBoard::vInitialize ( )
protectedvirtual

Initializes the variant.

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

Reimplemented from Chess::ShatranjBoard.

◆ vMakeMove()

void Chess::MakrukBoard::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.

Reimplemented from Chess::WesternBoard.

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

◆ vSetFenString()

bool Chess::MakrukBoard::vSetFenString ( const QStringList & inputFen)
protectedvirtual

This method reads FEN with full Makruk/Ouk counting support (A), standard FEN (B), and short FEN-like notation without castling rights and en passant fields (C). The latter two use Western counting and ignore Makruk counting.

A: rnsmksnr/8/pppppppp/8/8/PPPPPPPP/8/RNSKMSNR w - 0 0 1

B: rnsmksnr/8/pppppppp/8/8/PPPPPPPP/8/RNSKMSNR w - - 0 1 C: rnsmksnr/8/pppppppp/8/8/PPPPPPPP/8/RNSKMSNR w 0 1

FEN with Ouk initial move rights instead of castling rights are supported by OukBoard. Format C does not carry this information. Also see OukBoard.

Reimplemented from Chess::WesternBoard.

Reimplemented in Chess::AseanBoard, Chess::OukBoard, and Chess::SittuyinBoard.

◆ vUndoMove()

void Chess::MakrukBoard::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.

Reimplemented from Chess::WesternBoard.

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

Member Data Documentation

◆ SilverGeneralMovement

const unsigned Chess::MakrukBoard::SilverGeneralMovement = 256
staticprotected

Khon moves like Silver General.


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