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


C++ MoveList::find方法代码示例

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


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

示例1: playRandomGame

//------------------------------------------------------------------------------
//-------------------------------MCTS Methods-----------------------------------
//------------------------------------------------------------------------------
void playRandomGame(Player p, Board &b) {
    int movesPlayed = 1;
    int i = 0;
    Move last = MOVE_PASS;

    // Regenerate the movelist up to 4 times
    while (movesPlayed > 0 && i < 4) {
        movesPlayed = 0;
        i++;
        MoveList legalMoves = b.getLegalMoves(p);
        int koCount = 0;

        // While we still have legal moves remaining
        while (legalMoves.size() > 0) {
            // Check if the last move put its own chain into atari
            // Do not do this twice in a row to prevent infinite ko recapture
            if (koCount == 0) {
                Move cap = b.getPotentialCapture(last);
                if (cap != MOVE_PASS) {
                    int ci = legalMoves.find(cap);
                    if (ci != -1)
                        legalMoves.removeFast(ci);
                    
                    b.doMove(p, cap);
                    last = cap;
                    p = otherPlayer(p);
                    movesPlayed++;
                    koCount++;
                    continue;
                }
            }

            // Otherwise, pick a move at random
            std::uniform_int_distribution<int> distribution(0, legalMoves.size()-1);
            int index = distribution(rng);
            Move m = legalMoves.get(index);

            // Only play moves that are not into own eyes and not suicides
            if (!b.isEye(p, m) && b.isMoveValid(p, m)) {
                b.doMove(p, m);
                last = m;
                p = otherPlayer(p);
                movesPlayed++;
                koCount = 0;
            }

            legalMoves.removeFast(index);
        }
    }
}
开发者ID:jeffreyan11,项目名称:go-engine,代码行数:53,代码来源:search.cpp

示例2: generateMove


//.........这里部分代码省略.........
            int y = getY(next);
            if (x == 1 || x == boardSize || y == 1 || y == boardSize) {
                addition->denominator += 2 * basePrior;
            }
            else {
                int taperedPrior = basePrior * (legalMoves.size() - openingMoves) / boardSize;
                if (x == 3 || x == boardSize-2) {
                    addition->numerator += 2 * taperedPrior;
                    addition->denominator += 2 * taperedPrior;
                }
                if (y == 3 || y == boardSize-2) {
                    addition->numerator += 2 * taperedPrior;
                    addition->denominator += 2 * taperedPrior;
                }
            }
        }

        // Add a bonus for capturing a chain that the opponent placed
        // into atari on the previous move
        if (next == captureLastStone) {
            addition->numerator += 5 * basePrior;
            addition->denominator += 5 * basePrior;
        }

        // Add a bonus for escaping when the opponent's last move
        // placed our chain into atari
        if (next == potentialEscape) {
            addition->numerator += 5 * basePrior;
            addition->denominator += 5 * basePrior;
        }

        // Add a bonus to local moves
        if (legalMoves.size() < openingMoves) {
            int li = localMoves.find(next);
            if (li != -1) {
                localMoves.removeFast(li);
            }
            else {
                addition->numerator += basePrior;
                addition->denominator += 2 * basePrior;
            }
        }
    }

    // If we have no moves that are ko-legal, pass.
    if (searchTree.root->size == 0)
        return MOVE_PASS;

    // Calculate an estimate of a komi adjustment
    komiAdjustment /= legalMoves.size();


    // Expand the MC tree iteratively
    for (int n = 0; n < playouts; n++) {
        Board copy = Board(game);
        Player genPlayer = p;

        // Find a node in the tree to add a child to
        int depth = -1;
        MCNode *leaf = searchTree.findLeaf(genPlayer, copy, depth);

        MCNode *addition = new MCNode();
        addition->parent = leaf;
        MoveList candidates = copy.getLegalMoves(genPlayer);
        candidates.add(MOVE_PASS);
开发者ID:jeffreyan11,项目名称:go-engine,代码行数:66,代码来源:search.cpp


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