diff --git a/NineChess/src/aithread.cpp b/NineChess/src/aithread.cpp index 9df0ced2..3f4a5e25 100644 --- a/NineChess/src/aithread.cpp +++ b/NineChess/src/aithread.cpp @@ -35,7 +35,8 @@ void AiThread::setAi(const NineChess &chess) ai_ab.setChess(*(this->chess_)); #ifdef HASH_MAP_ENABLE - //ai_ab.clearHashMap(); + // TODO: 下第二盘时不明原因变慢,临时方案为清除哈希表 + ai_ab.clearHashMap(); #endif mutex.unlock(); diff --git a/NineChess/src/hashmap.h b/NineChess/src/hashmap.h index de67f252..6c7cc320 100644 --- a/NineChess/src/hashmap.h +++ b/NineChess/src/hashmap.h @@ -97,16 +97,19 @@ namespace CTSL //Concurrent Thread Safe Library #endif } -#ifndef DISABLE_HASHBUCKET + //Function to clean up the hasp map, i.e., remove all entries from it void clear() { +#ifdef DISABLE_HASHBUCKET + memset(hashTable, 0, sizeof(HashNode) * hashSize); +#else for(size_t i = 0; i < hashSize; i++) { (hashTable[i]).clear(); } - } #endif + } private: #ifdef DISABLE_HASHBUCKET diff --git a/NineChess/src/ninechessai_ab.cpp b/NineChess/src/ninechessai_ab.cpp index 1b50ad81..beb782e8 100644 --- a/NineChess/src/ninechessai_ab.cpp +++ b/NineChess/src/ninechessai_ab.cpp @@ -1007,7 +1007,7 @@ int NineChessAi_ab::recordHash(int value, int alpha, int beta, int depth, HashTy void NineChessAi_ab::clearHashMap() { //hashMapMutex.lock(); - //hashmap.clear(); + hashmap.clear(); //hashMapMutex.unlock(); } #endif /* HASH_MAP_ENABLE */