Add KRKS endgame evaluation
authorFabian Fichter <ianfab@users.noreply.github.com>
Fri, 5 Jun 2020 09:51:12 +0000 (11:51 +0200)
committerFabian Fichter <ianfab@users.noreply.github.com>
Fri, 5 Jun 2020 09:51:12 +0000 (11:51 +0200)
makruk STC
LLR: 2.96 (-2.94,2.94) [0.00,10.00]
Total: 5606 W: 531 L: 449 D: 4626
http://www.variantfishtest.org:6543/tests/view/5ed3d34a6e23db36d55f2ce0

src/endgame.cpp
src/endgame.h

index 5bc23c2..b470161 100644 (file)
@@ -124,6 +124,7 @@ namespace Endgames {
     add<KNSFKR>("KNSFKR");
     add<KSFK>("KSFK");
     add<KSFKF>("KSFKF");
+    add<KRKS>("KRKS");
 
     add<KNPK>("KNPK");
     add<KNPKB>("KNPKB");
@@ -519,6 +520,25 @@ Value Endgame<KSFKF>::operator()(const Position& pos) const {
 }
 
 
+/// KR vs KS
+template<>
+Value Endgame<KRKS>::operator()(const Position& pos) const {
+
+  assert(verify_material(pos, strongSide, RookValueMg, 0));
+  assert(verify_material(pos, weakSide, SilverValueMg, 0));
+
+  Square winnerKSq = pos.square<KING>(strongSide);
+  Square loserKSq = pos.square<KING>(weakSide);
+
+  Value result =  RookValueEg
+                - SilverValueEg
+                + PushToEdges[map_to_standard_board(pos, loserKSq)]
+                + PushClose[distance(winnerKSq, loserKSq)];
+
+  return strongSide == pos.side_to_move() ? result : -result;
+}
+
+
 /// KB and one or more pawns vs K. It checks for draws with rook pawns and
 /// a bishop of the wrong color. If such a draw is detected, SCALE_FACTOR_DRAW
 /// is returned. If not, the return value is SCALE_FACTOR_NONE, i.e. no scaling
index a0849a7..b674e3e 100644 (file)
@@ -54,6 +54,7 @@ enum EndgameCode {
   KNSFKR,  // KNSFKR vs K
   KSFK,  // KSF vs K
   KSFKF,  // KSF vs KF
+  KRKS,  // KR vs KS
 
   SCALING_FUNCTIONS,
   KBPsK,   // KB and pawns vs K