-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtranspositions.c
67 lines (60 loc) · 2.17 KB
/
transpositions.c
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#include "board.h"
#include "transpositions.h"
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
void initTable(unsigned long long size) {
transSize = size;
table = (struct bucket*)malloc(sizeof(struct bucket)*size);
if (table == 0) {
perror("Can not allocate transtable");
}
memset(table, 0, sizeof(struct bucket)*size);
}
inline void save(int score, int work, int flag, int s, unsigned long long idx) {
table[idx].slot[s].board[0] = board[0]&getPotential(0);
table[idx].slot[s].board[1] = board[1]&getPotential(1);
table[idx].slot[s].board[2] = board[0]|board[1];
table[idx].slot[s].data = flag | (score<<2);
table[idx].slot[s].work = work;
}
inline void putTable(int score, int work, int flag) {
unsigned long long idx = getHash()%transSize;
if (table[idx].slot[1].work <= work) {
save(score, work, flag, 1, idx);
} else {
save(score, work, flag, 0, idx);
}
}
inline int getType() {
unsigned long long idx = getHash()%transSize;
unsigned long long p1 = board[0]&getPotential(0);
unsigned long long p2 = board[1]&getPotential(1);
if (table[idx].slot[0].board[0] == p1 &&
table[idx].slot[0].board[1] == p2 &&
table[idx].slot[0].board[2] == (board[0]|board[1])) {
return table[idx].slot[0].data&TYPE_MASK;
}
else if (table[idx].slot[1].board[0] == p1 &&
table[idx].slot[1].board[1] == p2 &&
table[idx].slot[1].board[2] == (board[0]|board[1])) {
return table[idx].slot[1].data&TYPE_MASK;
}
return TT_EMPTY;
}
inline int getScore() {
unsigned long long idx = getHash()%transSize;
unsigned long long p1 = board[0]&getPotential(0);
unsigned long long p2 = board[1]&getPotential(1);
if (table[idx].slot[0].board[0] == p1 &&
table[idx].slot[0].board[1] == p2 &&
table[idx].slot[0].board[2] == board[0]|board[1]) {
return table[idx].slot[0].data&RESULT_MASK;
}
else if (table[idx].slot[1].board[0] == p1 &&
table[idx].slot[1].board[1] == p2 &&
table[idx].slot[1].board[2] == (board[0]|board[1])) {
return table[idx].slot[1].data&RESULT_MASK;
}
return 0;
}