Apply promotion limit to piece promotions
authorFabian Fichter <ianfab@users.noreply.github.com>
Sun, 5 Jan 2020 22:59:03 +0000 (23:59 +0100)
committerFabian Fichter <ianfab@users.noreply.github.com>
Sun, 5 Jan 2020 22:59:03 +0000 (23:59 +0100)
Closes #61.

src/movegen.cpp
src/variant.h

index 422a91c..a12c0c0 100644 (file)
@@ -263,7 +263,8 @@ namespace {
         // Xiangqi soldier
         if (pt == SOLDIER && pos.unpromoted_soldier(us, from))
             b1 &= file_bb(file_of(from));
-        Bitboard b2 = pos.promoted_piece_type(pt) ? b1 : Bitboard(0);
+        PieceType prom_pt = pos.promoted_piece_type(pt);
+        Bitboard b2 = prom_pt && (!pos.promotion_limit(prom_pt) || pos.promotion_limit(prom_pt) > pos.count(us, prom_pt)) ? b1 : Bitboard(0);
         Bitboard b3 = pos.piece_demotion() && pos.is_promoted(from) ? b1 : Bitboard(0);
 
         if (Checks)
index e7f09fd..f1e1c80 100644 (file)
@@ -47,7 +47,7 @@ struct Variant {
   Rank promotionRank = RANK_8;
   std::set<PieceType, std::greater<PieceType> > promotionPieceTypes = { QUEEN, ROOK, BISHOP, KNIGHT };
   bool sittuyinPromotion = false;
-  uint8_t promotionLimit[PIECE_TYPE_NB] = {}; // 0 means unlimited
+  int promotionLimit[PIECE_TYPE_NB] = {}; // 0 means unlimited
   PieceType promotedPieceType[PIECE_TYPE_NB] = {};
   bool piecePromotionOnCapture = false;
   bool mandatoryPawnPromotion = true;