mirror of
https://github.com/HChaZZY/Stockfish.git
synced 2025-12-25 19:46:55 +08:00
Merge branch 'master' of github.com:official-stockfish/Stockfish into nnue-player-merge
# 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
This commit is contained in:
@@ -7,22 +7,22 @@ namespace Eval
|
||||
|
||||
// --- tables
|
||||
|
||||
// Value when a certain BonaPiece is seen from the other side
|
||||
// Value when a certain PieceSquare is seen from the other side
|
||||
// BONA_PIECE_INIT is -1, so it must be a signed type.
|
||||
// Even if KPPT is expanded, BonaPiece will not exceed 2^15 for the time being, so int16_t is good.
|
||||
int16_t inv_piece_[Eval::fe_end];
|
||||
// Even if KPPT is expanded, PieceSquare will not exceed 2^15 for the time being, so int16_t is good.
|
||||
int16_t inv_piece_[PieceSquare::PS_END];
|
||||
|
||||
// Returns the one at the position where a BonaPiece on the board is mirrored.
|
||||
int16_t mir_piece_[Eval::fe_end];
|
||||
// Returns the one at the position where a PieceSquare on the board is mirrored.
|
||||
int16_t mir_piece_[PieceSquare::PS_END];
|
||||
|
||||
|
||||
// --- methods
|
||||
|
||||
// Returns the value when a certain BonaPiece is seen from the other side
|
||||
Eval::BonaPiece inv_piece(Eval::BonaPiece p) { return (Eval::BonaPiece)inv_piece_[p]; }
|
||||
// Returns the value when a certain PieceSquare is seen from the other side
|
||||
PieceSquare inv_piece(PieceSquare p) { return (PieceSquare)inv_piece_[p]; }
|
||||
|
||||
// Returns the one at the position where a BonaPiece on the board is mirrored.
|
||||
Eval::BonaPiece mir_piece(Eval::BonaPiece p) { return (Eval::BonaPiece)mir_piece_[p]; }
|
||||
// Returns the one at the position where a PieceSquare on the board is mirrored.
|
||||
PieceSquare mir_piece(PieceSquare p) { return (PieceSquare)mir_piece_[p]; }
|
||||
|
||||
std::function<void()> mir_piece_init_function;
|
||||
|
||||
@@ -37,23 +37,23 @@ namespace Eval
|
||||
|
||||
// exchange f and e
|
||||
int t[] = {
|
||||
f_pawn , e_pawn ,
|
||||
f_knight , e_knight ,
|
||||
f_bishop , e_bishop ,
|
||||
f_rook , e_rook ,
|
||||
f_queen , e_queen ,
|
||||
PieceSquare::PS_W_PAWN , PieceSquare::PS_B_PAWN ,
|
||||
PieceSquare::PS_W_KNIGHT , PieceSquare::PS_B_KNIGHT ,
|
||||
PieceSquare::PS_W_BISHOP , PieceSquare::PS_B_BISHOP ,
|
||||
PieceSquare::PS_W_ROOK , PieceSquare::PS_B_ROOK ,
|
||||
PieceSquare::PS_W_QUEEN , PieceSquare::PS_B_QUEEN ,
|
||||
};
|
||||
|
||||
// Insert uninitialized value.
|
||||
for (BonaPiece p = BONA_PIECE_ZERO; p < fe_end; ++p)
|
||||
for (PieceSquare p = PieceSquare::PS_NONE; p < PieceSquare::PS_END; ++p)
|
||||
{
|
||||
inv_piece_[p] = BONA_PIECE_NOT_INIT;
|
||||
inv_piece_[p] = PieceSquare::PS_NOT_INIT;
|
||||
|
||||
// mirror does not work for hand pieces. Just return the original value.
|
||||
mir_piece_[p] = (p < f_pawn) ? p : BONA_PIECE_NOT_INIT;
|
||||
mir_piece_[p] = (p < PieceSquare::PS_W_PAWN) ? p : PieceSquare::PS_NOT_INIT;
|
||||
}
|
||||
|
||||
for (BonaPiece p = BONA_PIECE_ZERO; p < fe_end; ++p)
|
||||
for (PieceSquare p = PieceSquare::PS_NONE; p < PieceSquare::PS_END; ++p)
|
||||
{
|
||||
for (int i = 0; i < 32 /* t.size() */; i += 2)
|
||||
{
|
||||
@@ -62,13 +62,13 @@ namespace Eval
|
||||
Square sq = (Square)(p - t[i]);
|
||||
|
||||
// found!!
|
||||
BonaPiece q = (p < fe_hand_end) ? BonaPiece(sq + t[i + 1]) : (BonaPiece)(Inv(sq) + t[i + 1]);
|
||||
PieceSquare q = (p < PieceSquare::PS_W_PAWN) ? PieceSquare(sq + t[i + 1]) : (PieceSquare)(rotate180(sq) + t[i + 1]);
|
||||
inv_piece_[p] = q;
|
||||
inv_piece_[q] = p;
|
||||
|
||||
/*
|
||||
It's a bit tricky, but regarding p
|
||||
p >= fe_hand_end
|
||||
p >= PieceSquare::PS_W_PAWN
|
||||
When.
|
||||
|
||||
For this p, let n be an integer (i in the above code can only be an even number),
|
||||
@@ -76,20 +76,20 @@ namespace Eval
|
||||
b) When t[2n + 1] <= p <t[2n + 2], the back piece
|
||||
Is.
|
||||
|
||||
Therefore, if p in the range of a) is set to q = Inv(p-t[2n+0]) + t[2n+1], it becomes the back piece in the box rotated 180 degrees.
|
||||
Therefore, if p in the range of a) is set to q = rotate180(p-t[2n+0]) + t[2n+1], it becomes the back piece in the box rotated 180 degrees.
|
||||
So inv_piece[] is initialized by swapping p and q.
|
||||
*/
|
||||
|
||||
// There is no mirror for hand pieces.
|
||||
if (p < fe_hand_end)
|
||||
if (p < PieceSquare::PS_W_PAWN)
|
||||
continue;
|
||||
|
||||
BonaPiece r1 = (BonaPiece)(Mir(sq) + t[i]);
|
||||
PieceSquare r1 = (PieceSquare)(flip_file(sq) + t[i]);
|
||||
mir_piece_[p] = r1;
|
||||
mir_piece_[r1] = p;
|
||||
|
||||
BonaPiece p2 = (BonaPiece)(sq + t[i + 1]);
|
||||
BonaPiece r2 = (BonaPiece)(Mir(sq) + t[i + 1]);
|
||||
PieceSquare p2 = (PieceSquare)(sq + t[i + 1]);
|
||||
PieceSquare r2 = (PieceSquare)(flip_file(sq) + t[i + 1]);
|
||||
mir_piece_[p2] = r2;
|
||||
mir_piece_[r2] = p2;
|
||||
|
||||
@@ -101,11 +101,11 @@ namespace Eval
|
||||
if (mir_piece_init_function)
|
||||
mir_piece_init_function();
|
||||
|
||||
for (BonaPiece p = BONA_PIECE_ZERO; p < fe_end; ++p)
|
||||
for (PieceSquare p = PieceSquare::PS_NONE; p < PieceSquare::PS_END; ++p)
|
||||
{
|
||||
// It remains uninitialized. The initialization code in the table above is incorrect.
|
||||
assert(mir_piece_[p] != BONA_PIECE_NOT_INIT && mir_piece_[p] < fe_end);
|
||||
assert(inv_piece_[p] != BONA_PIECE_NOT_INIT && inv_piece_[p] < fe_end);
|
||||
assert(mir_piece_[p] != PieceSquare::PS_NOT_INIT && mir_piece_[p] < PieceSquare::PS_END);
|
||||
assert(inv_piece_[p] != PieceSquare::PS_NOT_INIT && inv_piece_[p] < PieceSquare::PS_END);
|
||||
|
||||
// mir and inv return to their original coordinates after being applied twice.
|
||||
assert(mir_piece_[mir_piece_[p]] == p);
|
||||
@@ -126,7 +126,7 @@ namespace Eval
|
||||
// Apery's WCSC26 evaluation function, kpp p1==0 or p1==20 (0th step on the back)
|
||||
// There is dust in it, and if you don't avoid it, it will get caught in the assert.
|
||||
|
||||
std::unordered_set<BonaPiece> s;
|
||||
std::unordered_set<PieceSquare> s;
|
||||
vector<int> a = {
|
||||
f_hand_pawn - 1,e_hand_pawn - 1,
|
||||
f_hand_lance - 1, e_hand_lance - 1,
|
||||
@@ -137,7 +137,7 @@ namespace Eval
|
||||
f_hand_rook - 1, e_hand_rook - 1,
|
||||
};
|
||||
for (auto b : a)
|
||||
s.insert((BonaPiece)b);
|
||||
s.insert((PieceSquare)b);
|
||||
|
||||
// Excludes walks, incense, and katsura on the board that do not appear further (Apery also contains garbage here)
|
||||
for (Rank r = RANK_1; r <= RANK_2; ++r)
|
||||
@@ -146,18 +146,18 @@ namespace Eval
|
||||
if (r == RANK_1)
|
||||
{
|
||||
// first step
|
||||
BonaPiece b1 = BonaPiece(f_pawn + (f | r));
|
||||
PieceSquare b1 = PieceSquare(PieceSquare::PS_W_PAWN + (f | r));
|
||||
s.insert(b1);
|
||||
s.insert(inv_piece[b1]);
|
||||
|
||||
// 1st stage incense
|
||||
BonaPiece b2 = BonaPiece(f_lance + (f | r));
|
||||
PieceSquare b2 = PieceSquare(f_lance + (f | r));
|
||||
s.insert(b2);
|
||||
s.insert(inv_piece[b2]);
|
||||
}
|
||||
|
||||
// Katsura on the 1st and 2nd steps
|
||||
BonaPiece b = BonaPiece(f_knight + (f | r));
|
||||
PieceSquare b = PieceSquare(PieceSquare::PS_W_KNIGHT + (f | r));
|
||||
s.insert(b);
|
||||
s.insert(inv_piece[b]);
|
||||
}
|
||||
@@ -166,8 +166,8 @@ namespace Eval
|
||||
for (auto sq : SQ)
|
||||
{
|
||||
cout << sq << ' ';
|
||||
for (BonaPiece p1 = BONA_PIECE_ZERO; p1 < fe_end; ++p1)
|
||||
for (BonaPiece p2 = BONA_PIECE_ZERO; p2 < fe_end; ++p2)
|
||||
for (PieceSquare p1 = PieceSquare::PS_NONE; p1 < PieceSquare::PS_END; ++p1)
|
||||
for (PieceSquare p2 = PieceSquare::PS_NONE; p2 < PieceSquare::PS_END; ++p2)
|
||||
if (!s.count(p1) && !s.count(p2))
|
||||
kpp_write(sq, p1, p2, kpp[sq][p1][p2]);
|
||||
}
|
||||
@@ -177,7 +177,7 @@ namespace Eval
|
||||
{
|
||||
cout << sq1 << ' ';
|
||||
for (auto sq2 : SQ)
|
||||
for (BonaPiece p1 = BONA_PIECE_ZERO; p1 < fe_end; ++p1)
|
||||
for (PieceSquare p1 = PieceSquare::PS_NONE; p1 < PieceSquare::PS_END; ++p1)
|
||||
if (!s.count(p1))
|
||||
kkp_write(sq1, sq2, p1, kkp[sq1][sq2][p1]);
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
|
||||
#if defined(EVAL_NNUE) || defined(EVAL_LEARN)
|
||||
|
||||
// BonaPiece's mirror (horizontal flip) and inverse (180° on the board) tools to get pieces.
|
||||
// PieceSquare's mirror (horizontal flip) and inverse (180° on the board) tools to get pieces.
|
||||
|
||||
#include "../types.h"
|
||||
#include "../evaluate.h"
|
||||
@@ -15,18 +15,18 @@ namespace Eval
|
||||
// tables
|
||||
// -------------------------------------------------
|
||||
|
||||
// --- Provide Mirror and Inverse to BonaPiece.
|
||||
// --- Provide Mirror and Inverse to PieceSquare.
|
||||
|
||||
// These arrays are initialized by calling init() or init_mir_inv_tables();.
|
||||
// If you want to use only this table from the evaluation function,
|
||||
// Call init_mir_inv_tables().
|
||||
// These arrays are referenced from the KK/KKP/KPP classes below.
|
||||
|
||||
// Returns the value when a certain BonaPiece is seen from the other side
|
||||
extern Eval::BonaPiece inv_piece(Eval::BonaPiece p);
|
||||
// Returns the value when a certain PieceSquare is seen from the other side
|
||||
extern PieceSquare inv_piece(PieceSquare p);
|
||||
|
||||
// Returns the one at the position where a BonaPiece on the board is mirrored.
|
||||
extern Eval::BonaPiece mir_piece(Eval::BonaPiece p);
|
||||
// Returns the one at the position where a PieceSquare on the board is mirrored.
|
||||
extern PieceSquare mir_piece(PieceSquare p);
|
||||
|
||||
|
||||
// callback called when initializing mir_piece/inv_piece
|
||||
@@ -35,8 +35,8 @@ namespace Eval
|
||||
// At the timing when mir_piece_init_function is called, until fe_old_end
|
||||
// It is guaranteed that these tables have been initialized.
|
||||
extern std::function<void()> mir_piece_init_function;
|
||||
extern int16_t mir_piece_[Eval::fe_end];
|
||||
extern int16_t inv_piece_[Eval::fe_end];
|
||||
extern int16_t mir_piece_[PieceSquare::PS_END];
|
||||
extern int16_t inv_piece_[PieceSquare::PS_END];
|
||||
|
||||
// The table above will be initialized when you call this function explicitly or call init().
|
||||
extern void init_mir_inv_tables();
|
||||
|
||||
Reference in New Issue
Block a user