From 3e5c856d861848be8a41582d5616c242bda0b685 Mon Sep 17 00:00:00 2001 From: CalciteM Team Date: Thu, 1 Aug 2019 22:50:09 +0800 Subject: [PATCH] =?UTF-8?q?hash:=20=E5=93=88=E5=B8=8C=E8=A1=A8=E5=A4=A7?= =?UTF-8?q?=E5=B0=8F=E7=94=B164M=E8=B0=83=E5=B0=8F=E4=B8=BA32M?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * g++ 编译后运行不再提示 std::bad_alloc * 运行速度反而提升 5% --- NineChess/src/ninechessai_ab.cpp | 40 ++++++++++++++++---------------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/NineChess/src/ninechessai_ab.cpp b/NineChess/src/ninechessai_ab.cpp index 55a939b3..2b7478f8 100644 --- a/NineChess/src/ninechessai_ab.cpp +++ b/NineChess/src/ninechessai_ab.cpp @@ -34,7 +34,7 @@ using namespace CTSL; #ifdef HASH_MAP_ENABLE -static constexpr int hashsize = 0x4000000; // 8-128M:102s, 4-64M:93s 2-32M:91s 1-16M: 冲突 +static constexpr int hashsize = 0x2000000; // 8-128M:102s, 4-64M:93s 2-32M:91s 1-16M: 冲突 HashMap hashmap(hashsize); #endif // HASH_MAP_ENABLE @@ -1026,20 +1026,20 @@ int NineChessAi_ab::probeHash(uint64_t hash, int depth, int alpha, int beta, int type = hashValue.type; - if (hashValue.type == hashfEXACT) { - return hashValue.value; - } - if ((hashValue.type == hashfALPHA) && // 最多是 hashValue.value - (hashValue.value <= alpha)) { - return alpha; - } - if ((hashValue.type == hashfBETA) && // 至少是 hashValue.value - (hashValue.value >= beta)) { - return beta; + if (hashValue.type == hashfEXACT) { + return hashValue.value; + } + if ((hashValue.type == hashfALPHA) && // 最多是 hashValue.value + (hashValue.value <= alpha)) { + return alpha; + } + if ((hashValue.type == hashfBETA) && // 至少是 hashValue.value + (hashValue.value >= beta)) { + return beta; } -out: - bestMove = hashValue.bestMove; +out: + bestMove = hashValue.bestMove; return valUNKNOWN; } @@ -1081,13 +1081,13 @@ int NineChessAi_ab::recordHash(int value, int depth, HashType type, uint64_t has HashValue hashValue; memset(&hashValue, 0, sizeof(HashValue)); - if (findHash(hash, hashValue) && - hashValue.type != hashfEMPTY && - hashValue.depth > depth) { -#ifdef DEBUG_MODE - qDebug() << "Skip recordHash coz depth"; -#endif - return -1; + if (findHash(hash, hashValue) && + hashValue.type != hashfEMPTY && + hashValue.depth > depth) { +#ifdef DEBUG_MODE + qDebug() << "Skip recordHash coz depth"; +#endif + return -1; } hashValue.value = value;