Adjust king PSQT based on pawn rank
authorFabian Fichter <ianfab@users.noreply.github.com>
Sat, 12 Sep 2020 08:49:09 +0000 (10:49 +0200)
committerFabian Fichter <ianfab@users.noreply.github.com>
Sat, 12 Sep 2020 08:49:09 +0000 (10:49 +0200)
shogi STC
LLR: 2.96 (-2.94,2.94) [0.00,10.00]
Total: 865 W: 489 L: 374 D: 2
http://www.variantfishtest.org:6543/tests/view/5f5b2c286e23db221d9e9135

shogi LTC
LLR: 2.96 (-2.94,2.94) [0.00,10.00]
Total: 1244 W: 678 L: 558 D: 8
http://www.variantfishtest.org:6543/tests/view/5f5b5cf86e23db221d9e9145

src/psqt.cpp

index 40c13c7..67b8bdb 100644 (file)
 */
 
 #include <algorithm>
+#include <sstream>
 
 #include "types.h"
 #include "bitboard.h"
 #include "piece.h"
 #include "variant.h"
+#include "misc.h"
 
 namespace PSQT {
 
@@ -177,12 +179,25 @@ void init(const Variant* v) {
           && v->extinctionPieceTypes.find(ALL_PIECES) != v->extinctionPieceTypes.end())
           score = -make_score(mg_value(score) / 8, eg_value(score) / 8 / (1 + !pi->sliderCapture.size()));
 
+      // Determine pawn rank
+      std::istringstream ss(v->startFen);
+      unsigned char token;
+      Rank rc = v->maxRank;
+      Rank pawnRank = RANK_2;
+      while ((ss >> token) && !isspace(token))
+      {
+          if (token == '/')
+              --rc;
+          else if (token == v->pieceToChar[PAWN] || token == v->pieceToChar[SHOGI_PAWN])
+              pawnRank = rc;
+      }
+
       for (Square s = SQ_A1; s <= SQ_MAX; ++s)
       {
           File f = std::max(File(edge_distance(file_of(s), v->maxFile)), FILE_A);
           Rank r = rank_of(s);
           psq[ pc][ s] = score + (  pt == PAWN  ? PBonus[std::min(r, RANK_8)][std::min(file_of(s), FILE_H)]
-                                  : pt == KING  ? KingBonus[std::min(r, RANK_8)][std::min(f, FILE_D)] * (1 + v->capturesToHand)
+                                  : pt == KING  ? KingBonus[Utility::clamp(Rank(r - pawnRank + 1), RANK_1, RANK_8)][std::min(f, FILE_D)] * (1 + v->capturesToHand)
                                   : pt <= QUEEN ? Bonus[pc][std::min(r, RANK_8)][std::min(f, FILE_D)]
                                   : pt == HORSE ? Bonus[KNIGHT][std::min(r, RANK_8)][std::min(f, FILE_D)]
                                   : isSlider    ? make_score(5, 5) * (2 * f + std::max(std::min(r, Rank(v->maxRank - r)), RANK_1) - v->maxFile - 1)