打开 DONOT_DELETE_TREE 宏时不删除子节点以用空间换时间

Release自对弈双方总耗时由33s缩短到20s
This commit is contained in:
CalciteM 2019-07-07 22:27:23 +08:00
parent 7d6631317a
commit 54947bfe01
2 changed files with 7 additions and 4 deletions

View File

@ -9,6 +9,8 @@
//#define HASH_MAP_ENABLE
#define DONOT_DELETE_TREE
#define MOVE_PRIORITY_TABLE_SUPPORT
#ifdef DEBUG

View File

@ -45,7 +45,7 @@ struct NineChessAi_ab::Node *NineChessAi_ab::addNode(Node *parent, int value, in
newNode->parent = parent;
newNode->value = value;
newNode->move = move;
nodeCount++;
newNode->id = nodeCount;
@ -87,8 +87,9 @@ struct NineChessAi_ab::Node *NineChessAi_ab::addNode(Node *parent, int value, in
newNode->cmd = cmd;
#endif
if (parent)
if (parent) {
parent->children.push_back(newNode); // (7%)
}
return newNode;
}
@ -749,13 +750,13 @@ int NineChessAi_ab::alphaBetaPruning(int depth, int alpha, int beta, Node *node)
#endif
// 删除“孙子”节点,防止层数较深的时候节点树太大
#ifndef DEBUG_AB_TREE
#ifndef DONOT_DELETE_TREE
for (auto child : node->children) {
for (auto grandChild : child->children)
deleteTree(grandChild); // (9%)
child->children.clear(); // (3%)
}
#endif
#endif // DONOT_DELETE_TREE
#ifdef HASH_MAP_ENABLE
if (iter == hashmap.end()) {