Skip to content

Commit 5a7b45e

Browse files
protonspringvondele
authored andcommitted
Use equations for PushAway and PushClose
A functional simplification replacing the corresponding arrays. Tested in two variants, also the simpler one performs well, even though differences to master should be minimal. STC LLR: 2.95 (-2.94,2.94) {-1.50,0.50} Total: 57864 W: 11092 L: 11001 D: 35771 Ptnml(0-2): 826, 6458, 14320, 6455, 873 http://tests.stockfishchess.org/tests/view/5e5da5b6e42a5c3b3ca2e05c LTC LLR: 2.95 (-2.94,2.94) {-1.50,0.50} Total: 7198 W: 982 L: 883 D: 5333 Ptnml(0-2): 33, 575, 2296, 650, 45 http://tests.stockfishchess.org/tests/view/5e5df13ae42a5c3b3ca2e077 LTC (This exact version. . . more simplified) LLR: 2.95 (-2.94,2.94) {-1.50,0.50} Total: 5392 W: 729 L: 631 D: 4032 Ptnml(0-2): 23, 405, 1751, 485, 32 http://tests.stockfishchess.org/tests/view/5e5ead99e42a5c3b3ca2e0e4 closes #2570 Bench 5123316
1 parent 960d59d commit 5a7b45e

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

src/endgame.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,9 @@ namespace {
5454
4160, 4480, 4800, 5120, 5440, 5760, 6080, 6400
5555
};
5656

57-
// Tables used to drive a piece towards or away from another piece
58-
constexpr int PushClose[8] = { 0, 0, 100, 80, 60, 40, 20, 10 };
59-
constexpr int PushAway [8] = { 0, 5, 20, 40, 60, 80, 90, 100 };
57+
// Drive a piece close to or away from another piece
58+
inline int push_close(Square s1, Square s2) { return 140 - 20 * distance(s1, s2); }
59+
inline int push_away(Square s1, Square s2) { return 120 - push_close(s1, s2); }
6060

6161
// Pawn Rank based scaling factors used in KRPPKRP endgame
6262
constexpr int KRPPKRPScaleFactors[RANK_NB] = { 0, 9, 10, 14, 21, 44, 0, 0 };
@@ -130,7 +130,7 @@ Value Endgame<KXK>::operator()(const Position& pos) const {
130130
Value result = pos.non_pawn_material(strongSide)
131131
+ pos.count<PAWN>(strongSide) * PawnValueEg
132132
+ PushToEdges[loserKSq]
133-
+ PushClose[distance(winnerKSq, loserKSq)];
133+
+ push_close(winnerKSq, loserKSq);
134134

135135
if ( pos.count<QUEEN>(strongSide)
136136
|| pos.count<ROOK>(strongSide)
@@ -159,7 +159,7 @@ Value Endgame<KBNK>::operator()(const Position& pos) const {
159159
// to drive to opposite corners (A8/H1).
160160

161161
Value result = VALUE_KNOWN_WIN
162-
+ PushClose[distance(winnerKSq, loserKSq)]
162+
+ push_close(winnerKSq, loserKSq)
163163
+ PushToCorners[opposite_colors(bishopSq, SQ_A1) ? ~loserKSq : loserKSq];
164164

165165
assert(abs(result) < VALUE_TB_WIN_IN_MAX_PLY);
@@ -258,7 +258,7 @@ Value Endgame<KRKN>::operator()(const Position& pos) const {
258258

259259
Square bksq = pos.square<KING>(weakSide);
260260
Square bnsq = pos.square<KNIGHT>(weakSide);
261-
Value result = Value(PushToEdges[bksq] + PushAway[distance(bksq, bnsq)]);
261+
Value result = Value(PushToEdges[bksq] + push_away(bksq, bnsq));
262262
return strongSide == pos.side_to_move() ? result : -result;
263263
}
264264

@@ -277,7 +277,7 @@ Value Endgame<KQKP>::operator()(const Position& pos) const {
277277
Square loserKSq = pos.square<KING>(weakSide);
278278
Square pawnSq = pos.square<PAWN>(weakSide);
279279

280-
Value result = Value(PushClose[distance(winnerKSq, loserKSq)]);
280+
Value result = Value(push_close(winnerKSq, loserKSq));
281281

282282
if ( relative_rank(weakSide, pawnSq) != RANK_7
283283
|| distance(loserKSq, pawnSq) != 1
@@ -304,7 +304,7 @@ Value Endgame<KQKR>::operator()(const Position& pos) const {
304304
Value result = QueenValueEg
305305
- RookValueEg
306306
+ PushToEdges[loserKSq]
307-
+ PushClose[distance(winnerKSq, loserKSq)];
307+
+ push_close(winnerKSq, loserKSq);
308308

309309
return strongSide == pos.side_to_move() ? result : -result;
310310
}

0 commit comments

Comments
 (0)