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


C++ Moves::append方法代码示例

本文整理汇总了C++中Moves::append方法的典型用法代码示例。如果您正苦于以下问题:C++ Moves::append方法的具体用法?C++ Moves::append怎么用?C++ Moves::append使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Moves的用法示例。


在下文中一共展示了Moves::append方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: generatePawnMoves

void ChessBoard::generatePawnMoves(ChessBoard& board, int sqSrc, Moves& mvs)
{
    int sqDst;

    if (board.m_sdPlayer != SQ_SIDE(sqSrc))
    {
        sqDst = sqSrc - 1;
        if (IN_BOARD(sqDst) && board.canMove(board, sqSrc, sqDst))
        {
            mvs.append(ChessBoard::mv(sqSrc, sqDst));
        }
        sqDst = sqSrc + 1;
        if (IN_BOARD(sqDst) && board.canMove(board, sqSrc, sqDst))
        {
            mvs.append(ChessBoard::mv(sqSrc, sqDst));
        }
    }


    if (board.m_sdPlayer==0)
    {
        sqDst = sqSrc - 16;
    }
    else{
        sqDst = sqSrc + 16;
    }
    if (IN_BOARD(sqDst) && board.canMove(board, sqSrc, sqDst))
    {
        mvs.append(ChessBoard::mv(sqSrc, sqDst));
    }
}
开发者ID:longsion,项目名称:ChineseChess,代码行数:31,代码来源:chessboard.cpp

示例2: movementOptions

UltimateTicTacToeMontecarloAI::Moves UltimateTicTacToeMontecarloAI::movementOptions(Board const& board, int const previousMove) const
{
  int gridIndex = previousMove % GRID_SIZE;
  bool playAny = previousMove < 0 || gridWinner(board.grids, gridIndex) || gridFull(board.grids, gridIndex);

  Moves options;

  if(playAny)
  {
    for(int i = 0; i < BOARD_SIZE; ++i)
    {
      if(board.grids.at(i) == 0)
      {
        options.append(i);
      }
    }
    //qDebug() << "Play to any grid," << options.size() << "options";
  }
  else
  {
    for(int i = 0; i < GRID_SIZE; ++i)
    {
      int position = gridIndex * GRID_SIZE + i;
      if(board.grids.at(position) == 0)
      {
        options.append(position);
      }
    }
    //qDebug() << "Play to grid" << gridIndex << "," << options.size() << "options";
  }

  return options;
}
开发者ID:bzar,项目名称:ultimate-tic-tac-toe,代码行数:33,代码来源:ultimatetictactoemontecarloai.cpp

示例3: generateCannonMoves

void ChessBoard::generateCannonMoves(ChessBoard& board, int sqSrc, Moves& mvs)
{
    static const int delta[4] = {-16, -1, 1, 16};
    for(int i=0; i<4; i++)
    {
        int sqDst = sqSrc;
        bool skiped = false;
        while (true)
        {
            sqDst += delta[i];
            if (!IN_BOARD(sqDst)) break;
            if (!board.m_data[sqDst])
            {
                if (!skiped)
                {
                    mvs.append(ChessBoard::mv(sqSrc, sqDst));
                }
            }
            else{
                if (!skiped)
                {
                    skiped = true;
                }
                else{
                    int pc = board.m_data[sqDst];
                    if (pc!=0)
                    {
                        if (board.canMove(board, sqSrc, sqDst))
                        {
                            mvs.append(ChessBoard::mv(sqSrc, sqDst));
                        }
                    }
                    break;
                }
            }
        }
    }
}
开发者ID:longsion,项目名称:ChineseChess,代码行数:38,代码来源:chessboard.cpp

示例4: generateRookMoves

