mirror of
https://github.com/opelly27/Stockfish.git
synced 2026-05-20 05:07:46 +00:00
9b4967071e
This patch removes the EvalList structure from the Position object and generally simplifies the interface between do_move() and the NNUE code. The NNUE evaluation function first calculates the "accumulator". The accumulator consists of two halves: one for white's perspective, one for black's perspective. If the "friendly king" has moved or the accumulator for the parent position is not available, the accumulator for this half has to be calculated from scratch. To do this, the NNUE node needs to know the positions and types of all non-king pieces and the position of the friendly king. This information can easily be obtained from the Position object. If the "friendly king" has not moved, its half of the accumulator can be calculated by incrementally updating the accumulator for the previous position. For this, the NNUE code needs to know which pieces have been added to which squares and which pieces have been removed from which squares. In principle this information can be derived from the Position object and StateInfo struct (in the same way as undo_move() does this). However, it is probably a bit faster to prepare this information in do_move(), so I have kept the DirtyPiece struct. Since the DirtyPiece struct now stores the squares rather than "PieceSquare" indices, there are now at most three "dirty pieces" (previously two). A promotion move that captures a piece removes the capturing pawn and the captured piece from the board (to SQ_NONE) and moves the promoted piece to the promotion square (from SQ_NONE). An STC test has confirmed a small speedup: https://tests.stockfishchess.org/tests/view/5f43f06b5089a564a10d850a LLR: 2.94 (-2.94,2.94) {-0.25,1.25} Total: 87704 W: 9763 L: 9500 D: 68441 Ptnml(0-2): 426, 6950, 28845, 7197, 434 closes https://github.com/official-stockfish/Stockfish/pull/3068 No functional change
64 lines
2.5 KiB
C++
64 lines
2.5 KiB
C++
/*
|
|
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
|
Copyright (C) 2004-2020 The Stockfish developers (see AUTHORS file)
|
|
|
|
Stockfish is free software: you can redistribute it and/or modify
|
|
it under the terms of the GNU General Public License as published by
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
(at your option) any later version.
|
|
|
|
Stockfish is distributed in the hope that it will be useful,
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
GNU General Public License for more details.
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
*/
|
|
|
|
//Definition of input features HalfKP of NNUE evaluation function
|
|
|
|
#ifndef NNUE_FEATURES_HALF_KP_H_INCLUDED
|
|
#define NNUE_FEATURES_HALF_KP_H_INCLUDED
|
|
|
|
#include "../../evaluate.h"
|
|
#include "features_common.h"
|
|
|
|
namespace Eval::NNUE::Features {
|
|
|
|
// Feature HalfKP: Combination of the position of own king
|
|
// and the position of pieces other than kings
|
|
template <Side AssociatedKing>
|
|
class HalfKP {
|
|
|
|
public:
|
|
// Feature name
|
|
static constexpr const char* kName = "HalfKP(Friend)";
|
|
// Hash value embedded in the evaluation file
|
|
static constexpr std::uint32_t kHashValue =
|
|
0x5D69D5B9u ^ (AssociatedKing == Side::kFriend);
|
|
// Number of feature dimensions
|
|
static constexpr IndexType kDimensions =
|
|
static_cast<IndexType>(SQUARE_NB) * static_cast<IndexType>(PS_END);
|
|
// Maximum number of simultaneously active features
|
|
static constexpr IndexType kMaxActiveDimensions = 30; // Kings don't count
|
|
// Trigger for full calculation instead of difference calculation
|
|
static constexpr TriggerEvent kRefreshTrigger = TriggerEvent::kFriendKingMoved;
|
|
|
|
// Get a list of indices for active features
|
|
static void AppendActiveIndices(const Position& pos, Color perspective,
|
|
IndexList* active);
|
|
|
|
// Get a list of indices for recently changed features
|
|
static void AppendChangedIndices(const Position& pos, Color perspective,
|
|
IndexList* removed, IndexList* added);
|
|
|
|
private:
|
|
// Index of a feature for a given king position and another piece on some square
|
|
static IndexType MakeIndex(Color perspective, Square s, Piece pc, Square sq_k);
|
|
};
|
|
|
|
} // namespace Eval::NNUE::Features
|
|
|
|
#endif // #ifndef NNUE_FEATURES_HALF_KP_H_INCLUDED
|