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


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

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


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

示例1: iss

TEST(MoveGeneratorTest, testDrop) {
  {
    // 先手の手
    std::string src =
"P1+TO-KE *  *  *  *  *  *  * \n"
"P2 *  *  *  *  *  *  *  *  * \n"
"P3 *  *  * -OU *  *  * -FU * \n"
"P4 *  *  *  *  *  *  *  *  * \n"
"P5 *  *  * +FU * -KI *  *  * \n"
"P6 *  *  *  *  *  *  *  *  * \n"
"P7 *  * +FU *  *  *  * +FU * \n"
"P8 *  * +OU *  *  *  *  *  * \n"
"P9 *  *  *  * -KY * -RY *  * \n"
"P+00FU00FU00KY00KE00KA\n"
"P-\n"
"+\n";
    std::istringstream iss(src);
    Board board;
    CsaReader::readBoard(iss, board);

    // FUx45 KYx63 KEx54 KAx70
    Moves moves;
    MoveGenerator::generateDrop(board, moves);
    ASSERT_EQ(45+63+54+70, moves.size());
  }

  {
    // 後手の手
    std::string src =
"P1 *  *  *  * +KY * +RY *  * \n"
"P2 *  * -OU *  *  *  *  *  * \n"
"P3 *  * -FU *  *  *  * -FU * \n"
"P4 *  *  *  *  *  *  *  *  * \n"
"P5 *  *  * -FU * +KI *  *  * \n"
"P6 *  *  *  *  *  *  *  *  * \n"
"P7 *  *  * +OU *  *  * +FU * \n"
"P8 *  *  *  *  *  *  *  *  * \n"
"P9-TO+KE *  *  *  *  *  *  * \n"
"P+\n"
"P-00FU00FU00KY00KE00KA\n"
"-\n";
    std::istringstream iss(src);
    Board board;
    CsaReader::readBoard(iss, board);

    // FUx45 KYx63 KEx54 KAx70
    Moves moves;
    MoveGenerator::generateDrop(board, moves);
    ASSERT_EQ(45+63+54+70, moves.size());
  }
}
开发者ID:sunfish-shogi,项目名称:sunfish3,代码行数:51,代码来源:MoveGeneratorTest.cpp

示例2: expand