void ChessBoard::generateRookMoves(ChessBoard& board, int sqSrc, Moves& mvs)
{
    static const int delta[4] = {-16, -1, 1, 16};
    for(int i=0; i<4; i++)
    {
        int sqDst = sqSrc;
        while (true)
        {
            sqDst += delta[i];
            if (!IN_BOARD(sqDst)) break;
            if (!board.m_data[sqDst])
            {                
                mvs.append(ChessBoard::mv(sqSrc, sqDst));
            }
            else{
                if (board.canMove(board, sqSrc, sqDst))
                {
                    mvs.append(ChessBoard::mv(sqSrc, sqDst));
                }
                break;
            }
        }
    }
}
开发者ID:longsion,项目名称:ChineseChess,代码行数:24,代码来源:chessboard.cpp

示例5: generateAdvisorMoves

void ChessBoard::generateAdvisorMoves(ChessBoard& board, int sqSrc, Moves& mvs)
{
    static const int ccAdvisorDelta[4] = {-17, -15, 15, 17};
    for(int i=0; i<4; i++)
    {
        int sqDst = sqSrc + ccAdvisorDelta[i];
        if (IN_FORT(sqDst))
        {
            if (board.canMove(board, sqSrc, sqDst))
            {
                mvs.append(ChessBoard::mv(sqSrc, sqDst));
            }
        }
    }
}
开发者ID:longsion,项目名称:ChineseChess,代码行数:15,代码来源:chessboard.cpp

示例6: generateKingMoves

void ChessBoard::generateKingMoves(ChessBoard& board, int sqSrc, Moves& mvs)
{
    static const int ccKingDelta[4] = {-16, -1, 1, 16};
    for(int i=0; i<4; i++)
    {
        int sqDst = sqSrc + ccKingDelta[i];
        if (IN_FORT(sqDst))
        {
            if (board.canMove(board, sqSrc, sqDst))
            {
                mvs.append(ChessBoard::mv(sqSrc, sqDst));
            }
        }
    }
}
开发者ID:longsion,项目名称:ChineseChess,代码行数:15,代码来源:chessboard.cpp

示例7: generateBishopMoves

void ChessBoard::generateBishopMoves(ChessBoard& board, int sqSrc, Moves& mvs)
{
    static const int ccBishopDelta[4] = {-34, -30, 30, 34};
    static const int ccBishopPin[4] = {-17, -15, 15, 17};
    for(int i=0; i<4; i++)
    {
        int sqDst = sqSrc + ccBishopDelta[i];
        if (!IN_BOARD(sqDst)) continue;
        int sqPin = sqSrc + ccBishopPin[i];
        if (board.m_data[sqPin]) continue;
        if (SAME_HALF(sqSrc, sqDst))
        {
            if (board.isInBoard(sqDst) && board.canMove(board, sqSrc, sqDst))
            {
                mvs.append(ChessBoard::mv(sqSrc, sqDst));
            }
        }

    }
}
开发者ID:longsion,项目名称:ChineseChess,代码行数:20,代码来源:chessboard.cpp

示例8: generateKnightMoves

void ChessBoard::generateKnightMoves(ChessBoard& board, int sqSrc, Moves& mvs)
{
    static const int ccKingDelta[4] = {-16, -1, 1, 16};
    static const int ccKnightDelta[4][2] = {{-33, -31}, {-18, 14}, {-14, 18}, {31, 33}};
    for (int i=0; i<4; i++)
    {
        int sqPin = sqSrc + ccKingDelta[i];
        if (IN_BOARD(sqPin) && board.m_data[sqPin]==0)
        {
            //马腿没有东西
            for(int j=0; j<2; j++)
            {
                int sqDst = sqSrc + ccKnightDelta[i][j];
                if (board.isInBoard(sqDst) && board.canMove(board, sqSrc, sqDst))
                {
                    mvs.append(ChessBoard::mv(sqSrc, sqDst));
                }
            }
        }
    }
}
开发者ID:longsion,项目名称:ChineseChess,代码行数:21,代码来源:chessboard.cpp


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