Skip to content

Commit

Permalink
Merged pull request #805 with squash
Browse files Browse the repository at this point in the history
  • Loading branch information
RainRat committed Jul 5, 2024
1 parent cdf3bb2 commit 63f4854
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -629,6 +629,18 @@ Variant* VariantParser<DoCheck>::parse(Variant* v) {
if (DoCheck && (idx == std::string::npos || idx2 == std::string::npos))
std::cerr << "promotedPieceType - Invalid piece type: " << token << std::endl;
}
// priority drops
const auto& it_pr_drop = config.find("priorityDropTypes");
if (it_pr_drop != config.end())
{
char token;
size_t idx = 0;
std::stringstream ss(it_pr_drop->second);
while (ss >> token && ((idx = v->pieceToChar.find(toupper(token))) != std::string::npos))
v->isPriorityDrop[PieceType(idx)] = true;
if (DoCheck && idx == std::string::npos && token != '-')
std::cerr << "priorityDropTypes - Invalid piece type: " << token << std::endl;
}
parse_attribute("piecePromotionOnCapture", v->piecePromotionOnCapture);
parse_attribute("mandatoryPawnPromotion", v->mandatoryPawnPromotion);
parse_attribute("mandatoryPiecePromotion", v->mandatoryPiecePromotion);
Expand Down
2 changes: 2 additions & 0 deletions src/position.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1161,6 +1161,8 @@ bool Position::legal(Move m) const {
if (popcount((DarkSquares & to ? DarkSquares : ~DarkSquares) & pieces(us, BISHOP)) + 1 > (count_with_hand(us, BISHOP) + 1) / 2)
return false;
}
if (type_of(m) == DROP && (!var->isPriorityDrop[type_of(moved_piece(m))]) && priorityDropCountInHand[us] > 0)
return false;

// No legal moves from target square
if (immobility_illegal() && (type_of(m) == DROP || type_of(m) == NORMAL) && !(PseudoMoves[0][us][type_of(moved_piece(m))][to] & board_bb()))
Expand Down
3 changes: 3 additions & 0 deletions src/position.h
Original file line number Diff line number Diff line change
Expand Up @@ -392,6 +392,7 @@ class Position {
int pieceCountInPrison[COLOR_NB][PIECE_TYPE_NB];
Bitboard pawnCannotCheckZone[COLOR_NB];
PieceType committedGates[COLOR_NB][FILE_NB];
int priorityDropCountInHand[COLOR_NB];
int virtualPieces;
Bitboard promotedPieces;
void add_to_hand(Piece pc);
Expand Down Expand Up @@ -1761,13 +1762,15 @@ inline void Position::add_to_hand(Piece pc) {
if (variant()->freeDrops) return;
pieceCountInHand[color_of(pc)][type_of(pc)]++;
pieceCountInHand[color_of(pc)][ALL_PIECES]++;
priorityDropCountInHand[color_of(pc)] += var->isPriorityDrop[type_of(pc)];
psq += PSQT::psq[pc][SQ_NONE];
}

inline void Position::remove_from_hand(Piece pc) {
if (variant()->freeDrops) return;
pieceCountInHand[color_of(pc)][type_of(pc)]--;
pieceCountInHand[color_of(pc)][ALL_PIECES]--;
priorityDropCountInHand[color_of(pc)] -= var->isPriorityDrop[type_of(pc)];
psq -= PSQT::psq[pc][SQ_NONE];
}

Expand Down
1 change: 1 addition & 0 deletions src/variant.h
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ struct Variant {
bool mustCapture = false;
bool mustDrop = false;
PieceType mustDropType = ALL_PIECES;
bool isPriorityDrop[PIECE_TYPE_NB] = {};
bool pieceDrops = false;
bool dropLoop = false;
CapturingRule captureType = MOVE_OUT;
Expand Down
1 change: 1 addition & 0 deletions src/variants.ini
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,7 @@
# mustCapture: captures are mandatory (check evasion still takes precedence) [bool] (default: false)
# mustDrop: drops are mandatory (e.g., for Sittuyin setup phase) [bool] (default: false)
# mustDropType: piece type for which piece drops are mandatory [PieceType] (default: *)
# priorityDropTypes: piece types that must be dropped before dropping the other pieces [PieceType] (default: none)
# pieceDrops: enable piece drops [bool] (default: false)
# dropLoop: captures promoted pieces are not demoted [bool] (default: false)
# captureType: captured pieces are removed or go to hand or prison [CapturingRule] (default: out)
Expand Down

0 comments on commit 63f4854

Please sign in to comment.