当前位置: 首页>>代码示例>>C++>>正文


C++ ChessBoard::CurrentPlayerCanMove方法代码示例

本文整理汇总了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);
    }
开发者ID:LiosanGOG,项目名称:chenard,代码行数:89,代码来源:ttychess.cpp


注:本文中的ChessBoard::CurrentPlayerCanMove方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。