-
Notifications
You must be signed in to change notification settings - Fork 0
/
zobrist.cpp
45 lines (38 loc) · 1.24 KB
/
zobrist.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#include "zobrist.h"
#include "mainwindow.h"
#include "mythread.h"
extern int count, ABcut, tag, sto;
bool MyThread::lookup(int depth, int alpha, int beta, Pos& ret)
{
uint64_t hashInfo = hash & (HASH_TABLE_SIZE - 1); // 获取局面在表中位置
if((H[hashInfo].ref.a2 >= depth) && H[hashInfo].checknum == hash)
{
if(H[hashInfo].flag == HASH_EXACT){
ret = H[hashInfo].ref;
}else if(H[hashInfo].flag == HASH_ALPHA && H[hashInfo].ref.value <= alpha){
ret = H[hashInfo].ref;
ret.value = alpha;
}else if(H[hashInfo].flag == HASH_BETA && H[hashInfo].ref.value >= beta){
ret = H[hashInfo].ref;
ret.value = beta;
}else
return false;
tag++;
return true;
}
return false;
}
bool MyThread::store(QMutex &m, int hashf, long long hashIndex, const Pos ret, int deep)
{
uint64_t hashInfo;
QMutexLocker locker(&m);
hashInfo = hashIndex & (HASH_TABLE_SIZE - 1);
if(H[hashInfo].flag > HASH_BETA || H[hashInfo].flag < HASH_EXACT){
sto++;
H[hashInfo].checknum = hash;
H[hashInfo].flag = hashf;
H[hashInfo].ref = ret;
H[hashInfo].ref.a2 = deep;
}
return true;
}