From 58539c476ab49e4db2af46309768040c4c66af9a Mon Sep 17 00:00:00 2001 From: Fabian Fichter Date: Tue, 31 Mar 2020 20:04:09 +0200 Subject: [PATCH] Always allow passing in Janggi Closes #91. --- src/movegen.cpp | 2 +- src/parser.cpp | 3 ++- src/position.cpp | 9 +++++---- src/position.h | 12 +++++++++--- src/variant.cpp | 2 +- src/variant.h | 3 ++- src/variants.ini | 3 ++- tests/perft.sh | 4 ++-- 8 files changed, 24 insertions(+), 14 deletions(-) diff --git a/src/movegen.cpp b/src/movegen.cpp index 200d30a..61fb28b 100644 --- a/src/movegen.cpp +++ b/src/movegen.cpp @@ -347,7 +347,7 @@ namespace { moveList = make_move_and_gating(pos, moveList, Us, ksq, pop_lsb(&b)); // Passing move by king - if (pos.pass_on_stalemate()) + if (pos.king_pass()) *moveList++ = make(ksq, ksq); if (Type != CAPTURES && pos.can_castle(CastlingRights(OO | OOO))) diff --git a/src/parser.cpp b/src/parser.cpp index b8b9ebd..e638eac 100644 --- a/src/parser.cpp +++ b/src/parser.cpp @@ -242,7 +242,8 @@ Variant* VariantParser::parse(Variant* v) { parse_attribute("seirawanGating", v->seirawanGating); parse_attribute("cambodianMoves", v->cambodianMoves); parse_attribute("diagonalLines", v->diagonalLines); - parse_attribute("passOnStalemate", v->passOnStalemate); + parse_attribute("kingPass", v->kingPass); + parse_attribute("kingPassOnStalemate", v->kingPassOnStalemate); parse_attribute("makpongRule", v->makpongRule); parse_attribute("flyingGeneral", v->flyingGeneral); parse_attribute("xiangqiSoldier", v->xiangqiSoldier); diff --git a/src/position.cpp b/src/position.cpp index ab44621..bbf361a 100644 --- a/src/position.cpp +++ b/src/position.cpp @@ -873,8 +873,8 @@ bool Position::legal(Move m) const { if (immobility_illegal() && (type_of(m) == DROP || type_of(m) == NORMAL) && !(moves_bb(us, type_of(moved_piece(m)), to, 0) & board_bb())) return false; - // Illegal passing move - if (pass_on_stalemate() && type_of(m) == SPECIAL && from == to && !checkers()) + // Illegal king passing move + if (king_pass_on_stalemate() && type_of(m) == SPECIAL && from == to && !checkers()) { for (const auto& move : MoveList(*this)) if (!(type_of(move) == SPECIAL && from == to) && legal(move)) @@ -1195,7 +1195,7 @@ void Position::do_move(Move m, StateInfo& newSt, bool givesCheck) { Piece captured = type_of(m) == ENPASSANT ? make_piece(them, PAWN) : piece_on(to); if (to == from) { - assert((type_of(m) == PROMOTION && sittuyin_promotion()) || (type_of(m) == SPECIAL && pass_on_stalemate())); + assert((type_of(m) == PROMOTION && sittuyin_promotion()) || (type_of(m) == SPECIAL && king_pass())); captured = NO_PIECE; } st->capturedpromoted = is_promoted(to); @@ -1478,7 +1478,8 @@ void Position::undo_move(Move m) { Piece pc = piece_on(to); assert(type_of(m) == DROP || empty(from) || type_of(m) == CASTLING || is_gating(m) - || (type_of(m) == PROMOTION && sittuyin_promotion()) || (type_of(m) == SPECIAL && pass_on_stalemate())); + || (type_of(m) == PROMOTION && sittuyin_promotion()) + || (type_of(m) == SPECIAL && king_pass())); assert(type_of(st->capturedPiece) != KING); // Remove gated piece diff --git a/src/position.h b/src/position.h index b458136..ead5799 100644 --- a/src/position.h +++ b/src/position.h @@ -142,7 +142,8 @@ public: bool seirawan_gating() const; bool cambodian_moves() const; Bitboard diagonal_lines() const; - bool pass_on_stalemate() const; + bool king_pass() const; + bool king_pass_on_stalemate() const; bool unpromoted_soldier(Color c, Square s) const; bool makpong() const; // winning conditions @@ -578,9 +579,14 @@ inline Bitboard Position::diagonal_lines() const { return var->diagonalLines; } -inline bool Position::pass_on_stalemate() const { +inline bool Position::king_pass() const { assert(var != nullptr); - return var->passOnStalemate; + return var->kingPass || var->kingPassOnStalemate; +} + +inline bool Position::king_pass_on_stalemate() const { + assert(var != nullptr); + return var->kingPassOnStalemate; } inline bool Position::unpromoted_soldier(Color c, Square s) const { diff --git a/src/variant.cpp b/src/variant.cpp index c1fe12e..d581ac4 100644 --- a/src/variant.cpp +++ b/src/variant.cpp @@ -874,7 +874,7 @@ namespace { v->bikjangRule = true; v->diagonalLines = make_bitboard(SQ_D1, SQ_F1, SQ_E2, SQ_D3, SQ_F3, SQ_D8, SQ_F8, SQ_E9, SQ_D10, SQ_F10); - v->passOnStalemate = true; + v->kingPass = true; v->nFoldValue = -VALUE_MATE; v->perpetualCheckIllegal = true; return v; diff --git a/src/variant.h b/src/variant.h index 682d38e..4f0b3db 100644 --- a/src/variant.h +++ b/src/variant.h @@ -87,7 +87,8 @@ struct Variant { bool seirawanGating = false; bool cambodianMoves = false; Bitboard diagonalLines = 0; - bool passOnStalemate = false; + bool kingPass = false; + bool kingPassOnStalemate = false; bool makpongRule = false; bool flyingGeneral = false; bool xiangqiSoldier = false; diff --git a/src/variants.ini b/src/variants.ini index f481323..a5ae214 100644 --- a/src/variants.ini +++ b/src/variants.ini @@ -146,7 +146,8 @@ # seirawanGating: allow gating of pieces in hand like in S-Chess, requires "gating = true" [bool] (default: false) # cambodianMoves: enable special moves of cambodian chess, requires "gating = true" [bool] (default: false) # diagonalLines: enable special moves along diagonal for specific squares (Janggi) [Bitboard] -# passOnStalemate: allow passing by king in case of stalemate [bool] (default: false) +# kingPass: allow passing by king [bool] (default: false) +# kingPassOnStalemate: allow passing by king in case of stalemate [bool] (default: false) # makpongRule: the king may not move away from check [bool] (default: false) # flyingGeneral: disallow general face-off like in xiangqi [bool] (default: false) # xiangqiSoldier: restrict soldier to shogi pawn movements on first five ranks [bool] (default: false) diff --git a/tests/perft.sh b/tests/perft.sh index 59f21e4..706c823 100755 --- a/tests/perft.sh +++ b/tests/perft.sh @@ -74,8 +74,8 @@ if [[ $1 == "largeboard" ]]; then expect perft.exp courier startpos 4 500337 > /dev/null expect perft.exp grand startpos 3 259514 > /dev/null expect perft.exp xiangqi startpos 4 3290240 > /dev/null - expect perft.exp janggi startpos 4 948468 > /dev/null - expect perft.exp janggi "fen 1n1kaabn1/cr2N4/5C1c1/p1pNp3p/9/9/P1PbP1P1P/3r1p3/4A4/R1BA1KB1R b - - 0 1" 4 70256 > /dev/null + expect perft.exp janggi startpos 4 1075083 > /dev/null + expect perft.exp janggi "fen 1n1kaabn1/cr2N4/5C1c1/p1pNp3p/9/9/P1PbP1P1P/3r1p3/4A4/R1BA1KB1R b - - 0 1" 4 76826 > /dev/null fi rm perft.exp -- 1.7.0.4