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

A board for Shogi. More...

#include <shogiboard.h>

Inheritance diagram for Chess::ShogiBoard:
Chess::Board Chess::DobutsuShogiBoard Chess::EuroShogiBoard Chess::JudkinsShogiBoard Chess::MiniShogiBoard

Public Member Functions

virtual CoordinateSystem coordinateSystem () const
 
virtual Boardcopy () const
 
virtual QString defaultFenString () const
 
virtual int height () const
 
virtual QList< PiecereservePieceTypes () const
 
virtual Result result ()
 
 ShogiBoard ()
 
virtual QString variant () const
 
virtual bool variantHasDrops () const
 
virtual bool variantHasOptionalPromotions () const
 
virtual int width () const
 
- Public Member Functions inherited from Chess::Board
 Board (Zobrist *zobrist)
 
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
 
void reset ()
 
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 bool variantHasWallSquares () const
 
virtual ~Board ()
 

Protected Types

enum  ShogiPieceType {
  Pawn = 1, Lance, Knight, SilverGeneral,
  GoldGeneral, Bishop, Rook, King,
  PromotedPawn, PromotedLance, PromotedKnight, PromotedSilver,
  PromotedBishop, PromotedRook
}
 

Protected Member Functions

virtual void generateMovesForPiece (QVarLengthArray< Move > &moves, int pieceType, int square) const
 
virtual bool hasImpassePointRule () const
 
virtual Result impassePointRule (int points, int pieces) const
 
virtual bool inCheck (Side side, int square=0) const
 
virtual bool isLegalPosition ()
 
virtual QString lanMoveString (const Move &move)
 
virtual Move moveFromLanString (const QString &str)
 
virtual Move moveFromSanString (const QString &str)
 
virtual int normalPieceType (int type) const
 
virtual int promotedPieceType (int type) const
 
virtual int promotionRank () const
 
virtual bool ranksAreAllowed () const
 
virtual int reserveType (int pieceType) const
 
virtual QString sanMoveString (const Move &move)
 
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 ()
 
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
 
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)
 
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)
 

Static Protected Attributes

static const unsigned BishopMovement = 4
 
static const unsigned FerzMovement = 16
 
static const unsigned GoldMovement = 512
 
static const unsigned KnightMovement = 2
 
static const unsigned LanceMovement = 128
 
static const unsigned RookMovement = 8
 
static const unsigned SilverMovement = 256
 
static const unsigned WazirMovement = 64
 

Additional Inherited Members

- Public Types inherited from Chess::Board
enum  CoordinateSystem { NormalCoordinates, InvertedCoordinates }
 
enum  FenNotation { XFen, ShredderFen }
 
enum  MoveNotation { StandardAlgebraic, LongAlgebraic }
 

Detailed Description

A board for Shogi.

Shōgi is a Japanese form of chess where captured pieces can be brought back ("dropped") into the game,

It is played on a 9x9 board. The piece set traditionally consists of flat five-sided pieces with their names written on them. Such sets have been in use at least since the 11th century AD.

Shōgi emerged from the earlier game of Shō Shōgi by the reinsertion of captured pieces as own pieces (15th century AD) and removal of the Drunk Elephant piece by imperial order (16th century AD).

Shōgi has eight types of original pieces. Either side starts with a set of 9 x Pawn (on the third rank), 2 x Lance, 2 x Knight, 2 x Silver (General), 2 x Gold (General), 1 x Bishop, 1 x Rook, 1 x King. The latter three types move like in standard chess. The Pawn moves and captures 1 square straight forward. The Lance moves and captures like a Rook, but only forwards. Similarly, the Knight leaps like a chess Knight, but only in the two forward directions. The Silver goes one square diagonally or forward (5 moves). The Gold goes like a King but not diagonally backward (6 moves).

