本文整理汇总了C++中MoveList::get方法的典型用法代码示例。如果您正苦于以下问题:C++ MoveList::get方法的具体用法?C++ MoveList::get怎么用?C++ MoveList::get使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MoveList
的用法示例。
在下文中一共展示了MoveList::get方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: doCaptures
int Board::doCaptures(Player victim, Move seed) {
if (pieces[index(getX(seed), getY(seed))] != victim)
return 0;
Stone *visited = new Stone[arraySize*arraySize];
for (int i = 0; i < arraySize*arraySize; i++) {
visited[i] = 0;
}
MoveList captured;
if (isSurrounded(victim, EMPTY, getX(seed), getY(seed), visited, captured)) {
if (updateBoard) {
for (unsigned int i = 0; i < captured.size(); i++) {
Move m = captured.get(i);
pieces[index(getX(m), getY(m))] = EMPTY;
zobristKey ^= zobristTable[zobristIndex(victim, getX(m), getY(m))];
}
// Record how many pieces were captured for scoring purposes
if (victim == BLACK)
whiteCaptures += captured.size();
else
blackCaptures += captured.size();
}
}
delete[] visited;
return captured.size();
}
示例2: perft
/*
* Performs a PERFT (performance test). Useful for testing/debugging
* PERFT n counts the number of possible positions after n moves by either side,
* ex. PERFT 4 = # of positions after 2 moves from each side
*
* 7/8/15: PERFT 5, 1.46 s (i5-2450m)
* 7/11/15: PERFT 5, 1.22 s (i5-2450m)
* 7/13/15: PERFT 5, 1.08 s (i5-2450m)
* 7/14/15: PERFT 5, 0.86 s (i5-2450m)
* 7/17/15: PERFT 5, 0.32 s (i5-2450m)
* 8/7/15: PERFT 5, 0.25 s, PERFT 6, 6.17 s (i5-5200u)
* 8/8/15: PERFT 6, 5.90 s (i5-5200u)
* 8/11/15: PERFT 6, 5.20 s (i5-5200u)
*/
uint64_t perft(Board &b, int color, int depth, uint64_t &captures) {
if (depth == 0)
return 1;
uint64_t nodes = 0;
MoveList pl;
b.getAllPseudoLegalMoves(pl, color);
for (unsigned int i = 0; i < pl.size(); i++) {
Board copy = b.staticCopy();
if (!copy.doPseudoLegalMove(pl.get(i), color))
continue;
if (isCapture(pl.get(i)))
captures++;
nodes += perft(copy, color^1, depth-1, captures);
}
return nodes;
}
示例3: 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);
}
}
}
示例4: generateMove
Move generateMove(Player p, Move lastMove) {
MoveList legalMoves = game.getLegalMoves(p);
MoveList localMoves = game.getLocalMoves(lastMove);
// Pass if every move is either into your own eye, a suicide, or places
// a chain into atari
bool playPass = true;
for (unsigned int n = 0; n < legalMoves.size(); n++) {
Board copy = Board(game);
Move m = legalMoves.get(n);
if (!copy.isMoveValid(otherPlayer(p), m) && copy.isEye(p, m))
continue;
if (!copy.isMoveValid(p, m))
continue;
copy.doMove(p, m);
if (copy.isInAtari(m))
continue;
playPass = false;
break;
}
if (playPass)
return MOVE_PASS;
MCTree searchTree;
float komiAdjustment = 0.0;
Move captureLastStone = game.getPotentialCapture(lastMove);
Move potentialEscape = game.getPotentialEscape(p, lastMove);
// Add all first-level moves
for (unsigned int n = 0; n < legalMoves.size(); n++) {
Board copy = Board(game);
Player genPlayer = p;
Move next = legalMoves.get(n);
// Check legality of moves (suicide)
if (!copy.isMoveValid(genPlayer, next))
continue;
copy.doMove(genPlayer, next);
// Never place own chain in atari
if (copy.isInAtari(next))
continue;
// Check for ko rule violation
bool koViolation = false;
if (next != MOVE_PASS) {
uint64_t newKey = copy.getZobristKey();
for (int i = keyStackSize-1; i >= 0; i--) {
if (newKey == keyStack[i]) {
koViolation = true;
break;
}
}
}
if (koViolation)
continue;
// First level moves are added to the root
MCNode *leaf = searchTree.root;
MCNode *addition = new MCNode();
addition->parent = leaf;
addition->m = next;
// Play out a random game. The final board state will be stored in copy.
playRandomGame(otherPlayer(genPlayer), copy);
// Score the game
float myScore = 0.0, oppScore = 0.0;
scoreGame(genPlayer, copy, myScore, oppScore);
if (myScore > oppScore)
addition->numerator++;
addition->scoreDiff = ((int) myScore) - ((int) oppScore);
komiAdjustment += myScore - oppScore;
// Add the new node to the tree
leaf->children[leaf->size] = addition;
leaf->size++;
// Backpropagate the results
searchTree.backPropagate(addition);
// Do priors, if any
// Own eye and opening priors inspired by Pachi,
// written by Petr Baudis and Jean-loup Gailly
int basePrior = boardSize * boardSize / 8;
// Discourage playing into own eyes
if (game.isEye(genPlayer, next)) {
addition->denominator += basePrior;
// If this eye is not ko-related we almost certainly should not play
// in it
if (!game.isMoveValid(otherPlayer(genPlayer), next)) {
addition->denominator += 10 * basePrior;
addition->scoreDiff -= 10 * 360;
}
//.........这里部分代码省略.........