本文整理汇总了C++中Moves::at方法的典型用法代码示例。如果您正苦于以下问题:C++ Moves::at方法的具体用法?C++ Moves::at怎么用?C++ Moves::at使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Moves
的用法示例。
在下文中一共展示了Moves::at方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: 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;
}
}
示例2: 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;
}