Path: blob/master/src/nnue/features/full_threats.h
474 views
/*1Stockfish, a UCI chess playing engine derived from Glaurung 2.12Copyright (C) 2004-2025 The Stockfish developers (see AUTHORS file)3Stockfish is free software: you can redistribute it and/or modify4it under the terms of the GNU General Public License as published by5the Free Software Foundation, either version 3 of the License, or6(at your option) any later version.7Stockfish is distributed in the hope that it will be useful,8but WITHOUT ANY WARRANTY; without even the implied warranty of9MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the10GNU General Public License for more details.11You should have received a copy of the GNU General Public License12along with this program. If not, see <http://www.gnu.org/licenses/>.13*/1415//Definition of input features Simplified_Threats of NNUE evaluation function1617#ifndef NNUE_FEATURES_FULL_THREATS_INCLUDED18#define NNUE_FEATURES_FULL_THREATS_INCLUDED1920#include <cstdint>2122#include "../../misc.h"23#include "../../types.h"24#include "../nnue_common.h"2526namespace Stockfish {27class Position;28}2930namespace Stockfish::Eval::NNUE::Features {3132static constexpr int numValidTargets[PIECE_NB] = {0, 6, 12, 10, 10, 12, 8, 0,330, 6, 12, 10, 10, 12, 8, 0};34void init_threat_offsets();3536class FullThreats {37public:38// Feature name39static constexpr const char* Name = "Full_Threats(Friend)";4041// Hash value embedded in the evaluation file42static constexpr std::uint32_t HashValue = 0x8f234cb8u;4344// Number of feature dimensions45static constexpr IndexType Dimensions = 79856;4647// clang-format off48// Orient a square according to perspective (rotates by 180 for black)49static constexpr std::int8_t OrientTBL[SQUARE_NB] = {50SQ_A1, SQ_A1, SQ_A1, SQ_A1, SQ_H1, SQ_H1, SQ_H1, SQ_H1,51SQ_A1, SQ_A1, SQ_A1, SQ_A1, SQ_H1, SQ_H1, SQ_H1, SQ_H1,52SQ_A1, SQ_A1, SQ_A1, SQ_A1, SQ_H1, SQ_H1, SQ_H1, SQ_H1,53SQ_A1, SQ_A1, SQ_A1, SQ_A1, SQ_H1, SQ_H1, SQ_H1, SQ_H1,54SQ_A1, SQ_A1, SQ_A1, SQ_A1, SQ_H1, SQ_H1, SQ_H1, SQ_H1,55SQ_A1, SQ_A1, SQ_A1, SQ_A1, SQ_H1, SQ_H1, SQ_H1, SQ_H1,56SQ_A1, SQ_A1, SQ_A1, SQ_A1, SQ_H1, SQ_H1, SQ_H1, SQ_H1,57SQ_A1, SQ_A1, SQ_A1, SQ_A1, SQ_H1, SQ_H1, SQ_H1, SQ_H1,58};5960static constexpr int map[PIECE_TYPE_NB-2][PIECE_TYPE_NB-2] = {61{0, 1, -1, 2, -1, -1},62{0, 1, 2, 3, 4, 5},63{0, 1, 2, 3, -1, 4},64{0, 1, 2, 3, -1, 4},65{0, 1, 2, 3, 4, 5},66{0, 1, 2, 3, -1, -1}67};68// clang-format on6970struct FusedUpdateData {71Bitboard dp2removedOriginBoard = 0;72Bitboard dp2removedTargetBoard = 0;7374Square dp2removed;75};7677// Maximum number of simultaneously active features.78static constexpr IndexType MaxActiveDimensions = 128;79using IndexList = ValueList<IndexType, MaxActiveDimensions>;80using DiffType = DirtyThreats;8182static IndexType83make_index(Color perspective, Piece attkr, Square from, Square to, Piece attkd, Square ksq);8485// Get a list of indices for active features86static void append_active_indices(Color perspective, const Position& pos, IndexList& active);8788// Get a list of indices for recently changed features89static void append_changed_indices(Color perspective,90Square ksq,91const DiffType& diff,92IndexList& removed,93IndexList& added,94FusedUpdateData* fd = nullptr,95bool first = false);9697// Returns whether the change stored in this DirtyPiece means98// that a full accumulator refresh is required.99static bool requires_refresh(const DiffType& diff, Color perspective);100};101102} // namespace Stockfish::Eval::NNUE::Features103104#endif // #ifndef NNUE_FEATURES_FULL_THREATS_INCLUDED105106107