refactor: 新增 deletSubTree() 接口并使用

This commit is contained in:
Calcitem 2020-05-04 10:09:29 +08:00
parent 36daf7bb4f
commit 67bfcab176
2 changed files with 16 additions and 11 deletions

View File

@ -523,6 +523,20 @@ void AIAlgorithm::deleteTree(Node *node)
memmgr.memmgr_free(node);
}
void AIAlgorithm::deleteSubTree(Node *node)
{
int cs = node->childrenSize;
for (int i = 0; i < cs; i++) {
Node *c = node->children[i];
int size = c->childrenSize;
for (int j = 0; j < size; j++) {
deleteTree(c->children[j]);
}
c->childrenSize = 0;
}
}
void AIAlgorithm::setState(const StateInfo &g)
{
// 如果规则改变重建hashmap
@ -989,19 +1003,9 @@ out:
// 删除“孙子”节点,防止层数较深的时候节点树太大
#ifndef DONOT_DELETE_TREE
int cs = node->childrenSize;
for (int i = 0; i < cs; i++) {
Node *c = node->children[i];
int size = c->childrenSize;
for (int j = 0; j < size; j++) {
deleteTree(c->children[j]);
}
c->childrenSize = 0;
}
deleteSubTree(node);
#endif // DONOT_DELETE_TREE
if (gameOptions.getIDSEnabled()) {
#ifdef IDS_ADD_VALUE
node->children[0]->value += 1;

View File

@ -238,6 +238,7 @@ public: /* TODO: Move to private or protected */
// 清空节点树
void deleteTree(Node *node);
void deleteSubTree(Node *node);
// 构造根节点
void buildRoot();