Full Winboard compatibility for Janggi
authorFabian Fichter <ianfab@users.noreply.github.com>
Sat, 16 May 2020 13:57:58 +0000 (15:57 +0200)
committerFabian Fichter <ianfab@users.noreply.github.com>
Sat, 16 May 2020 14:37:37 +0000 (16:37 +0200)
* Adapt to Winboard's handling of passing moves
* Replace piece image for soldier to avoid promotion issues

src/variant.cpp
src/xboard.cpp

index 621cfe0..d5c471c 100644 (file)
@@ -854,7 +854,7 @@ namespace {
     // https://en.wikipedia.org/wiki/Janggi
     Variant* janggi_variant() {
         Variant* v = xiangqi_variant();
-        v->pieceToCharTable = "PN.R.AB....C.........Kpn.r.ab....c.........k";
+        v->pieceToCharTable = ".N.R.AB.P..C.........K.n.r.ab.p..c.........k";
         v->remove_piece(FERS);
         v->remove_piece(CANNON);
         v->remove_piece(ELEPHANT);
index f37f349..e8adfb7 100644 (file)
@@ -236,7 +236,29 @@ void StateMachine::process_command(Position& pos, std::string token, std::istrin
   {
       std::string fen;
       std::getline(is >> std::ws, fen);
-      setboard(pos, states, fen);
+      // Check if setboard actually indicates a passing move
+      // to avoid unnecessarily clearing the move history
+      if (pos.king_pass())
+      {
+          StateInfo st;
+          Position p;
+          p.set(pos.variant(), fen, pos.is_chess960(), &st, pos.this_thread());
+          Move m;
+          std::string passMove = "pass";
+          if ((m = UCI::to_move(pos, passMove)) != MOVE_NONE)
+              do_move(pos, moveList, states, m);
+          // apply setboard if passing does not lead to a match
+          if (pos.key() != p.key())
+              setboard(pos, states, fen);
+      }
+      else
+          setboard(pos, states, fen);
+      // Winboard sends setboard after passing moves
+      if (pos.side_to_move() == playColor)
+      {
+          go(pos, limits, states);
+          moveAfterSearch = true;
+      }
   }
   else if (token == "cores")
   {