Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
official-stockfish
GitHub Repository: official-stockfish/Stockfish
Path: blob/master/src/nnue/features/half_ka_v2_hm.cpp
633 views
1
/*
2
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
3
Copyright (C) 2004-2026 The Stockfish developers (see AUTHORS file)
4
5
Stockfish is free software: you can redistribute it and/or modify
6
it under the terms of the GNU General Public License as published by
7
the Free Software Foundation, either version 3 of the License, or
8
(at your option) any later version.
9
10
Stockfish is distributed in the hope that it will be useful,
11
but WITHOUT ANY WARRANTY; without even the implied warranty of
12
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
GNU General Public License for more details.
14
15
You should have received a copy of the GNU General Public License
16
along with this program. If not, see <http://www.gnu.org/licenses/>.
17
*/
18
19
//Definition of input features HalfKAv2_hm of NNUE evaluation function
20
21
#include "half_ka_v2_hm.h"
22
23
#include "../../bitboard.h"
24
#include "../../position.h"
25
#include "../../types.h"
26
#include "../nnue_common.h"
27
28
namespace Stockfish::Eval::NNUE::Features {
29
30
// Index of a feature for a given king position and another piece on some square
31
32
IndexType HalfKAv2_hm::make_index(Color perspective, Square s, Piece pc, Square ksq) {
33
const IndexType flip = 56 * perspective;
34
return (IndexType(s) ^ OrientTBL[ksq] ^ flip) + PieceSquareIndex[perspective][pc]
35
+ KingBuckets[int(ksq) ^ flip];
36
}
37
38
// Get a list of indices for active features
39
40
void HalfKAv2_hm::append_active_indices(Color perspective, const Position& pos, IndexList& active) {
41
Square ksq = pos.square<KING>(perspective);
42
Bitboard bb = pos.pieces();
43
while (bb)
44
{
45
Square s = pop_lsb(bb);
46
active.push_back(make_index(perspective, s, pos.piece_on(s), ksq));
47
}
48
}
49
50
// Get a list of indices for recently changed features
51
52
void HalfKAv2_hm::append_changed_indices(
53
Color perspective, Square ksq, const DiffType& diff, IndexList& removed, IndexList& added) {
54
removed.push_back(make_index(perspective, diff.from, diff.pc, ksq));
55
if (diff.to != SQ_NONE)
56
added.push_back(make_index(perspective, diff.to, diff.pc, ksq));
57
58
if (diff.remove_sq != SQ_NONE)
59
removed.push_back(make_index(perspective, diff.remove_sq, diff.remove_pc, ksq));
60
61
if (diff.add_sq != SQ_NONE)
62
added.push_back(make_index(perspective, diff.add_sq, diff.add_pc, ksq));
63
}
64
65
bool HalfKAv2_hm::requires_refresh(const DiffType& diff, Color perspective) {
66
return diff.pc == make_piece(perspective, KING);
67
}
68
69
} // namespace Stockfish::Eval::NNUE::Features
70
71