Seirawan gatings on castling
[capablanca.git] / lasker-2.2.3 / src / algcheck.c
index 1c1ff75..33f6b28 100644 (file)
@@ -529,12 +529,18 @@ char *alg_unparse(struct game_state_t * gs, struct move_t * mt)
     piece = piecetype(gs->board[mt->fromFile][mt->fromRank]);
   }
 
-  if ((mt->fromFile == ALG_CASTLE) && (mt->toFile > mt->toRank)) { // [HGM] castle: K ends right of R
-    strcpy(mStr, "O-O");
-    goto check;
-  }
-  if ((mt->fromFile == ALG_CASTLE) && (mt->toFile < mt->toRank)) { // [HGM] castle: K ends left of R
-    strcpy(mStr, "O-O-O");
+  if (mt->fromFile == ALG_CASTLE) {
+    int r = gs->onMove == WHITE ? 1 : gs->ranks;
+    if(mt->toFile > mt->toRank) { // [HGM] castle: K ends right of R
+      strcpy(mStr, "O-O");
+    }
+    if (mt->toFile < mt->toRank) { // [HGM] castle: K ends left of R
+      strcpy(mStr, "O-O-O");
+    }
+    if(gs->drops == 2) {
+       if(mt->piecePromotionTo < 0) snprintf(mStr, 20, "%c%de%d", mt->fromRank + 'a', r, r);
+       goto suffix; // [HGM] in Seirawan castling can have gating suffix
+    }
     goto check;
   }
   strcpy(mStr, "");
@@ -690,10 +696,10 @@ char *alg_unparse(struct game_state_t * gs, struct move_t * mt)
   }
   sprintf(tmp, "%c%d", mt->toFile + 'a', mt->toRank + 1 - (gs->ranks > 9));
   strcat(mStr, tmp);
-
+suffix:
   if ((piece == PAWN || gs->promoType == 3 || gs->drops == 2) && (mt->piecePromotionTo != NOPIECE)) {
     strcat(mStr, "=");         /* = before promoting piece */
-    switch (piecetype(mt->piecePromotionTo)) {
+    switch (piecetype(abs(mt->piecePromotionTo))) {
     case KNIGHT:
       strcat(mStr, "N");
       break;