[gnu.chess] Gnuchess does not undo promotion correctly & fix

tom@tnosoes.UUCP (Tom Vijlbrief) (01/23/90)

The routine Undo() in gnuchess 1.52 (I don't have the newer version 1.55)
does not correctly undo a pawn promotion. Undo() is in nondsp.c and uxdsp.c.

The original version is:
======================================================================
Undo()
 
/*
   Undo the most recent half-move.
*/
 
{
short f,t;
  f = GameList[GameCnt].gmove>>8;
  t = GameList[GameCnt].gmove & 0xFF;
  if (board[t] == king && distance(t,f) > 1)
    castle(GameList[GameCnt].color,f,t,2);
  else
    {
      board[f] = board[t]; color[f] = color[t];
      board[t] = GameList[GameCnt].piece;
      color[t] = GameList[GameCnt].color;
      if (board[f] == king) --kingmoved[color[f]];
    }
  if (TCflag) ++TimeControl.moves[color[f]];
  GameCnt--; mate = false; Sdepth = 0;
  UpdateDisplay(0,0,1,0);
  InitializeStats();
}
==================================================
The fixed version is:
=================================================

......

{
short f,t;
  f = GameList[GameCnt].gmove>>8;
  t = GameList[GameCnt].gmove & 0xFF;
  if (board[t] == king && distance(t,f) > 1)
    castle(GameList[GameCnt].color,f,t,2);
  else
    {
      /* Check for promotion: */
      if (board[t] == queen &&
        ((row[f]==6 && row[t]==7) || (row[f]==1 && row[t]==0))) {
          int g, from= f;
          for (g= GameCnt-1; g>=0; g--)
            if (GameList[g].gmove & 0xFF == from)
                from= GameList[g].gmove>>8;
          if (row[from]==1 || row[from]==6)
                board[t]= pawn;
      }

      board[f] = board[t]; color[f] = color[t];
      board[t] = GameList[GameCnt].piece;
      color[t] = GameList[GameCnt].color;
      if (board[f] == king) --kingmoved[color[f]];
    }

.... etc ....
======================================================

===============================================================================
Tom Vijlbrief
TNO Institute for Perception
P.O. Box 23				Phone: +31 34 63 562 11
3769 ZG  Soesterberg			E-mail: tnosoes!tom@mcvax.cwi.nl
The Netherlands				    or:	uunet!mcvax!tnosoes!tom
===============================================================================