-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscore.cpp
More file actions
62 lines (43 loc) · 1003 Bytes
/
score.cpp
File metadata and controls
62 lines (43 loc) · 1003 Bytes
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
// includes
#include <cmath>
#include "common.hpp"
#include "libmy.hpp"
#include "score.hpp"
#include "search.hpp" // for Ply_Max
namespace score {
// functions
Score to_tt(Score sc, Ply ply) {
assert(is_ok(sc));
assert(ply >= 0 && ply <= Ply_Max);
if (is_win(sc)) {
sc += Score(ply);
assert(sc <= +Inf);
} else if (is_loss(sc)) {
sc -= Score(ply);
assert(sc >= -Inf);
}
return sc;
}
Score from_tt(Score sc, Ply ply) {
if (sc == score::None) return score::None; // HACK for SMP
assert(is_ok(sc));
assert(ply >= 0 && ply <= Ply_Max);
if (is_win(sc)) {
sc -= Score(ply);
// assert(is_win(sc)); // triggers in SMP
} else if (is_loss(sc)) {
sc += Score(ply);
// assert(is_loss(sc)); // triggers in SMP
}
return sc;
}
Score clamp(Score sc) {
if (is_win(sc)) {
sc = +Eval_Inf;
} else if (is_loss(sc)) {
sc = -Eval_Inf;
}
assert(is_eval(sc));
return sc;
}
} // namespace score