Move killer[2][MAX_PLY];
U32 history[16][64];
int pv_length[MAX_PLY];
int follow_pv;
long nodes;
int ply;
bool follow_pv;
U64 nodes;
U32 ply;
Move move_list_best_move;
U32 inline move_list_score(Move move) {
const piece::Type type = move.piece().type;
if (move.is_capture()) return piece::score(type, move.piece_capture().type) + 10000;
if (killer[0][ply] == move) return 9000;
if (killer[1][ply] == move) return 8000;
return history[to_underlying(type)][to_underlying(move.target())];
}
void move_list_sort(MoveList &list, bool check_best = true) {
for (auto &[move, score] : list)
score = move_list_score(move);
bool best = false;
if (check_best) {
for (auto &[move, score] : list) {
if (move == move_list_best_move) {
score = 30000;
best = true;
break;
}
}
}
if (!best && ply && follow_pv) {
follow_pv = false;
for (auto &[move, score] : list) {
if (move == pv_table[0][ply]) {
score = 20000;
follow_pv = true;
break;
}
}
}
sort(list.begin(), list.end());
}
int evaluate(const Board &board) {
Color side = board.get_side();