-
Notifications
You must be signed in to change notification settings - Fork 0
/
nnue.cpp
63 lines (57 loc) · 2.26 KB
/
nnue.cpp
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
#include "nnue.hpp"
#include <utility>
namespace nnue {
void Board::setFen(const std::string& fen) {
setFenInternal(fen);
if (prophet) {
prophet_reset(prophet);
prophet_activate_all(prophet,
{
.white = us(chess::Color::WHITE),
.black = us(chess::Color::BLACK),
.pawns = pieces(chess::PieceType::PAWN),
.knights = pieces(chess::PieceType::KNIGHT),
.bishops = pieces(chess::PieceType::BISHOP),
.rooks = pieces(chess::PieceType::ROOK),
.queens = pieces(chess::PieceType::QUEEN),
.kings = pieces(chess::PieceType::KING),
.side_to_move = (uint8_t) side_to_move_,
});
}
}
void Board::accept_prophet(Prophet* new_prophet) {
if (prophet) {
prophet_die_for_sins(prophet);
}
prophet = new_prophet;
prophet_reset(prophet);
prophet_activate_all(prophet,
{
.white = us(chess::Color::WHITE),
.black = us(chess::Color::BLACK),
.pawns = pieces(chess::PieceType::PAWN),
.knights = pieces(chess::PieceType::KNIGHT),
.bishops = pieces(chess::PieceType::BISHOP),
.rooks = pieces(chess::PieceType::ROOK),
.queens = pieces(chess::PieceType::QUEEN),
.kings = pieces(chess::PieceType::KING),
.side_to_move = (uint8_t) side_to_move_,
});
}
Prophet* Board::release_prophet() {
return std::exchange(prophet, nullptr);
}
void Board::placePiece(chess::Piece piece, chess::Square sq) {
if (prophet) prophet_activate(prophet, (int32_t) chess::utils::typeOfPiece(piece), (int32_t) color(piece), sq);
chess::Board::placePiece(piece, sq);
}
void Board::removePiece(chess::Piece piece, chess::Square sq) {
if (prophet) prophet_deactivate(prophet, (int32_t) chess::utils::typeOfPiece(piece), (int32_t) color(piece), sq);
chess::Board::removePiece(piece, sq);
}
Board::~Board() {
if (prophet) {
prophet_die_for_sins(prophet);
}
}
} // namespace nnue