2 /* This file contains code for X-CHESS.
3 Copyright (C) 1986 Free Software Foundation, Inc.
5 This file is part of X-CHESS.
7 X-CHESS is distributed in the hope that it will be useful,
8 but WITHOUT ANY WARRANTY. No author or distributor
9 accepts responsibility to anyone for the consequences of using it
10 or for whether it serves any particular purpose or works at all,
11 unless he says so in writing. Refer to the X-CHESS General Public
12 License for full details.
14 Everyone is granted permission to copy, modify and redistribute
15 X-CHESS, but only under the conditions described in the
16 X-CHESS General Public License. A copy of this license is
17 supposed to have been given to you along with X-CHESS so you
18 can know your rights and responsibilities. It should be in a
19 file named COPYING. Among other things, the copyright notice
20 and this notice must be preserved on all copies. */
23 /* RCS Info: $Revision: 1.4 $ on $Date: 86/11/23 17:18:20 $
24 * $Source: /users/faustus/xchess/RCS/record.c,v $
25 * Copyright (c) 1986 Wayne A. Christopher, U. C. Berkeley CAD Group
26 * Permission is granted to do anything with this code except sell it
27 * or remove this message.
29 * Deal with recording moves.
36 bool record_english = true;
37 char *record_file = DEF_RECORD_FILE;
39 bool saveflag = false;
41 static char *colnames[] = { "qr", "qn", "qb", "q", "k", "kb", "kn", "kr" } ;
42 static char *pcnames[] = { "P", "R", "N", "B", "Q", "K" } ;
44 static char *movestring();
45 static char *tstring();
48 #define RECORD_HEADER "\n
\ 61 XChess Game Record
\ 60\n"
56 i = XTextWidth(win->medium, RECORD_HEADER,
57 sizeof(RECORD_HEADER) - 1);
58 i = (40 * win->small->max_bounds.width - i *
59 win->medium->max_bounds.width) /
60 win->medium->max_bounds.width / 2;
61 TxtGrab(win->display, win->recwin, "xchess", win->small, win->textback.pixel,
62 win->textcolor.pixel, win->cursorcolor.pixel);
63 TxtAddFont(win->display, win->recwin, 1, win->medium, win->textcolor.pixel);
65 TxtWriteStr(win->display, win->recwin, " ");
66 TxtWriteStr(win->display, win->recwin, RECORD_HEADER);
69 if (!(backup = fopen(record_file, "w"))) {
73 fprintf(backup, "X Chess -- %s\n", datestring());
75 fprintf(backup, "\tWhite on %s, black on %s\n",
76 dispname1, dispname2);
78 fprintf(backup, "\tGame played on %s\n",
80 fprintf(backup, "\t%s\n", record_english ? "english" :
93 TxtWriteStr(win1->display, win1->recwin, "\n\n
\ 61 New Game
\ 60\n\n");
95 TxtWriteStr(win2->display, win2->recwin, "\n\n
\ 61 New Game
\ 60\n\n");
99 fprintf(backup, "\n\nNew Game\n\n");
111 sprintf(buf, "\n%s\n", s);
112 TxtWriteStr(win1->display, win1->recwin, s);
114 TxtWriteStr(win2->display, win2->recwin, s);
117 fprintf(backup, "\n%s\n", s);
118 fprintf(backup, "Time: white: %s, ", tstring(whiteseconds));
119 fprintf(backup, "black: %s\n", tstring(blackseconds));
133 if (!(fp = fopen(record_file, "w"))) {
137 fprintf(fp, "X Chess -- %s\n", datestring());
139 fprintf(fp, "\tWhite on %s, black on %s\n",
140 dispname1, dispname2);
142 fprintf(fp, "\tGame played on %s\n", dispname1);
143 fprintf(fp, "\t%s\n", record_english ? "english" : "algebraic");
145 for (m = moves, i = 1; m; i++) {
147 fprintf(fp, "%2d. %-16s ", i, s);
153 fprintf(fp, "%s\n", s);
169 if (m->piece.color == WHITE) {
171 sprintf(buf, "%2d. %-16s ", movenum, s);
173 sprintf(buf, "%s\n", s);
175 TxtWriteStr(win1->display, win1->recwin, buf);
177 TxtWriteStr(win2->display, win2->recwin, buf);
180 fprintf(backup, "%s", buf);
190 extern move *lastmove;
192 char *s = movestring(m);
196 if (m->piece.color == WHITE) {
197 sprintf(buf, "%2d. %-16s ", movenum, s);
199 sprintf(buf, "%s\n", s);
202 for (i = 0; *s != '\0'; i++)
203 *s++ = '
\b'; /* control H, backspace */
205 TxtWriteStr(win1->display, win1->recwin, buf);
207 TxtWriteStr(win2->display, win2->recwin, buf);
210 if (nexttomove == BLACK)
213 fseek(backup, -i, 1);
225 static char buf[BSIZE];
227 if (!record_english || (m->piece.color == WHITE)) {
228 fy = SIZE - m->fromy;
238 sprintf(buf, "%s/%s%d-%s%d%s", pcnames[(int) m->piece.
239 type], colnames[m->fromx], fy,
240 colnames[m->tox], ty, m->check ? "+" :
243 sprintf(buf, "%c%d%c%d", 'a' + m->fromx, fy, 'a' +
248 sprintf(buf, "%s/%s%dx%s/%s%d%s%s",
249 pcnames[(int) m->piece.type],
250 colnames[m->fromx], fy,
251 pcnames[(int) m->taken.type],
252 colnames[m->tox], ty,
253 m->enpassant ? "e.p." : "",
254 m->check ? "+" : "");
256 sprintf(buf, "%c%d%c%d", 'a' + m->fromx, fy, 'a' +
262 sprintf(buf, "O-O%s", m->check ? "ch" : "");
263 else if (m->piece.color == WHITE)
271 sprintf(buf, "O-O-O%s", m->check ? "ch" : "");
272 else if (m->piece.color == WHITE)
279 sprintf(buf, "something strange");
282 if ((m->piece.type == PAWN) && (((m->piece.color == BLACK) &&
283 (m->toy == 7)) || ((m->piece.color == WHITE) &&
288 if (!(random() % 50))
290 else if (!(random() % 50))
292 else if (!(random() % 500))
294 else if (!(random() % 500))
308 sprintf(buf, "%dh %dm %ds", s / 3600, (s % 3600) / 60, s % 60);
310 sprintf(buf, "%dm %ds", (s % 3600) / 60, s % 60);
312 sprintf(buf, "%ds", s);