-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathboard_eval.h
More file actions
132 lines (97 loc) · 2.04 KB
/
board_eval.h
File metadata and controls
132 lines (97 loc) · 2.04 KB
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
#pragma once
#include <cstdint>
#include <atomic>
#include "bit_manipulation.h"
struct Lock {
private:
std::atomic_flag is_locked;
public:
inline Lock() { ; }
inline void lock() {
while (std::atomic_flag_test_and_set(&is_locked)) {
;
}
}
inline void unlock() {
std::atomic_flag_clear(&is_locked);
}
inline bool try_lock() {
return !(std::atomic_flag_test_and_set(&is_locked));
}
};
int get_number_of_CPU_core();
#include <exception>
class EvalFailureException : public std::runtime_error {
public:
EvalFailureException() noexcept;
};
enum class piece_id : Uint8;
struct bot_move_data {
Sint8 begin_pos = -1;
Sint8 target_pos = -1;
bool promotion = false;
bool tera = false;
bool skip_bonus_turn = false;
piece_id promotion_id = std::bit_cast<piece_id>((Uint8)-1);
};
template<typename T, size_t capacity>
struct MoveContainer {
private:
std::array<T, capacity> data;
size_t len;
public:
inline MoveContainer() {
len = 0;
}
inline void push(T const& value) {
#if ENABLE_SAFETY_CHECKS
if (length == capacity)
throw;
#endif
data[len++] = value;
}
inline T* begin() {
return data._Unchecked_begin();
}
inline T* end() {
return begin() + len;
}
inline bool empty() {
return len == 0;
}
inline T& back() {
return data[len-1];
}
inline void pop() {
#if ENABLE_SAFETY_CHECKS
if (length == 0)
throw;
#endif
len--;
}
inline constexpr size_t length() {
return len;
}
inline constexpr T& operator[](size_t index) {
#if ENABLE_SAFETY_CHECKS
if (index >= length)
throw;
#endif
return data[index];
}
inline constexpr T const& operator[](size_t index) const {
#if ENABLE_SAFETY_CHECKS
if (index >= length)
throw;
#endif
return data[index];
}
};
#include "board.h"
#include "piece2.h"
float eval_depth0(Board& board);
float eval_board(Board& board, int depth, float alpha, float beta, bot_move_data* best_move);
void start_eval(Game&, Board& board);
void start_threaded_eval(Game& game, Board& board);
Uint64 perft(Board& board, int depth);
void print_perft(Board board, int depth);