prefetch: 实现不需要模拟走子的预取 (目前只实现了吃子) 并启用预取

自对弈时长由 22s 缩短到 20.5s。
This commit is contained in:
Calcitem 2020-04-19 12:53:10 +08:00
parent f5570820b4
commit 41bae6e6f2
4 changed files with 36 additions and 10 deletions

View File

@ -95,7 +95,7 @@
//#define TRANSPOSITION_TABLE_DEBUG
#endif
//#define PREFETCH_SUPPORT
#define PREFETCH_SUPPORT
//#define USE_STD_STACK

View File

@ -862,18 +862,14 @@ value_t AIAlgorithm::search(depth_t depth, value_t alpha, value_t beta, Node *no
#endif // CLEAR_PRUNED_FLAG_BEFORE_SEARCH
int nchild = node->childrenSize;
for (int i = 0; i < nchild; i++) {
#ifdef PREFETCH_SUPPORT
if (i + 1 < nchild)
{
stashPosition();
doMove(node->children[i + 1]->move);
hash_t nextHash = st->getHash();
TT::prefetchHash(nextHash);
undoMove();
for (int i = 0; i < nchild; i++) {
TT::prefetchHash(st->getNextMainHash(node->children[i]->move));
}
#endif // PREFETCH_SUPPORT
for (int i = 0; i < nchild; i++) {
// 棋局入栈保存,以便后续撤销着法
stashPosition();

View File

@ -1171,3 +1171,32 @@ hash_t StateInfo::updateHashMisc()
return position->hash;
}
hash_t StateInfo::getNextMainHash(move_t m)
{
hash_t nextMainHash = position->hash << 8 >> 8;
square_t sq = SQ_0;
if (m < 0) {
sq = static_cast<square_t>(-m);
int pieceType = Player::toId(position->board.locationToPlayer(sq));
nextMainHash ^= zobrist[sq][pieceType];
if (rule.hasForbiddenLocations && position->phase == PHASE_PLACING) {
nextMainHash ^= zobrist[sq][PIECETYPE_FORBIDDEN];
}
}
#if 0
if (m & 0x1f00) {
if (choose(static_cast<square_t>(m >> 8))) {
return place(static_cast<square_t>(m & 0x00ff));
}
} else {
return place(static_cast<square_t>(m & 0x00ff));
}
#endif
return nextMainHash;
}

View File

@ -264,6 +264,7 @@ public:
hash_t revertHash(square_t square);
hash_t updateHash(square_t square);
hash_t updateHashMisc();
hash_t StateInfo::getNextMainHash(move_t m);
#ifdef MCTS_AI
// MCTS 相关