mirror of
https://github.com/opelly27/Stockfish.git
synced 2026-05-20 10:57:43 +00:00
55a6b2bdc4
# Conflicts: # README.md # Readme.md # src/Makefile # src/evaluate.cpp # src/evaluate.h # src/misc.cpp # src/nnue/architectures/halfkp_256x2-32-32.h # src/nnue/evaluate_nnue.cpp # src/nnue/evaluate_nnue.h # src/nnue/features/feature_set.h # src/nnue/features/features_common.h # src/nnue/features/half_kp.cpp # src/nnue/features/half_kp.h # src/nnue/features/index_list.h # src/nnue/layers/affine_transform.h # src/nnue/layers/clipped_relu.h # src/nnue/layers/input_slice.h # src/nnue/nnue_accumulator.h # src/nnue/nnue_architecture.h # src/nnue/nnue_common.h # src/nnue/nnue_feature_transformer.h # src/position.cpp # src/position.h # src/types.h # src/ucioption.cpp # stockfish.md
69 lines
2.5 KiB
C++
69 lines
2.5 KiB
C++
//Definition of input features HalfRelativeKP of NNUE evaluation function
|
||
|
||
#ifndef _NNUE_FEATURES_HALF_RELATIVE_KP_H_
|
||
#define _NNUE_FEATURES_HALF_RELATIVE_KP_H_
|
||
|
||
#if defined(EVAL_NNUE)
|
||
|
||
#include "../../evaluate.h"
|
||
#include "features_common.h"
|
||
|
||
namespace Eval {
|
||
|
||
namespace NNUE {
|
||
|
||
namespace Features {
|
||
|
||
// Feature HalfRelativeKP: Relative position of each piece other than the ball based on own ball or enemy ball
|
||
template <Side AssociatedKing>
|
||
class HalfRelativeKP {
|
||
public:
|
||
// feature quantity name
|
||
static constexpr const char* kName = (AssociatedKing == Side::kFriend) ?
|
||
"HalfRelativeKP(Friend)" : "HalfRelativeKP(Enemy)";
|
||
// Hash value embedded in the evaluation function file
|
||
static constexpr std::uint32_t kHashValue =
|
||
0xF9180919u ^ (AssociatedKing == Side::kFriend);
|
||
// Piece type excluding balls
|
||
static constexpr IndexType kNumPieceKinds = (PieceSquare::PS_END - PieceSquare::PS_W_PAWN) / SQUARE_NB;
|
||
// width of the virtual board with the ball in the center
|
||
static constexpr IndexType kBoardWidth = FILE_NB * 2 - 1;
|
||
// height of a virtual board with balls in the center
|
||
static constexpr IndexType kBoardHeight = RANK_NB * 2 - 1;
|
||
// number of feature dimensions
|
||
static constexpr IndexType kDimensions =
|
||
kNumPieceKinds * kBoardHeight * kBoardWidth;
|
||
// The maximum value of the number of indexes whose value is 1 at the same time among the feature values
|
||
static constexpr IndexType kMaxActiveDimensions = PieceId::PIECE_ID_KING;
|
||
// Timing of full calculation instead of difference calculation
|
||
static constexpr TriggerEvent kRefreshTrigger =
|
||
(AssociatedKing == Side::kFriend) ?
|
||
TriggerEvent::kFriendKingMoved : TriggerEvent::kEnemyKingMoved;
|
||
|
||
// Get a list of indices with a value of 1 among the features
|
||
static void AppendActiveIndices(const Position& pos, Color perspective,
|
||
IndexList* active);
|
||
|
||
// Get a list of indices whose values have changed from the previous one in the feature quantity
|
||
static void AppendChangedIndices(const Position& pos, Color perspective,
|
||
IndexList* removed, IndexList* added);
|
||
|
||
// Find the index of the feature quantity from the ball position and PieceSquare
|
||
static IndexType MakeIndex(Square sq_k, PieceSquare p);
|
||
|
||
private:
|
||
// Get the piece information
|
||
static void GetPieces(const Position& pos, Color perspective,
|
||
PieceSquare** pieces, Square* sq_target_k);
|
||
};
|
||
|
||
} // namespace Features
|
||
|
||
} // namespace NNUE
|
||
|
||
} // namespace Eval
|
||
|
||
#endif // defined(EVAL_NNUE)
|
||
|
||
#endif
|