Always allow passing in Janggi
authorFabian Fichter <ianfab@users.noreply.github.com>
Tue, 31 Mar 2020 18:04:09 +0000 (20:04 +0200)
committerFabian Fichter <ianfab@users.noreply.github.com>
Tue, 31 Mar 2020 18:04:09 +0000 (20:04 +0200)
Closes #91.

src/movegen.cpp
src/parser.cpp
src/position.cpp
src/position.h
src/variant.cpp
src/variant.h
src/variants.ini
tests/perft.sh

index 200d30a..61fb28b 100644 (file)
@@ -347,7 +347,7 @@ namespace {
             moveList = make_move_and_gating<NORMAL>(pos, moveList, Us, ksq, pop_lsb(&b));
 
         // Passing move by king
-        if (pos.pass_on_stalemate())
+        if (pos.king_pass())
             *moveList++ = make<SPECIAL>(ksq, ksq);
 
         if (Type != CAPTURES && pos.can_castle(CastlingRights(OO | OOO)))
index b8b9ebd..e638eac 100644 (file)
@@ -242,7 +242,8 @@ Variant* VariantParser<DoCheck>::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);
index ab44621..bbf361a 100644 (file)
@@ -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<NON_EVASIONS>(*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
index b458136..ead5799 100644 (file)
@@ -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 {
index c1fe12e..d581ac4 100644 (file)
@@ -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;
index 682d38e..4f0b3db 100644 (file)
@@ -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;
index f481323..a5ae214 100644 (file)
 # 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)
index 59f21e4..706c823 100755 (executable)
@@ -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