Skip to content

Commit 3e5c856

Browse files
committed
hash: 哈希表大小由64M调小为32M
* g++ 编译后运行不再提示 std::bad_alloc * 运行速度反而提升 5%
1 parent 8d05047 commit 3e5c856

File tree

1 file changed

+20
-20
lines changed

1 file changed

+20
-20
lines changed

NineChess/src/ninechessai_ab.cpp

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
using namespace CTSL;
3535

3636
#ifdef HASH_MAP_ENABLE
37-
static constexpr int hashsize = 0x4000000; // 8-128M:102s, 4-64M:93s 2-32M:91s 1-16M: 冲突
37+
static constexpr int hashsize = 0x2000000; // 8-128M:102s, 4-64M:93s 2-32M:91s 1-16M: 冲突
3838
HashMap<uint64_t, NineChessAi_ab::HashValue> hashmap(hashsize);
3939
#endif // HASH_MAP_ENABLE
4040

@@ -1026,20 +1026,20 @@ int NineChessAi_ab::probeHash(uint64_t hash, int depth, int alpha, int beta, int
10261026

10271027
type = hashValue.type;
10281028

1029-
if (hashValue.type == hashfEXACT) {
1030-
return hashValue.value;
1031-
}
1032-
if ((hashValue.type == hashfALPHA) && // 最多是 hashValue.value
1033-
(hashValue.value <= alpha)) {
1034-
return alpha;
1035-
}
1036-
if ((hashValue.type == hashfBETA) && // 至少是 hashValue.value
1037-
(hashValue.value >= beta)) {
1038-
return beta;
1029+
if (hashValue.type == hashfEXACT) {
1030+
return hashValue.value;
1031+
}
1032+
if ((hashValue.type == hashfALPHA) && // 最多是 hashValue.value
1033+
(hashValue.value <= alpha)) {
1034+
return alpha;
1035+
}
1036+
if ((hashValue.type == hashfBETA) && // 至少是 hashValue.value
1037+
(hashValue.value >= beta)) {
1038+
return beta;
10391039
}
10401040

1041-
out:
1042-
bestMove = hashValue.bestMove;
1041+
out:
1042+
bestMove = hashValue.bestMove;
10431043
return valUNKNOWN;
10441044
}
10451045

@@ -1081,13 +1081,13 @@ int NineChessAi_ab::recordHash(int value, int depth, HashType type, uint64_t has
10811081
HashValue hashValue;
10821082
memset(&hashValue, 0, sizeof(HashValue));
10831083

1084-
if (findHash(hash, hashValue) &&
1085-
hashValue.type != hashfEMPTY &&
1086-
hashValue.depth > depth) {
1087-
#ifdef DEBUG_MODE
1088-
qDebug() << "Skip recordHash coz depth";
1089-
#endif
1090-
return -1;
1084+
if (findHash(hash, hashValue) &&
1085+
hashValue.type != hashfEMPTY &&
1086+
hashValue.depth > depth) {
1087+
#ifdef DEBUG_MODE
1088+
qDebug() << "Skip recordHash coz depth";
1089+
#endif
1090+
return -1;
10911091
}
10921092

10931093
hashValue.value = value;

0 commit comments

Comments
 (0)