From bb5e26ce0318b0637a075255e9d30e0b7c441bbd Mon Sep 17 00:00:00 2001 From: Fabian Fichter Date: Fri, 5 Mar 2021 16:33:16 +0100 Subject: [PATCH] Generalize doubled pawn drop setting Allow to prohibit dropping a doubled piece of any type, not only restricted to shogi pawns. Closes #266. --- src/evaluate.cpp | 5 +++-- src/parser.cpp | 4 ++-- src/position.h | 8 ++++---- src/ucioption.cpp | 2 +- src/variant.cpp | 6 +++--- src/variant.h | 2 +- src/variants.ini | 4 ++-- 7 files changed, 16 insertions(+), 15 deletions(-) diff --git a/src/evaluate.cpp b/src/evaluate.cpp index 808418f..4262504 100644 --- a/src/evaluate.cpp +++ b/src/evaluate.cpp @@ -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; diff --git a/src/parser.cpp b/src/parser.cpp index bba3654..dbe3847 100644 --- a/src/parser.cpp +++ b/src/parser.cpp @@ -141,7 +141,7 @@ void VariantParser::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::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); diff --git a/src/position.h b/src/position.h index 8fa03e0..59df07a 100644 --- a/src/position.h +++ b/src/position.h @@ -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 { diff --git a/src/ucioption.cpp b/src/ucioption.cpp index c09b609..d75c7fd 100644 --- a/src/ucioption.cpp +++ b/src/ucioption.cpp @@ -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"; diff --git a/src/variant.cpp b/src/variant.cpp index 80de6a0..9d2e52e 100644 --- a/src/variant.cpp +++ b/src/variant.cpp @@ -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() { diff --git a/src/variant.h b/src/variant.h index d8586dd..0dd36a3 100644 --- a/src/variant.h +++ b/src/variant.h @@ -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; diff --git a/src/variants.ini b/src/variants.ini index d51171e..d6a2d1f 100644 --- a/src/variants.ini +++ b/src/variants.ini @@ -152,7 +152,7 @@ # 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) @@ -214,7 +214,7 @@ # doubleStep = false # castling = false # promotedPieceType = p:g s:g b:h r:d -# shogiDoubledPawn = false +# dropNoDoubled = p # immobilityIllegal = true # shogiPawnDropMateIllegal = true # stalemateValue = loss -- 1.7.0.4