5454
5555
5656using namespace std ;
57- using namespace Stockfish ::Eval::NNUE;
5857
5958namespace Stockfish {
6059
@@ -396,7 +395,8 @@ namespace {
396395
397396 attackedBy[Us][Pt] = 0 ;
398397
399- while (b1) {
398+ while (b1)
399+ {
400400 Square s = pop_lsb (b1);
401401
402402 // Find attacked squares, including x-ray attacks for bishops and rooks
@@ -1038,46 +1038,51 @@ namespace {
10381038 return v;
10391039 }
10401040
1041- // specifically correct for cornered bishops to fix FRC with NNUE.
1041+
1042+ // / Fisher Random Chess: correction for cornered bishops, to fix chess960 play with NNUE
1043+
10421044 Value fix_FRC (const Position& pos) {
10431045
1044- Value bAdjust = Value ( 0 ) ;
1046+ constexpr Bitboard Corners = 1ULL << SQ_A1 | 1ULL << SQ_H1 | 1ULL << SQ_A8 | 1ULL << SQ_H8 ;
10451047
1046- constexpr Value p1=Value (209 ), p2=Value (136 ), p3=Value (148 );
1048+ if (!(pos.pieces (BISHOP) & Corners))
1049+ return VALUE_ZERO;
10471050
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;
1051+ constexpr int penalty1 = -209 ;
1052+ constexpr int penalty2 = -136 ;
1053+ constexpr int penalty3 = -148 ;
1054+
1055+ int correction = 0 ;
1056+
1057+ if ( pos.piece_on (SQ_A1) == W_BISHOP
1058+ && pos.piece_on (SQ_B2) == W_PAWN)
1059+ correction += !pos.empty (SQ_B3) ? penalty1
1060+ : pos.piece_on (SQ_C3) == W_PAWN ? penalty2
1061+ : penalty3;
1062+
1063+ if ( pos.piece_on (SQ_H1) == W_BISHOP
1064+ && pos.piece_on (SQ_G2) == W_PAWN)
1065+ correction += !pos.empty (SQ_G3) ? penalty1
1066+ : pos.piece_on (SQ_F3) == W_PAWN ? penalty2
1067+ : penalty3;
1068+
1069+ if ( pos.piece_on (SQ_A8) == B_BISHOP
1070+ && pos.piece_on (SQ_B7) == B_PAWN)
1071+ correction += !pos.empty (SQ_B6) ? -penalty1
1072+ : pos.piece_on (SQ_C6) == B_PAWN ? -penalty2
1073+ : -penalty3;
1074+
1075+ if ( pos.piece_on (SQ_H8) == B_BISHOP
1076+ && pos.piece_on (SQ_G7) == B_PAWN)
1077+ correction += !pos.empty (SQ_G6) ? -penalty1
1078+ : pos.piece_on (SQ_F6) == B_PAWN ? -penalty2
1079+ : -penalty3;
1080+
1081+ return pos.side_to_move () == WHITE ? Value (correction)
1082+ : -Value (correction);
10781083 }
10791084
1080- } // namespace
1085+ } // namespace Eval
10811086
10821087
10831088// / evaluate() is the evaluator for the outer world. It returns a static
@@ -1092,14 +1097,19 @@ Value Eval::evaluate(const Position& pos) {
10921097 else
10931098 {
10941099 // Scale and shift NNUE for compatibility with search and classical evaluation
1095- auto adjusted_NNUE = [&](){
1096- int mat = pos.non_pawn_material () + 2 * PawnValueMg * pos.count <PAWN>();
1097- Value nnueValue = NNUE::evaluate (pos) * (641 + mat / 32 - 4 * pos.rule50_count ()) / 1024 + Tempo;
1100+ auto adjusted_NNUE = [&]()
1101+ {
1102+ int material = pos.non_pawn_material () + 2 * PawnValueMg * pos.count <PAWN>();
1103+ int scale = 641
1104+ + material / 32
1105+ - 4 * pos.rule50_count ();
1106+
1107+ Value nnue = NNUE::evaluate (pos) * scale / 1024 + Tempo;
10981108
10991109 if (pos.is_chess960 ())
1100- nnueValue += fix_FRC (pos);
1110+ nnue += fix_FRC (pos);
11011111
1102- return nnueValue ;
1112+ return nnue ;
11031113 };
11041114
11051115 // If there is PSQ imbalance use classical eval, with small probability if it is small
0 commit comments