int UltimateTicTacToeMontecarloAI::expand(int leafIndex, Nodes& nodes, int const player) const
{
  Node& node = nodes[leafIndex];
  node.children.reserve(maxChildren);
  Moves options = movementOptions(node.board, node.previousMove);
  int turn = node.previousMove > 0 ? otherPlayer(node.board.grids.at(node.previousMove)) : player;

  int mostPromisingChildIndex = -1;
  int mostPromisingChildScore = 0;

  while(node.children.size() < maxChildren && !options.empty())
  {
    Move move = options.takeAt(qrand() % options.size());
    int childIndex = nodes.size();
    node.children.append(childIndex);
    Board newBoard(node.board);
    nodes.append( Node {0, 1, playMove(newBoard, move, turn), move, leafIndex, Node::Children()});
    int score = scoreBoard(nodes.last().board, player);
    if(score > mostPromisingChildScore || mostPromisingChildIndex < 0)
    {
      mostPromisingChildIndex = childIndex;
      mostPromisingChildScore = score;
    }
  }

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

示例3: solve

bool solve(Board & board, Moves & steps) {
  bool r = false;
  priority_queue<Board> q;
  Searched searched;
  searched[board.value()] = State();
  q.push(board);
  while (!q.empty()) {
    Board b = q.top();
    q.pop();
    ull_t v = b.value();
    if (v == target_value) {
      build_path(v, searched, steps);
      r = true;
      break;
    }
    uint depth = searched[v].depth;
    b.debug(depth);
    if (depth <= MAX_DEPTH) {
      Moves cand = b.valid_moves();
      for (int i = 0; i< cand.size(); i++) {
        Board n = b.move(cand[i]);
        ull_t nv = n.value();
        Searched::iterator it = searched.find(nv);
        if (it == searched.end()) {
          searched[nv] = State(v, depth + 1, cand[i]);
          q.push(n);
        }
        else if (depth + 1 < it->second.depth) {
          State & s = it->second;
          s.parent = v;
          s.depth = depth + 1;
          s.step = cand[i];
          q.push(n);
        }
      }
    }
  }
  return r;
}
开发者ID:cymqqqq,项目名称:programming-challenges,代码行数:39,代码来源:ch8_ex2_a_star.cpp

示例4: simulate

int UltimateTicTacToeMontecarloAI::simulate(Board board, int const previousMove, int const player) const
{
  int turn = previousMove > 0 ? otherPlayer(board.grids.at(previousMove)) : player;
  GameState state = gameState(board, player);
  Move prev = previousMove;
  while(state == GameState::UNRESOLVED)
  {
    Moves options = movementOptions(board, prev);
    Move option = options.at(qrand() % options.size());
    playMove(board, option, turn);
    turn = otherPlayer(turn);
    state = gameState(board, player);
    prev = option;
  }

  switch(state)
  {
    case GameState::WIN: return 1;
    case GameState::LOSE: return -1;
    default: return 0;
  }
}
开发者ID:bzar,项目名称:ultimate-tic-tac-toe,代码行数:22,代码来源:ultimatetictactoemontecarloai.cpp

示例5: main

int main() {
  init();
  int n = 0;
  cin >> n;
  for (int i = 0; i < n; i++) {
    vector<char> vec(16);
    for (int j = 0; j < 16; j++) {
      int ch;
      cin >> ch;
      vec[j] = ch;
    }
    Board board(vec);
    Moves steps;
    if (solve(board, steps)) {
      for (int k = 0; k < steps.size(); k++) {
        cout << steps[k];
      }
    }
    else {
      cout << "This puzzle is not solvable.";
    }
    cout << endl;
  }
}
开发者ID:cymqqqq,项目名称:programming-challenges,代码行数:24,代码来源:ch8_ex2_a_star.cpp

示例6: Moves

CachedMoves::CachedMoves(const Moves& moves) :
    Moves(moves), boards_(moves.size() + 1) {
    boards_rebuild();
}
开发者ID:starius,项目名称:thechess,代码行数:4,代码来源:CachedMoves.cpp

示例7: realThink

int UltimateTicTacToeMontecarloAI::realThink(const UltimateTicTacToeMontecarloAI::Board &board, const int previousMove, const int player) const
{
  //printBoard(board);
  if(maxIterations == 0) {
    Moves options = movementOptions(board, previousMove);
    return options.at(qrand() % options.size());
  }

  //qint64 now = QDateTime::currentMSecsSinceEpoch();
  //qDebug() << "c: " << c << ", maxIterations: " << maxIterations << ", maxChildren: " <<maxChildren;
  Nodes nodes;
  nodes.reserve(maxIterations * maxChildren);
  nodes.append(Node { 0, 1, board, previousMove, -1, Node::Children() });

  int i;
  for(i = 0; i < maxIterations; ++i)
  {
    int leafIndex = select(nodes);
    Node const& leaf = nodes.at(leafIndex);

    GameState leafState = gameState(leaf.board, player);
    if(leafState == GameState::WIN)
    {
/*      qDebug() << "---";
      printBoard(leaf.board);
*/
      break;
    }
    else if(leafState == GameState::LOSE)
    {
      backpropagate(leafIndex, nodes, -10);
    }
    else if(leafState == GameState::TIE)
    {
      backpropagate(leafIndex, nodes, -5);
    }
    else if(leafState == GameState::UNRESOLVED)
    {
      int nodeIndex = expand(leafIndex, nodes, player);

      Node const& node = nodes.at(nodeIndex);
      int score = simulate(node.board,  node.previousMove, player);

      backpropagate(nodeIndex, nodes, score);
    }
  }

  //qDebug() << "Found solution in " << i + 1 << " iterations";
  Node const& root = nodes.at(0);
  int bestChildIndex = pickBestChild(root, nodes, false);
  Node const& bestChild = nodes.at(bestChildIndex);

  //qDebug() << "AI took " << (QDateTime::currentMSecsSinceEpoch() - now) << " ms";

  /*for(int childIndex : root.children)
  {
    Node const& child = nodes.at(childIndex);
    qDebug() << child.previousMove << ":" << child.v << child.n;
  }*/
  //qDebug() << bestChild.previousMove / 9 << bestChild.previousMove %9;
  return bestChild.previousMove;
}
开发者ID:bzar,项目名称:ultimate-tic-tac-toe,代码行数:62,代码来源:ultimatetictactoemontecarloai.cpp


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