-
Notifications
You must be signed in to change notification settings - Fork 0
/
node.cuh
74 lines (72 loc) · 2.08 KB
/
node.cuh
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
68
69
70
71
72
73
74
#pragma once
#include "types.hpp"
#include "board.cuh"
class MobilityGenerator {
public:
__device__ MobilityGenerator() {}
__host__ __device__ MobilityGenerator(ull player, ull opponent)
: x(~opponent), y(~player) {}
MobilityGenerator(const MobilityGenerator &) = default;
MobilityGenerator& operator=(const MobilityGenerator &) = default;
__host__ __device__ ull player_pos() const {
return x & ~y;
}
__host__ __device__ ull opponent_pos() const {
return ~x & y;
}
__host__ __device__ ull empty_pos() const {
return ~(x ^ y);
}
__host__ __device__ ull next_bit() {
ull p = not_checked_yet();
constexpr ull corner = UINT64_C(0x8100000000000081);
ull masked = p & corner;
ull bit = masked ? (masked & -masked) : (p & -p);
reset(bit);
return bit;
}
__host__ __device__ bool completed() const {
return not_checked_yet() == 0;
}
__host__ __device__ MobilityGenerator move(ull flip, ull bit) const {
ull p = player_pos();
ull o = opponent_pos();
return MobilityGenerator(o ^ flip, (p ^ flip) | bit);
}
__host__ __device__ MobilityGenerator pass() const {
ull p = player_pos();
ull o = opponent_pos();
return MobilityGenerator(o , p);
}
__host__ __device__ int score() const {
return final_score(player_pos(), opponent_pos());
}
private:
__host__ __device__ ull not_checked_yet() const {
return x & y;
}
__host__ __device__ void reset(ull bit) {
x ^= bit;
y ^= bit;
}
ull x, y;
};
struct Node {
MobilityGenerator mg;
short result;
short alpha;
short beta;
bool not_pass;
bool passed_prev;
__device__ Node() {}
__host__ __device__ Node(const MobilityGenerator &mg, int alpha, int beta, bool passed_prev = false)
: mg(mg), result(-SHRT_MAX), alpha(alpha), beta(beta), not_pass(false), passed_prev(passed_prev) {}
__host__ __device__ Node(const MobilityGenerator &mg)
: Node(mg, -64, 64) {}
Node(const Node &) = default;
Node& operator=(const Node &) = default;
__device__ void commit(short score) {
result = max(result, score);
alpha = max(alpha, result);
}
};