X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=src%2Fendgame.cpp;h=c8be21983dd7064a7a06c1ce66d04c420d4d3a96;hb=485d517c687a2d3cb0b88cc8c198483759eaf2c7;hp=66ee54d846044c90d03ec4dcaf9699e07aae13ee;hpb=96ac85b3196ed7369a91a0852da0adcaf05a04b3;p=stockfish
diff --git a/src/endgame.cpp b/src/endgame.cpp
index 66ee54d8..c8be2198 100644
--- a/src/endgame.cpp
+++ b/src/endgame.cpp
@@ -1,8 +1,6 @@
/*
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
- Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
- Copyright (C) 2008-2015 Marco Costalba, Joona Kiiski, Tord Romstad
- Copyright (C) 2015-2019 Marco Costalba, Joona Kiiski, Gary Linscott, Tord Romstad
+ 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
@@ -18,49 +16,31 @@
along with this program. If not, see .
*/
-#include
#include
#include "bitboard.h"
#include "endgame.h"
#include "movegen.h"
-using std::string;
-
namespace {
- // Table used to drive the king towards the edge of the board
+ // Used to drive the king towards the edge of the board
// in KX vs K and KQ vs KR endgames.
- constexpr int PushToEdges[SQUARE_NB] = {
- 100, 90, 80, 70, 70, 80, 90, 100,
- 90, 70, 60, 50, 50, 60, 70, 90,
- 80, 60, 40, 30, 30, 40, 60, 80,
- 70, 50, 30, 20, 20, 30, 50, 70,
- 70, 50, 30, 20, 20, 30, 50, 70,
- 80, 60, 40, 30, 30, 40, 60, 80,
- 90, 70, 60, 50, 50, 60, 70, 90,
- 100, 90, 80, 70, 70, 80, 90, 100
- };
-
- // Table used to drive the king towards a corner square of the
- // right color in KBN vs K endgames.
- constexpr int PushToCorners[SQUARE_NB] = {
- 6400, 6080, 5760, 5440, 5120, 4800, 4480, 4160,
- 6080, 5760, 5440, 5120, 4800, 4480, 4160, 4480,
- 5760, 5440, 4960, 4480, 4480, 4000, 4480, 4800,
- 5440, 5120, 4480, 3840, 3520, 4480, 4800, 5120,
- 5120, 4800, 4480, 3520, 3840, 4480, 5120, 5440,
- 4800, 4480, 4000, 4480, 4480, 4960, 5440, 5760,
- 4480, 4160, 4480, 4800, 5120, 5440, 5760, 6080,
- 4160, 4480, 4800, 5120, 5440, 5760, 6080, 6400
- };
-
- // Tables used to drive a piece towards or away from another piece
- constexpr int PushClose[8] = { 0, 0, 100, 80, 60, 40, 20, 10 };
- constexpr int PushAway [8] = { 0, 5, 20, 40, 60, 80, 90, 100 };
-
- // Pawn Rank based scaling factors used in KRPPKRP endgame
- constexpr int KRPPKRPScaleFactors[RANK_NB] = { 0, 9, 10, 14, 21, 44, 0, 0 };
+ // Values range from 27 (center squares) to 90 (in the corners)
+ inline int push_to_edge(Square s) {
+ int rd = edge_distance(rank_of(s)), fd = edge_distance(file_of(s));
+ return 90 - (7 * fd * fd / 2 + 7 * rd * rd / 2);
+ }
+
+ // Used to drive the king towards A1H8 corners in KBN vs K endgames.
+ // Values range from 0 on A8H1 diagonal to 7 in A1H8 corners
+ inline int push_to_corner(Square s) {
+ return abs(7 - rank_of(s) - file_of(s));
+ }
+
+ // Drive a piece close to or away from another piece
+ inline int push_close(Square s1, Square s2) { return 140 - 20 * distance(s1, s2); }
+ inline int push_away(Square s1, Square s2) { return 120 - push_close(s1, s2); }
#ifndef NDEBUG
bool verify_material(const Position& pos, Color c, Value npm, int pawnsCnt) {
@@ -75,17 +55,40 @@ namespace {
assert(pos.count(strongSide) == 1);
if (file_of(pos.square(strongSide)) >= FILE_E)
- sq = Square(sq ^ 7); // Mirror SQ_H1 -> SQ_A1
-
- if (strongSide == BLACK)
- sq = ~sq;
+ sq = flip_file(sq);
- return sq;
+ return strongSide == WHITE ? sq : flip_rank(sq);
}
} // namespace
+namespace Endgames {
+
+ std::pair