Article View: gnu.chess
Article #72Gnuchess does not undo promotion correctly & fix
From: Tom Vijlbrief
Date: Tue, 23 Jan 1990 07:58
Date: Tue, 23 Jan 1990 07:58
70 lines
2563 bytes
2563 bytes
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
===============================================================================
Technical Details
Message-ID:
<673@tnosoes.UUCP>Path:
arc1-ca.pugleaf.net!utzoo!utgpu!jarvis.csri.toronto.edu!clyde.concordia.ca!uunet!mcsun!hp4nl!tnosoes!tomShow Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!jarvis.csri.toronto.edu!clyde.concordia.ca!uunet!mcsun!hp4nl!tnosoes!tom From: tom@tnosoes.UUCP (Tom Vijlbrief) Newsgroups: gnu.chess Subject: Gnuchess does not undo promotion correctly & fix Keywords: gnuchess Message-ID: <673@tnosoes.UUCP> Date: 23 Jan 90 07:58:27 GMT Organization: TNO Institute for Perception, Soesterberg, The Netherlands Lines: 70