All these pieces except King and Gold General have the option to promote if their move starts or ends in the opponent's third of the board. A Pawn or Lance reaching the highest rank must promote. A Knight must promote when reaching the highest two ranks. All promoted Pawns, Lances, Knights, and Silvers move like Gold Generals. A promoted Bishop moves like Bishop or King, a promoted Rook like Rook or King.

A captured piece switches sides and goes into the hand of the capturing side. Promoted pieces change back to their original types. A player may drop a piece in hand onto an empty square of the board. This counts as a move. Pawns, Lances, and Knights must not be dropped onto the highest ranks where they would be unable to move. Pawns must not be dropped onto files with own Pawns and must not be dropped to give mate immediately.

A side must avert an attack on their King (check, ote 王手) immediately. It is forbidden to enter check. If there is no legal move to avert check then the side in check loses by checkmate (tsumi 詰み).

When a game position occurs four times with the same player to move and the same pieces in hand for each player the game is drawn by repetition (sennichite, 千日手). If the situation has arisen from a perpetual check then the side giving check loses.

Note
Rules: http://en.wikipedia.org/wiki/Shogi

Member Enumeration Documentation

◆ ShogiPieceType

Piece types for Shogi.

Enumerator
Pawn 

Foot Soldier P (Fuhyō) FU.

Lance 

Incense Chariot L (Kyōsha) KY.

Knight 

Cassia Horse N (Keima) KE.

SilverGeneral 

Silver General S (Ginshō) GI.

GoldGeneral 

Gold General G (Kinshō) KI.

Bishop 

Angle Mover B (Kakugyō) KA.

Rook 

Flying Chariot R (Hisha) HI.

King 

Jeweled General K (GyoKushō) OU.

King General K (Ōshō) OU

PromotedPawn 

Reaches Gold +P (Tokin) TO.

Promoted piece types for Shogi. When they are captured they get demoted back.

PromotedLance 

Promoted Incense +L (Narikyō) NY.

PromotedKnight 

Promoted Cassia +N (Narikei) NK.

PromotedSilver 

Promoted Silver +S (Narigin) NG.

PromotedBishop 

Dragon Horse +B (Ryūma) UM.

PromotedRook 

Dragon King +R (Ryūō) RY

Constructor & Destructor Documentation

◆ ShogiBoard()

Chess::ShogiBoard::ShogiBoard ( )

Creates a new ShogiBoard object.

Member Function Documentation

◆ coordinateSystem()

Board::CoordinateSystem Chess::ShogiBoard::coordinateSystem ( ) const
virtual

Returns the coordinate system used in the variant.

Reimplemented from Chess::Board.

◆ copy()

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

Creates and returns a deep copy of this board.

Implements Chess::Board.

Reimplemented in Chess::DobutsuShogiBoard, Chess::EuroShogiBoard, Chess::JudkinsShogiBoard, and Chess::MiniShogiBoard.

◆ defaultFenString()

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

Returns the variant's default starting FEN string.

Implements Chess::Board.

Reimplemented in Chess::DobutsuShogiBoard, Chess::EuroShogiBoard, Chess::JudkinsShogiBoard, and Chess::MiniShogiBoard.

◆ generateMovesForPiece()

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

Implements Chess::Board.

Reimplemented in Chess::EuroShogiBoard.

◆ hasImpassePointRule()

bool Chess::ShogiBoard::hasImpassePointRule ( ) const
protectedvirtual

Returns true if the impassé point rule is active else false.

◆ height()

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

Returns the height of the board in squares.

Implements Chess::Board.

Reimplemented in Chess::DobutsuShogiBoard, Chess::EuroShogiBoard, Chess::JudkinsShogiBoard, and Chess::MiniShogiBoard.

◆ impassePointRule()

Result Chess::ShogiBoard::impassePointRule ( int  points,
int  pieces 
) const
protectedvirtual

Criteria of impasse rule limit given material value of points and the number of pieces of the side to move in the promotion zone.

Reimplemented in Chess::JudkinsShogiBoard.

