src/chess/rules.c

changeset 201
b61c2b90f19c
parent 195
27d02ccb0cef
--- a/src/chess/rules.c	Mon Aug 31 17:51:32 2026 +0200
+++ b/src/chess/rules.c	Mon Aug 31 17:56:17 2026 +0200
@@ -1082,6 +1082,18 @@
             move->fromfile = fileidx('e');
             move->tofile = fileidx('c');
             move->fromrank = move->torank = color == WHITE ? 0 : 7;
+        } else if (mstr[2] == '-') {
+            /* long notation pawn move with hyphen (e.g. "d4-d5") */
+            if (isfile(mstr[0]) && isrank(mstr[1]) &&
+                isfile(mstr[3]) && isrank(mstr[4])) {
+                move->piece = mkpiece(PAWN, color);
+                move->fromfile = fileidx(mstr[0]);
+                move->fromrank = rankidx(mstr[1]);
+                move->tofile = fileidx(mstr[3]);
+                move->torank = rankidx(mstr[4]);
+            } else {
+                return INVALID_MOVE_SYNTAX;
+            }
         } else {
             move->piece = getpiece(mstr[0], color);
             if (mstr[2] == 'x') {
@@ -1110,14 +1122,27 @@
             move->torank = rankidx(mstr[4]);
         }
     } else if (len == 6) {
-        /* long notation capture (e.g. "Nc5xf3") */
         if (mstr[3] == 'x') {
+            /* long notation capture (e.g. "Nc5xf3") */
             move->capture = true;
             move->piece = getpiece(mstr[0], color);
             move->fromfile = fileidx(mstr[1]);
             move->fromrank = rankidx(mstr[2]);
             move->tofile = fileidx(mstr[4]);
             move->torank = rankidx(mstr[5]);
+        } else if (mstr[3] == '-') {
+            /* long notation move with hyphen (e.g. "Nb1-c3") */
+            Piece p = getpiece(mstr[0], color);
+            if (p != 0 && isfile(mstr[1]) && isrank(mstr[2]) &&
+                isfile(mstr[4]) && isrank(mstr[5])) {
+                move->piece = p;
+                move->fromfile = fileidx(mstr[1]);
+                move->fromrank = rankidx(mstr[2]);
+                move->tofile = fileidx(mstr[4]);
+                move->torank = rankidx(mstr[5]);
+            } else {
+                return INVALID_MOVE_SYNTAX;
+            }
         }
     }
 

mercurial