本文整理汇总了C++中ChessBoard::CurrentPlayerCanMove方法的典型用法代码示例。如果您正苦于以下问题:C++ ChessBoard::CurrentPlayerCanMove方法的具体用法?C++ ChessBoard::CurrentPlayerCanMove怎么用?C++ ChessBoard::CurrentPlayerCanMove使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ChessBoard
的用法示例。
在下文中一共展示了ChessBoard::CurrentPlayerCanMove方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: RecordMove
//----------------------------------------------------------------
// The following function is called by the ChessGame after
// each player moves, so that the move can be displayed
// in standard chess notation, if the UI desires.
// It is helpful to use the ::FormatChessMove() function
// for this purpose.
// The parameter 'thinkTime' is how long the player thought
// about the move, expressed in hundredths of seconds.
//
// NOTE: This function is called BEFORE the move
// has been made on the given ChessBoard.
// This is necessary for ::FormatChessMove() to work.
//----------------------------------------------------------------
virtual void RecordMove(ChessBoard &board, Move move, INT32 thinkTime)
{
TheTerminal.print(BoolSideName(board.WhiteToMove()));
TheTerminal.print(" move #");
TheTerminal.printInteger((board.GetCurrentPlyNumber()/2) + 1);
TheTerminal.print(": ");
int source, dest;
SQUARE prom = move.actualOffsets(board, source, dest);
char sourceFile = XPART(source) - 2 + 'a';
char sourceRank = YPART(source) - 2 + '1';
char destFile = XPART(dest) - 2 + 'a';
char destRank = YPART(dest) - 2 + '1';
TheTerminal.print(sourceFile);
TheTerminal.print(sourceRank);
TheTerminal.print(destFile);
TheTerminal.print(destRank);
if (prom)
{
char pchar = '?';
int pindex = UPIECE_INDEX(prom);
switch (pindex)
{
case Q_INDEX: pchar = 'Q'; break;
case R_INDEX: pchar = 'R'; break;
case B_INDEX: pchar = 'B'; break;
case N_INDEX: pchar = 'N'; break;
}
TheTerminal.print(pchar);
}
// Temporarily make the move, so we can display what the board
// looks like after the move has been made.
// We also use this to determine if the move causes check,
// checkmate, stalemate, etc.
UnmoveInfo unmove;
board.MakeMove(move, unmove);
// Report check, checkmate, draws.
bool inCheck = board.CurrentPlayerInCheck();
bool canMove = board.CurrentPlayerCanMove();
if (canMove)
{
if (inCheck)
{
TheTerminal.print('+');
}
}
else
{
// The game is over!
if (inCheck)
{
if (board.WhiteToMove())
{
// White just got checkmated.
TheTerminal.print("# 0-1");
}
else
{
// Black just got checkmated.
TheTerminal.print("# 1-0");
}
}
else
{
// The game is a draw (could be stalemate, could be by repetition, insufficient material, ...)
TheTerminal.print(" 1/2-1/2");
}
}
TheTerminal.printline();
// Unmake the move, because the caller will make the move itself.
board.UnmakeMove(move, unmove);
}