◆ isLegalPosition()

bool Chess::ShogiBoard::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::DobutsuShogiBoard.

◆ lanMoveString()

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

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

Reimplemented from Chess::Board.

◆ moveFromLanString()

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

Converts a string in LAN format into a Move object.

Reimplemented from Chess::Board.

◆ moveFromSanString()

Move Chess::ShogiBoard::moveFromSanString ( const QString str)
protectedvirtual

Converts a string in SAN format into a Move object.

Implements Chess::Board.

◆ normalPieceType()

int Chess::ShogiBoard::normalPieceType ( int  type) const
protectedvirtual

Returns original piece type corresponding to promoted type.

◆ promotedPieceType()

int Chess::ShogiBoard::promotedPieceType ( int  type) const
protectedvirtual

Returns promoted piece type corresponding to normal type.

Reimplemented in Chess::DobutsuShogiBoard.

◆ promotionRank()

int Chess::ShogiBoard::promotionRank ( ) const
protectedvirtual

Returns the lowest (relative) rank of the promotion zone.

Reimplemented in Chess::EuroShogiBoard.

◆ ranksAreAllowed()

bool Chess::ShogiBoard::ranksAreAllowed ( ) const
protectedvirtual

Returns whether the current position has no pieces on forbidden ranks.

Reimplemented in Chess::EuroShogiBoard.

◆ reservePieceTypes()

QList< Piece > Chess::ShogiBoard::reservePieceTypes ( ) const
virtual

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 from Chess::Board.

◆ reserveType()

int Chess::ShogiBoard::reserveType ( int  pieceType) const
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 from Chess::Board.

◆ result()

Result Chess::ShogiBoard::result ( )
virtual

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

Implements Chess::Board.

Reimplemented in Chess::DobutsuShogiBoard, Chess::EuroShogiBoard, and Chess::MiniShogiBoard.

◆ sanMoveString()

QString Chess::ShogiBoard::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.

◆ variant()

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

Returns the name of the chess variant.

Implements Chess::Board.

Reimplemented in Chess::DobutsuShogiBoard, Chess::EuroShogiBoard, Chess::JudkinsShogiBoard, and Chess::MiniShogiBoard.

◆ variantHasDrops()

bool Chess::ShogiBoard::variantHasDrops ( ) const
virtual

Returns true if the variant allows piece drops. The default value is false.

See also
CrazyhouseBoard

Reimplemented from Chess::Board.

◆ vFenString()

QString Chess::ShogiBoard::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.

◆ vInitialize()

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

◆ vIsLegalMove()

bool Chess::ShogiBoard::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.

◆ vMakeMove()

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

◆ vSetFenString()

bool Chess::ShogiBoard::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.

◆ vUndoMove()

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

◆ width()

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

Returns the width of the board in squares.

Implements Chess::Board.

Reimplemented in Chess::DobutsuShogiBoard, Chess::EuroShogiBoard, Chess::JudkinsShogiBoard, and Chess::MiniShogiBoard.

Member Data Documentation

◆ BishopMovement

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

Movement mask for Bishop moves.

◆ FerzMovement

const unsigned Chess::ShogiBoard::FerzMovement = 16
staticprotected

Movement mask for Ferz move pattern.

◆ GoldMovement

const unsigned Chess::ShogiBoard::GoldMovement = 512
staticprotected

Movement mask for Gold General moves.

◆ KnightMovement

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

Movement mask for Knight moves.

◆ LanceMovement

const unsigned Chess::ShogiBoard::LanceMovement = 128
staticprotected

Movement mask for Lance moves.

◆ RookMovement

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

Movement mask for Rook moves.

◆ SilverMovement

const unsigned Chess::ShogiBoard::SilverMovement = 256
staticprotected

Movement mask for Silver General moves.

◆ WazirMovement

const unsigned Chess::ShogiBoard::WazirMovement = 64
staticprotected

Movement mask for Wazir move pattern.


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