我已经用 C 语言实现了一个带有 AI 的 m,n,k 游戏。游戏运行良好,但当我必须释放决策树时,它总是抛出“访问冲突读取位置”异常。
这是决策树结构的实现:
typedef struct decision_tree_s {
unsigned short **board;
status_t status;
struct decision_tree_s *brother;
struct decision_tree_s *children;
} decision_tree_t;
这是delete_tree
函数的实现:
void delete_tree(decision_tree_t **tree) {
decision_tree_t *tmp;
if (*tree != NULL) {
delete_tree((*tree)->children);
delete_tree((*tree)->brother);
free(*tree);
*tree = NULL;
}
}