Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
official-stockfish
GitHub Repository: official-stockfish/Stockfish
Path: blob/master/src/nnue/features/full_threats.h
648 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
Stockfish is free software: you can redistribute it and/or modify
5
it under the terms of the GNU General Public License as published by
6
the Free Software Foundation, either version 3 of the License, or
7
(at your option) any later version.
8
Stockfish is distributed in the hope that it will be useful,
9
but WITHOUT ANY WARRANTY; without even the implied warranty of
10
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
GNU General Public License for more details.
12
You should have received a copy of the GNU General Public License
13
along with this program. If not, see <http://www.gnu.org/licenses/>.
14
*/
15
16
//Definition of input features Simplified_Threats of NNUE evaluation function
17
18
#ifndef NNUE_FEATURES_FULL_THREATS_INCLUDED
19
#define NNUE_FEATURES_FULL_THREATS_INCLUDED
20
21
#include <cstdint>
22
23
#include "../../misc.h"
24
#include "../../types.h"
25
#include "../nnue_common.h"
26
27
namespace Stockfish {
28
class Position;
29
}
30
31
namespace Stockfish::Eval::NNUE::Features {
32
33
static constexpr int numValidTargets[PIECE_NB] = {0, 6, 10, 8, 8, 10, 0, 0,
34
0, 6, 10, 8, 8, 10, 0, 0};
35
36
class FullThreats {
37
public:
38
// Feature name
39
static constexpr const char* Name = "Full_Threats(Friend)";
40
41
// Hash value embedded in the evaluation file
42
static constexpr std::uint32_t HashValue = 0x8f234cb8u;
43
44
// Number of feature dimensions
45
static constexpr IndexType Dimensions = 60144;
46
47
// clang-format off
48
// Orient a square according to perspective (rotates by 180 for black)
49
static constexpr std::int8_t OrientTBL[SQUARE_NB] = {
50
SQ_A1, SQ_A1, SQ_A1, SQ_A1, SQ_H1, SQ_H1, SQ_H1, SQ_H1,
51
SQ_A1, SQ_A1, SQ_A1, SQ_A1, SQ_H1, SQ_H1, SQ_H1, SQ_H1,
52
SQ_A1, SQ_A1, SQ_A1, SQ_A1, SQ_H1, SQ_H1, SQ_H1, SQ_H1,
53
SQ_A1, SQ_A1, SQ_A1, SQ_A1, SQ_H1, SQ_H1, SQ_H1, SQ_H1,
54
SQ_A1, SQ_A1, SQ_A1, SQ_A1, SQ_H1, SQ_H1, SQ_H1, SQ_H1,
55
SQ_A1, SQ_A1, SQ_A1, SQ_A1, SQ_H1, SQ_H1, SQ_H1, SQ_H1,
56
SQ_A1, SQ_A1, SQ_A1, SQ_A1, SQ_H1, SQ_H1, SQ_H1, SQ_H1,
57
SQ_A1, SQ_A1, SQ_A1, SQ_A1, SQ_H1, SQ_H1, SQ_H1, SQ_H1,
58
};
59
60
static constexpr int map[PIECE_TYPE_NB-2][PIECE_TYPE_NB-2] = {
61
{ 0, 1, -1, 2, -1, -1},
62
{ 0, 1, 2, 3, 4, -1},
63
{ 0, 1, 2, 3, -1, -1},
64
{ 0, 1, 2, 3, -1, -1},
65
{ 0, 1, 2, 3, 4, -1},
66
{-1, -1, -1, -1, -1, -1}
67
};
68
// clang-format on
69
70
struct FusedUpdateData {
71
Bitboard dp2removedOriginBoard = 0;
72
Bitboard dp2removedTargetBoard = 0;
73
74
Square dp2removed;
75
};
76
77
// Maximum number of simultaneously active features.
78
static constexpr IndexType MaxActiveDimensions = 128;
79
using IndexList = ValueList<IndexType, MaxActiveDimensions>;
80
using DiffType = DirtyThreats;
81
82
static IndexType
83
make_index(Color perspective, Piece attkr, Square from, Square to, Piece attkd, Square ksq);
84
85
// Get a list of indices for active features
86
static void append_active_indices(Color perspective, const Position& pos, IndexList& active);
87
88
// Get a list of indices for recently changed features
89
static void append_changed_indices(Color perspective,
90
Square ksq,
91
const DiffType& diff,
92
IndexList& removed,
93
IndexList& added,
94
FusedUpdateData* fd = nullptr,
95
bool first = false,
96
const ThreatWeightType* prefetchBase = nullptr,
97
IndexType prefetchStride = 0);
98
99
// Returns whether the change stored in this DirtyPiece means
100
// that a full accumulator refresh is required.
101
static bool requires_refresh(const DiffType& diff, Color perspective);
102
};
103
104
} // namespace Stockfish::Eval::NNUE::Features
105
106
#endif // #ifndef NNUE_FEATURES_FULL_THREATS_INCLUDED
107
108