Skip to content

Commit

Permalink
Support microshogi
Browse files Browse the repository at this point in the history
https://en.wikipedia.org/wiki/Micro_shogi

No functional change for other variants.
  • Loading branch information
ianfab committed Feb 17, 2019
1 parent 92e35e6 commit 0db865d
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 2 deletions.
9 changes: 8 additions & 1 deletion src/movegen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,14 @@ namespace {
{
Bitboard promotion_zone = promotion_zone_bb(us, pos.promotion_rank(), pos.max_rank());
if (pos.mandatory_piece_promotion())
b1 &= promotion_zone & from ? 0 : ~promotion_zone;
b1 &= (promotion_zone & from ? 0 : ~promotion_zone) | (pos.piece_promotion_on_capture() ? ~pos.pieces() : 0);
// Exclude quiet promotions/demotions
if (pos.piece_promotion_on_capture())
{
b2 &= pos.pieces();
b3 &= pos.pieces();
}
// Consider promotions/demotions into promotion zone
if (!(promotion_zone & from))
{
b2 &= promotion_zone;
Expand Down
3 changes: 2 additions & 1 deletion src/position.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -836,7 +836,8 @@ bool Position::pseudo_legal(const Move m) const {
// Handle the case where a mandatory piece promotion/demotion is not taken
if ( mandatory_piece_promotion()
&& (is_promoted(from) ? piece_demotion() : promoted_piece_type(type_of(pc)) != NO_PIECE_TYPE)
&& (promotion_zone_bb(us, promotion_rank(), max_rank()) & (SquareBB[from] | to)))
&& ( (promotion_zone_bb(us, promotion_rank(), max_rank()) & (SquareBB[from] | to))
|| (piece_promotion_on_capture() && !capture(m))))
return false;

// Is not a promotion, so promotion piece must be empty
Expand Down
6 changes: 6 additions & 0 deletions src/position.h
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ class Position {
const std::set<PieceType, std::greater<PieceType> >& promotion_piece_types() const;
bool sittuyin_promotion() const;
PieceType promoted_piece_type(PieceType pt) const;
bool piece_promotion_on_capture() const;
bool mandatory_piece_promotion() const;
bool piece_demotion() const;
bool endgame_eval() const;
Expand Down Expand Up @@ -332,6 +333,11 @@ inline PieceType Position::promoted_piece_type(PieceType pt) const {
return var->promotedPieceType[pt];
}

inline bool Position::piece_promotion_on_capture() const {
assert(var != nullptr);
return var->piecePromotionOnCapture;
}

inline bool Position::mandatory_piece_promotion() const {
assert(var != nullptr);
return var->mandatoryPiecePromotion;
Expand Down
16 changes: 16 additions & 0 deletions src/variant.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,21 @@ VariantMap variants; // Global object
v->shogiDoubledPawn = true;
return v;
}
Variant* microshogi_variant() {
Variant* v = kyotoshogi_variant();
v->maxFile = FILE_D;
v->startFen = "kb+r+l/p3/4/3P/+L+RBK[-] w 0 1";
v->promotionRank = RANK_1;
v->piecePromotionOnCapture = true;
v->promotedPieceType[LANCE] = SILVER;
v->promotedPieceType[BISHOP] = GOLD;
v->promotedPieceType[ROOK] = GOLD;
v->promotedPieceType[SHOGI_PAWN] = SHOGI_KNIGHT;
v->promotedPieceType[SILVER] = NO_PIECE_TYPE;
v->promotedPieceType[GOLD] = NO_PIECE_TYPE;
v->promotedPieceType[SHOGI_KNIGHT] = NO_PIECE_TYPE;
return v;
}
Variant* dobutsu_variant() {
Variant* v = minishogi_variant_base();
v->maxRank = RANK_4;
Expand Down Expand Up @@ -580,6 +595,7 @@ void VariantMap::init() {
add("minishogi", minishogi_variant());
add("mini", minishogi_variant());
add("kyotoshogi", kyotoshogi_variant());
add("micro", microshogi_variant());
add("dobutsu", dobutsu_variant());
add("gorogoro", gorogoroshogi_variant());
add("judkins", judkinsshogi_variant());
Expand Down
1 change: 1 addition & 0 deletions src/variant.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ struct Variant {
std::set<PieceType, std::greater<PieceType> > promotionPieceTypes = { QUEEN, ROOK, BISHOP, KNIGHT };
bool sittuyinPromotion = false;
PieceType promotedPieceType[PIECE_TYPE_NB] = {};
bool piecePromotionOnCapture = false;
bool mandatoryPiecePromotion = false;
bool pieceDemotion = false;
bool endgameEval = false;
Expand Down

0 comments on commit 0db865d

Please sign in to comment.