Generalize doubled pawn drop setting
authorFabian Fichter <ianfab@users.noreply.github.com>
Fri, 5 Mar 2021 15:33:16 +0000 (16:33 +0100)
committerFabian Fichter <ianfab@users.noreply.github.com>
Fri, 5 Mar 2021 15:33:16 +0000 (16:33 +0100)
Allow to prohibit dropping a doubled piece of any type,
not only restricted to shogi pawns.

Closes #266.

src/evaluate.cpp
src/parser.cpp
src/position.h
src/ucioption.cpp
src/variant.cpp
src/variant.h
src/variants.ini

index 808418f..4262504 100644 (file)
@@ -646,8 +646,9 @@ namespace {
         if (pos.seirawan_gating() && !pos.piece_drops() && pos.count_in_hand(Us, ALL_PIECES) > popcount(pos.gates(Us)))
             score -= make_score(200, 900) / pos.count_in_hand(Us, ALL_PIECES) * (pos.count_in_hand(Us, ALL_PIECES) - popcount(pos.gates(Us)));
 
-        if (pt == SHOGI_PAWN && !pos.shogi_doubled_pawn())
-            score -= make_score(50, 20) * std::max(pos.count_with_hand(Us, SHOGI_PAWN) - pos.max_file() - 1, 0);
+        // Redundant pieces that can not be doubled per file (e.g., shogi pawns)
+        if (pt == pos.drop_no_doubled())
+            score -= make_score(50, 20) * std::max(pos.count_with_hand(Us, pt) - pos.max_file() - 1, 0);
     }
 
     return score;
index bba3654..dbe3847 100644 (file)
@@ -141,7 +141,7 @@ void VariantParser<DoCheck>::parse_attribute(const std::string& key, PieceType&
         char token;
         size_t idx;
         std::stringstream ss(it->second);
-        if (ss >> token && (idx = pieceToChar.find(toupper(token))) != std::string::npos)
+        if (ss >> token && (idx = token == '-' ? 0 : pieceToChar.find(toupper(token))) != std::string::npos)
             target = PieceType(idx);
         else if (DoCheck)
             std::cerr << key << " - Invalid piece type: " << token << std::endl;
@@ -270,7 +270,7 @@ Variant* VariantParser<DoCheck>::parse(Variant* v) {
     parse_attribute("sittuyinRookDrop", v->sittuyinRookDrop);
     parse_attribute("dropOppositeColoredBishop", v->dropOppositeColoredBishop);
     parse_attribute("dropPromoted", v->dropPromoted);
-    parse_attribute("shogiDoubledPawn", v->shogiDoubledPawn);
+    parse_attribute("dropNoDoubled", v->dropNoDoubled, v->pieceToChar);
     parse_attribute("immobilityIllegal", v->immobilityIllegal);
     parse_attribute("gating", v->gating);
     parse_attribute("arrowGating", v->arrowGating);
index 8fa03e0..59df07a 100644 (file)
@@ -159,7 +159,7 @@ public:
   bool sittuyin_rook_drop() const;
   bool drop_opposite_colored_bishop() const;
   bool drop_promoted() const;
-  bool shogi_doubled_pawn() const;
+  PieceType drop_no_doubled() const;
   bool immobility_illegal() const;
   bool gating() const;
   bool arrow_gating() const;
@@ -604,7 +604,7 @@ inline Bitboard Position::drop_region(Color c, PieceType pt) const {
           b &= ~rank_bb(relative_rank(c, RANK_1, max_rank()));
   }
   // Doubled shogi pawns
-  if (pt == SHOGI_PAWN && !shogi_doubled_pawn())
+  if (pt == drop_no_doubled())
       for (File f = FILE_A; f <= max_file(); ++f)
           if (file_bb(f) & pieces(c, pt))
               b &= ~file_bb(f);
@@ -665,9 +665,9 @@ inline bool Position::drop_promoted() const {
   return var->dropPromoted;
 }
 
-inline bool Position::shogi_doubled_pawn() const {
+inline PieceType Position::drop_no_doubled() const {
   assert(var != nullptr);
-  return var->shogiDoubledPawn;
+  return var->dropNoDoubled;
 }
 
 inline bool Position::immobility_illegal() const {
index c09b609..d75c7fd 100644 (file)
@@ -119,7 +119,7 @@ void on_variant_change(const Option &o) {
             {
                 if (pt == PAWN && !v->firstRankPawnDrops)
                     suffix += "j";
-                else if (pt == SHOGI_PAWN && !v->shogiDoubledPawn)
+                else if (pt == v->dropNoDoubled)
                     suffix += "f";
                 else if (pt == BISHOP && v->dropOppositeColoredBishop)
                     suffix += "s";
index 80de6a0..9d2e52e 100644 (file)
@@ -451,7 +451,7 @@ namespace {
         v->promotedPieceType[SILVER]     = GOLD;
         v->promotedPieceType[BISHOP]     = DRAGON_HORSE;
         v->promotedPieceType[ROOK]       = DRAGON;
-        v->shogiDoubledPawn = false;
+        v->dropNoDoubled = SHOGI_PAWN;
         v->immobilityIllegal = true;
         v->shogiPawnDropMateIllegal = true;
         v->stalemateValue = -VALUE_MATE;
@@ -486,7 +486,7 @@ namespace {
         v->promotedPieceType[ROOK]         = NO_PIECE_TYPE;
         v->immobilityIllegal = false;
         v->shogiPawnDropMateIllegal = false;
-        v->shogiDoubledPawn = true;
+        v->dropNoDoubled = NO_PIECE_TYPE;
         return v;
     }
     Variant* microshogi_variant() {
@@ -523,7 +523,7 @@ namespace {
         v->flagPiece = KING;
         v->whiteFlag = Rank4BB;
         v->blackFlag = Rank1BB;
-        v->shogiDoubledPawn = true;
+        v->dropNoDoubled = NO_PIECE_TYPE;
         return v;
     }
     Variant* gorogoroshogi_variant() {
index d8586dd..0dd36a3 100644 (file)
@@ -87,7 +87,7 @@ struct Variant {
   bool sittuyinRookDrop = false;
   bool dropOppositeColoredBishop = false;
   bool dropPromoted = false;
-  bool shogiDoubledPawn = true;
+  PieceType dropNoDoubled = NO_PIECE_TYPE;
   bool immobilityIllegal = false;
   bool gating = false;
   bool arrowGating = false;
index d51171e..d6a2d1f 100644 (file)
 # sittuyinRookDrop: restrict region of rook drops to first rank [bool] (default: false)
 # dropOppositeColoredBishop: dropped bishops have to be on opposite-colored squares [bool] (default: false)
 # dropPromoted: pieces may be dropped in promoted state [bool] (default: false)
-# shogiDoubledPawn: allow shogi pawns to be doubled [bool] (default: true)
+# dropNoDoubled: specified piece type can not be dropped to the same file (e.g. shogi pawn) [PieceType] (default: -)
 # immobilityIllegal: pieces may not move to squares where they can never move from [bool] (default: false)
 # gating: maintain squares on backrank with extra rights in castling field of FEN [bool] (default: false)
 # arrowGating: allow gating in Game of the Amazons style [bool] (default: false)
 # doubleStep = false
 # castling = false
 # promotedPieceType = p:g s:g b:h r:d
-# shogiDoubledPawn = false
+# dropNoDoubled = p
 # immobilityIllegal = true
 # shogiPawnDropMateIllegal = true
 # stalemateValue = loss