Path: blob/master/src/nnue/features/full_threats.h
648 views
/*1Stockfish, a UCI chess playing engine derived from Glaurung 2.12Copyright (C) 2004-2026 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, 10, 8, 8, 10, 0, 0,330, 6, 10, 8, 8, 10, 0, 0};3435class FullThreats {36public:37// Feature name38static constexpr const char* Name = "Full_Threats(Friend)";3940// Hash value embedded in the evaluation file41static constexpr std::uint32_t HashValue = 0x8f234cb8u;4243// Number of feature dimensions44static constexpr IndexType Dimensions = 60144;4546// clang-format off47// Orient a square according to perspective (rotates by 180 for black)48static constexpr std::int8_t OrientTBL[SQUARE_NB] = {49SQ_A1, SQ_A1, SQ_A1, SQ_A1, SQ_H1, SQ_H1, SQ_H1, SQ_H1,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,57};5859static constexpr int map[PIECE_TYPE_NB-2][PIECE_TYPE_NB-2] = {60{ 0, 1, -1, 2, -1, -1},61{ 0, 1, 2, 3, 4, -1},62{ 0, 1, 2, 3, -1, -1},63{ 0, 1, 2, 3, -1, -1},64{ 0, 1, 2, 3, 4, -1},65{-1, -1, -1, -1, -1, -1}66};67// clang-format on6869struct FusedUpdateData {70Bitboard dp2removedOriginBoard = 0;71Bitboard dp2removedTargetBoard = 0;7273Square dp2removed;74};7576// Maximum number of simultaneously active features.77static constexpr IndexType MaxActiveDimensions = 128;78using IndexList = ValueList<IndexType, MaxActiveDimensions>;79using DiffType = DirtyThreats;8081static IndexType82make_index(Color perspective, Piece attkr, Square from, Square to, Piece attkd, Square ksq);8384// Get a list of indices for active features85static void append_active_indices(Color perspective, const Position& pos, IndexList& active);8687// Get a list of indices for recently changed features88static void append_changed_indices(Color perspective,89Square ksq,90const DiffType& diff,91IndexList& removed,92IndexList& added,93FusedUpdateData* fd = nullptr,94bool first = false,95const ThreatWeightType* prefetchBase = nullptr,96IndexType prefetchStride = 0);9798// Returns whether the change stored in this DirtyPiece means99// that a full accumulator refresh is required.100static bool requires_refresh(const DiffType& diff, Color perspective);101};102103} // namespace Stockfish::Eval::NNUE::Features104105#endif // #ifndef NNUE_FEATURES_FULL_THREATS_INCLUDED106107108