Skip to content

Commit ace9632

Browse files
Vizvezdenecvondele
authored andcommitted
Add a specific FRC correction from classical to NNUE
our net currently is not trained on FRC games, and so doesn't know about the important pattern of a bishop that is cornered in FRC. This patch introduces a term we have in the classical evaluation for this case, and adds it to the NNUE eval. Since fishtest doesn't support FRC right now, the patch was tested locally at STC conditions, starting from the book of FRC starting positions. Score of master vs patch: 993 - 2226 - 6781 [0.438] 10000 Which corresponds to approximately 40 Elo The patch passes non-regression testing for traditional chess (where it adds one branch). passed STC: https://tests.stockfishchess.org/tests/view/604fa2532433018de7a38b67 LLR: 2.95 (-2.94,2.94) {-1.25,0.25} Total: 30560 W: 2701 L: 2636 D: 25223 Ptnml(0-2): 88, 2056, 10921, 2133, 82 passed STC also in an earlier version: https://tests.stockfishchess.org/tests/view/604f61282433018de7a38b4d closes #3398 No functional change
1 parent 5089061 commit ace9632

File tree

1 file changed

+45
-1
lines changed

1 file changed

+45
-1
lines changed

src/evaluate.cpp

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1038,6 +1038,45 @@ namespace {
10381038
return v;
10391039
}
10401040

1041+
// specifically correct for cornered bishops to fix FRC with NNUE.
1042+
Value fix_FRC(const Position& pos) {
1043+
1044+
Value bAdjust = Value(0);
1045+
1046+
constexpr Value p1=Value(209), p2=Value(136), p3=Value(148);
1047+
1048+
Color Us = pos.side_to_move();
1049+
if ( (pos.pieces(Us, BISHOP) & relative_square(Us, SQ_A1))
1050+
&& (pos.pieces(Us, PAWN) & relative_square(Us, SQ_B2)))
1051+
{
1052+
bAdjust -= !pos.empty(relative_square(Us,SQ_B3)) ? p1
1053+
: pos.piece_on(relative_square(Us,SQ_C3)) == make_piece(Us, PAWN) ? p2
1054+
: p3;
1055+
}
1056+
if ( (pos.pieces(Us, BISHOP) & relative_square(Us, SQ_H1))
1057+
&& (pos.pieces(Us, PAWN) & relative_square(Us, SQ_G2)))
1058+
{
1059+
bAdjust -= !pos.empty(relative_square(Us,SQ_G3)) ? p1
1060+
: pos.piece_on(relative_square(Us,SQ_F3)) == make_piece(Us, PAWN) ? p2
1061+
: p3;
1062+
}
1063+
if ( (pos.pieces(~Us, BISHOP) & relative_square(Us, SQ_A8))
1064+
&& (pos.pieces(~Us, PAWN) & relative_square(Us, SQ_B7)))
1065+
{
1066+
bAdjust += !pos.empty(relative_square(Us,SQ_B6)) ? p1
1067+
: pos.piece_on(relative_square(Us,SQ_C6)) == make_piece(~Us, PAWN) ? p2
1068+
: p3;
1069+
}
1070+
if ( (pos.pieces(~Us, BISHOP) & relative_square(Us, SQ_H8))
1071+
&& (pos.pieces(~Us, PAWN) & relative_square(Us, SQ_G7)))
1072+
{
1073+
bAdjust += !pos.empty(relative_square(Us,SQ_G6)) ? p1
1074+
: pos.piece_on(relative_square(Us,SQ_F6)) == make_piece(~Us, PAWN) ? p2
1075+
: p3;
1076+
}
1077+
return bAdjust;
1078+
}
1079+
10411080
} // namespace
10421081

10431082

@@ -1055,7 +1094,12 @@ Value Eval::evaluate(const Position& pos) {
10551094
// Scale and shift NNUE for compatibility with search and classical evaluation
10561095
auto adjusted_NNUE = [&](){
10571096
int mat = pos.non_pawn_material() + 2 * PawnValueMg * pos.count<PAWN>();
1058-
return NNUE::evaluate(pos) * (641 + mat / 32 - 4 * pos.rule50_count()) / 1024 + Tempo;
1097+
Value nnueValue = NNUE::evaluate(pos) * (641 + mat / 32 - 4 * pos.rule50_count()) / 1024 + Tempo;
1098+
1099+
if (pos.is_chess960())
1100+
nnueValue += fix_FRC(pos);
1101+
1102+
return nnueValue;
10591103
};
10601104

10611105
// If there is PSQ imbalance use classical eval, with small probability if it is small

0 commit comments

Comments
 (0)