summaryrefslogtreecommitdiffstats
path: root/gnu/games
diff options
context:
space:
mode:
Diffstat (limited to 'gnu/games')
-rw-r--r--gnu/games/Makefile5
-rw-r--r--gnu/games/Makefile.inc9
-rw-r--r--gnu/games/chess/Makefile15
-rw-r--r--gnu/games/chess/Xchess/Makefile136
-rw-r--r--gnu/games/chess/Xchess/XCircle.c162
-rw-r--r--gnu/games/chess/Xchess/board.c179
-rw-r--r--gnu/games/chess/Xchess/button.c337
-rw-r--r--gnu/games/chess/Xchess/clock.c291
-rw-r--r--gnu/games/chess/Xchess/control.c515
-rw-r--r--gnu/games/chess/Xchess/jail.c327
-rw-r--r--gnu/games/chess/Xchess/message.c101
-rw-r--r--gnu/games/chess/Xchess/parse.c386
-rw-r--r--gnu/games/chess/Xchess/popup.c112
-rw-r--r--gnu/games/chess/Xchess/program.c204
-rw-r--r--gnu/games/chess/Xchess/record.c315
-rw-r--r--gnu/games/chess/Xchess/scrollText.c1877
-rw-r--r--gnu/games/chess/Xchess/scrollText/scrollText.c1858
-rw-r--r--gnu/games/chess/Xchess/std.c427
-rw-r--r--gnu/games/chess/Xchess/std.h105
-rw-r--r--gnu/games/chess/Xchess/valid.c264
-rw-r--r--gnu/games/chess/Xchess/window.c952
-rw-r--r--gnu/games/chess/Xchess/xchess.c205
-rw-r--r--gnu/games/chess/chess.6161
-rw-r--r--gnu/games/chess/gnuchess.c2307
-rw-r--r--gnu/games/chess/gnuchess.h97
-rw-r--r--gnu/games/chess/move.c357
-rw-r--r--gnu/games/chess/move.h81
-rw-r--r--gnu/games/chess/nondsp.c791
-rw-r--r--gnu/games/chess/uxdsp.c933
29 files changed, 0 insertions, 13509 deletions
diff --git a/gnu/games/Makefile b/gnu/games/Makefile
deleted file mode 100644
index 4a7577e..0000000
--- a/gnu/games/Makefile
+++ /dev/null
@@ -1,5 +0,0 @@
-# $Id$
-
-SUBDIR= chess
-
-.include <bsd.subdir.mk>
diff --git a/gnu/games/Makefile.inc b/gnu/games/Makefile.inc
deleted file mode 100644
index 4437a84..0000000
--- a/gnu/games/Makefile.inc
+++ /dev/null
@@ -1,9 +0,0 @@
-# $Id$
-
-BINOWN?= games
-.if defined(HIDEGAME)
-BINDIR?= /usr/games/hide
-BINMODE?= 4700
-.else
-BINDIR?= /usr/games
-.endif
diff --git a/gnu/games/chess/Makefile b/gnu/games/chess/Makefile
deleted file mode 100644
index a40e597..0000000
--- a/gnu/games/chess/Makefile
+++ /dev/null
@@ -1,15 +0,0 @@
-# @(#)Makefile 5.4 (Berkeley) 5/11/90
-
-PROG= chess
-SRCS= gnuchess.c uxdsp.c move.c
-CFLAGS+=-DNEWMOVE=12
-MAN6= chess.6
-DPADD= ${LIBCURSES} ${LIBTERMCAP}
-LDADD= -lcurses -ltermcap
-HIDEGAME=hidegame
-
-beforeinstall:
- ${INSTALL} -c -o ${BINOWN} -g ${BINGRP} -m 444 \
- ${.CURDIR}/gnuchess.book ${DESTDIR}/usr/share/games
-
-.include <bsd.prog.mk>
diff --git a/gnu/games/chess/Xchess/Makefile b/gnu/games/chess/Xchess/Makefile
deleted file mode 100644
index c4d0d78..0000000
--- a/gnu/games/chess/Xchess/Makefile
+++ /dev/null
@@ -1,136 +0,0 @@
-# RCS Info: $Revision: 1.3 $ on $Date: 1995/05/30 04:41:16 $
-# $Source: /home/ncvs/src/gnu/games/chess/Xchess/Makefile,v $
-# Copyright (c) 1985 Wayne A. Christopher, U. C. Berkeley CAD Group
-#
-# Makefile for xchess.
-
-#CC = cc -O -m68010 -L/pub.MC68010/lib -L/usr.MC68010/lib
-CC = cc -O
-
-CFILES =\
- board.c\
- button.c\
- clock.c\
- control.c\
- jail.c\
- message.c\
- parse.c\
- popup.c\
- program.c\
- record.c\
- std.c\
- valid.c\
- window.c\
- XCircle.c
-
-COBJS =\
- board.o\
- button.o\
- clock.o\
- control.o\
- jail.o\
- message.o\
- parse.o\
- popup.o\
- program.o\
- record.o\
- std.o\
- valid.o\
- window.o\
- XCircle.o
-
-HFILES =\
- std.h\
- xchess.h
-
-SOURCE = $(CFILES)
-
-ALLFILES = $(SOURCE) $(HFILES)
-
-INCLUDE = -I. -I${X11BASE}/include
-
-DEFINES = -DDEF_PROGRAM=\"/usr/games/chess\"
-
-CFLAGS = $(DEFINES) $(INCLUDE)
-LINTFLAGS = -u -z -lc -DLINT $(DEFINES) $(INCLUDE)
-LINTLIB = ../lib/llib-lX.ln
-#LDFLAGS = -L/usr2/X/lib -z -lX -lm
-LDFLAGS = -L${X11BASE}/lib -loldX -lX11 -z -lm
-GPLDFLAGS = -z -loldX -lX11 -lXMenu_p -lX -lm_p -g -pg
-
-.c.o: $*.c
- $(CC) $(CFLAGS) -c $*.c
-.s.o: $*.s
- $(CC) $(CFLAGS) -c $*.s
-
-all: xchess scrollText.o
- @echo "All done."
-
-everything: all tags depend lint wc
- @echo "All done."
-
-xchess: xchess.o $(COBJS) scrollText.o
- $(CC) -o xchess xchess.o $(COBJS) scrollText.o \
- $(LDFLAGS)
-
-scrollText.o: scrollText.h scrollText.c
-
-gpxchess: xchess.o $(COBJS)
- $(CC) -o gpxchess xchess.o $(COBJS) scrollText/libScroll.a \
- $(GPLDFLAGS)
-
-lint: $(SOURCE)
- lint $(LINTFLAGS) $(SOURCE) $(LINTLIB) | \
- grep -v "multiply declared"
-
-qgrind: $(ALLFILES)
- qgrind -lc $(ALLFILES)
-
-vgrind: $(ALLFILES)
- vgrind -lc $(ALLFILES)
-
-opt: all
-
-reopt: all
-
-install: all
-
-source: $(SOURCE)
-
-tags: $(ALLFILES)
- ctags -w -t *.c *.h > /dev/null 2>&1
-
-wc: $(ALLFILES)
- @wc $(ALLFILES)
-
-print: $(ALLFILES)
- @pr $(ALLFILES)
-
-clean:
- rm -f *.o *.a *.out xchess tags foo tmp
-
-tar:
- tar -cf xchess.tar Makefile *.h *.c *.bitmap *.icon *.cur *.1\
- scrollText/Makefile scrollText/*.h scrollText/*.c scrollText/*.1\
- scrollText/*.3
-
-$(ALLFILES):
- co $@
-
-depend: $(SOURCE)
- cc -M $(CFLAGS) $(CFILES) > makedep
- echo '/^# DO NOT DELETE THIS LINE/+2,$$d' >eddep
- echo '$$r makedep' >>eddep
- echo 'w' >>eddep
- ed - Makefile < eddep
- rm eddep makedep
- echo '# DEPENDENCIES MUST END AT END OF FILE' >> Makefile
- echo '# IF YOU PUT STUFF HERE IT WILL GO AWAY' >> Makefile
- echo '# see make depend above' >> Makefile
-
-#-----------------------------------------------------------------
-# DO NOT DELETE THIS LINE -- make depend uses it
-# DEPENDENCIES MUST END AT END OF FILE
-
-xchess.o $(COBJS): $(HFILES)
-
diff --git a/gnu/games/chess/Xchess/XCircle.c b/gnu/games/chess/Xchess/XCircle.c
deleted file mode 100644
index 5514855..0000000
--- a/gnu/games/chess/Xchess/XCircle.c
+++ /dev/null
@@ -1,162 +0,0 @@
-
-/* This file contains code for X-CHESS.
- Copyright (C) 1986 Free Software Foundation, Inc.
-
-This file is part of X-CHESS.
-
-X-CHESS is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY. No author or distributor
-accepts responsibility to anyone for the consequences of using it
-or for whether it serves any particular purpose or works at all,
-unless he says so in writing. Refer to the X-CHESS General Public
-License for full details.
-
-Everyone is granted permission to copy, modify and redistribute
-X-CHESS, but only under the conditions described in the
-X-CHESS General Public License. A copy of this license is
-supposed to have been given to you along with X-CHESS so you
-can know your rights and responsibilities. It should be in a
-file named COPYING. Among other things, the copyright notice
-and this notice must be preserved on all copies. */
-
-
-/* RCS Info: $Revision: 1.2 $ on $Date: 1995/05/30 04:41:18 $
- * $Source: /home/ncvs/src/gnu/games/chess/Xchess/XCircle.c,v $
- * Copyright (c) 1986 Wayne A. Christopher, U. C. Berkeley CAD Group
- * Permission is granted to do anything with this code except sell it
- * or remove this message.
- *
- */
-
-#include <stdio.h>
-#include <X11/Xlib.h>
-#include <X11/X10.h>
-#include <math.h>
-
-#define PI 3.1415926535897932384
-
-#define MAXVERTS 1000
-
-void
-XCircle(win, x, y, rad, start, end, width, height, pixel, func, planes)
- Window win;
- int x, y, rad;
- double start, end;
- int pixel;
- int width, height;
- int func, planes;
-{
- Vertex verts[MAXVERTS];
- double xp, yp, ang;
- int lx, ly, xpt, ypt, i;
- double gradincr = 2 / (double) rad;
- int bk = 0;
-
- while (end >= PI * 2)
- end -= PI * 2;
- while (start >= PI * 2)
- start -= PI * 2;
- while (end < 0)
- end += PI * 2;
- while (start < 0)
- start += PI * 2;
- if (end == start) {
- if (end < gradincr)
- end = end + PI * 2 - gradincr / 2;
- else
- end -= gradincr / 2;
- }
- for (ang = start, i = 0; i < MAXVERTS; ) {
-
- xp = x + rad * cos(ang);
- yp = y + rad * sin(ang);
-
- xpt = xp;
- ypt = yp;
-
- if (!i || (lx != xpt) || (ly != ypt)) {
- verts[i].x = xpt;
- verts[i].y = ypt;
- verts[i].flags = 0;
- i++;
- }
- lx = xpt;
- ly = ypt;
- if (bk)
- break;
- if (((ang < end) && (ang + gradincr > end)) || ((end < start)
- && (ang + gradincr > 2 * PI)
- && (ang + gradincr - 2 * PI > end))) {
- ang = end;
- bk = 1;
- } else if (ang == end) {
- break;
- } else {
- ang += gradincr;
- }
- if (ang >= PI * 2)
- ang -= PI * 2;
- }
-
- /* Now draw the thing.. */
- XDraw(win, verts, i, width, height, pixel, func, planes);
-
- return;
-}
-
-#ifdef notdef /* VertexCurved is screwed up */
-
-void
-XCircle(win, x, y, rad, start, end, width, height, pixel, func, planes)
- Window win;
- int x, y, rad;
- double start, end;
- int pixel;
- int width, height;
- int func, planes;
-{
- Vertex verts[7];
- int i, j, sv, ev;
- int dp = 0;
-
- for (i = j = 0 ; i < 4; i++) {
- verts[j].x = x + rad * cos((double) (PI * i / 2));
- verts[j].y = y + rad * sin((double) (PI * i / 2));
- verts[j].flags = VertexCurved;
- if ((start >= PI * i / 2) && (start < PI * (i + 1) / 2) &&
- (start != end)) {
- j++;
- verts[j].x = x + rad * cos(start);
- verts[j].y = y + rad * sin(start);
- verts[j].flags = VertexCurved;
- sv = j;
- } else if ((end >= PI * i / 2) && (end < PI * (i + 1) / 2)
- && (start != end)) {
- j++;
- verts[j].x = x + rad * cos(end);
- verts[j].y = y + rad * sin(end);
- verts[j].flags = VertexCurved;
- ev = j;
- }
- j++;
- }
- verts[0].flags |= VertexStartClosed;
- verts[j].x = verts[0].x;
- verts[j].y = verts[0].y;
- verts[j].flags = (verts[0].flags & ~VertexStartClosed) |
- VertexEndClosed;
- for (i = 0; i < 15; i++) {
- if (dp)
- verts[i % 7].flags |= VertexDontDraw;
- if (i % 7 == ev)
- dp = 1;
- else if (i % 7 == sv)
- dp = 0;
- }
- XDraw(win, verts, j + 1, width, height, pixel, func, planes);
-
- return;
-}
-
-#endif notdef
-
diff --git a/gnu/games/chess/Xchess/board.c b/gnu/games/chess/Xchess/board.c
deleted file mode 100644
index fab97d8..0000000
--- a/gnu/games/chess/Xchess/board.c
+++ /dev/null
@@ -1,179 +0,0 @@
-
-/* This file contains code for X-CHESS.
- Copyright (C) 1986 Free Software Foundation, Inc.
-
-This file is part of X-CHESS.
-
-X-CHESS is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY. No author or distributor
-accepts responsibility to anyone for the consequences of using it
-or for whether it serves any particular purpose or works at all,
-unless he says so in writing. Refer to the X-CHESS General Public
-License for full details.
-
-Everyone is granted permission to copy, modify and redistribute
-X-CHESS, but only under the conditions described in the
-X-CHESS General Public License. A copy of this license is
-supposed to have been given to you along with X-CHESS so you
-can know your rights and responsibilities. It should be in a
-file named COPYING. Among other things, the copyright notice
-and this notice must be preserved on all copies. */
-
-
-/* RCS Info: $Revision: 1.1.1.1 $ on $Date: 1993/06/12 14:41:08 $
- * $Source: /home/ncvs/src/gnu/games/chess/Xchess/board.c,v $
- * Copyright (c) 1986 Wayne A. Christopher, U. C. Berkeley CAD Group
- * Permission is granted to do anything with this code except sell it
- * or remove this message.
- *
- * Stuff to deal with the board.
- */
-
-#include "xchess.h"
-
-board *chessboard;
-
-void
-board_setup()
-{
- chessboard = alloc(board);
- board_init(chessboard);
- return;
-}
-
-void
-board_init(b)
- board *b;
-{
- int i, j;
-
- for (i = 0; i < 2; i++)
- for (j = 0; j < SIZE; j++)
- b->square[i][j].color = BLACK;
- for (i = 2; i < 6; i++)
- for (j = 0; j < SIZE; j++)
- b->square[i][j].color = NONE;
- for (i = 6; i < 8; i++)
- for (j = 0; j < SIZE; j++)
- b->square[i][j].color = WHITE;
- for (i = 0; i < SIZE; i++)
- b->square[1][i].type = b->square[6][i].type =
- PAWN;
- b->square[0][0].type = b->square[7][0].type = ROOK;
- b->square[0][1].type = b->square[7][1].type = KNIGHT;
- b->square[0][2].type = b->square[7][2].type = BISHOP;
- b->square[0][3].type = b->square[7][3].type = QUEEN;
- b->square[0][4].type = b->square[7][4].type = KING;
- b->square[0][5].type = b->square[7][5].type = BISHOP;
- b->square[0][6].type = b->square[7][6].type = KNIGHT;
- b->square[0][7].type = b->square[7][7].type = ROOK;
- b->black_cant_castle_k = false;
- b->black_cant_castle_q = false;
- b->white_cant_castle_k = false;
- b->white_cant_castle_q = false;
-
- return;
-}
-
-void
-board_drawall()
-{
- int i, j;
-
- for (i = 0; i < SIZE; i++)
- for (j = 0; j < SIZE; j++)
- if (chessboard->square[i][j].color != NONE) {
- win_drawpiece(&chessboard->square[i][j], i,
- j, WHITE);
- if (!oneboard)
- win_drawpiece(&chessboard->square[i][j],
- i, j, BLACK);
- }
- return;
-}
-
-void
-board_move(b, m)
- board *b;
- move *m;
-{
- switch (m->type) {
-
- case MOVE:
- case CAPTURE:
- b->square[m->fromy][m->fromx].color = NONE;
- b->square[m->toy][m->tox].color = m->piece.color;
- b->square[m->toy][m->tox].type = m->piece.type;
- if ((m->piece.type == PAWN) && (((m->piece.color == BLACK) &&
- (m->toy == 7)) || ((m->piece.color == WHITE) &&
- (m->toy == 0))))
- b->square[m->toy][m->tox].type = QUEEN;
- if (m->enpassant)
- b->square[m->toy + ((m->piece.color == WHITE) ? 1 :
- -1)][m->tox].color = NONE;
- break;
-
- case KCASTLE:
- if (m->piece.color == WHITE) {
- b->square[7][5].color = m->piece.color;
- b->square[7][5].type = ROOK;
- b->square[7][6].color = m->piece.color;
- b->square[7][6].type = KING;
- b->square[7][4].color = NONE;
- b->square[7][7].color = NONE;
- } else {
- b->square[0][5].color = m->piece.color;
- b->square[0][5].type = ROOK;
- b->square[0][6].color = m->piece.color;
- b->square[0][6].type = KING;
- b->square[0][4].color = NONE;
- b->square[0][7].color = NONE;
- }
- break;
-
- case QCASTLE:
- if (m->piece.color == WHITE) {
- b->square[7][3].color = m->piece.color;
- b->square[7][3].type = ROOK;
- b->square[7][2].color = m->piece.color;
- b->square[7][2].type = KING;
- b->square[7][4].color = NONE;
- b->square[7][0].color = NONE;
- } else {
- b->square[0][3].color = m->piece.color;
- b->square[0][3].type = ROOK;
- b->square[0][2].color = m->piece.color;
- b->square[0][2].type = KING;
- b->square[0][4].color = NONE;
- b->square[0][0].color = NONE;
- }
- break;
-
- default:
- fprintf(stderr, "Bad move type %d\n", m->type);
- }
-
- if (m->piece.type == KING) {
- if (m->piece.color == WHITE)
- b->white_cant_castle_q =
- b->white_cant_castle_k= true;
- else
- b->black_cant_castle_q =
- b->black_cant_castle_k= true;
- } else if (m->piece.type == ROOK) {
- if (m->piece.color == WHITE) {
- if (m->fromx == 0)
- b->white_cant_castle_q = true;
- else if (m->fromx == 7)
- b->white_cant_castle_k = true;
- } else {
- if (m->fromx == 0)
- b->black_cant_castle_q = true;
- else if (m->fromx == 7)
- b->black_cant_castle_k = true;
- }
- }
-
- return;
-}
-
diff --git a/gnu/games/chess/Xchess/button.c b/gnu/games/chess/Xchess/button.c
deleted file mode 100644
index d91005d..0000000
--- a/gnu/games/chess/Xchess/button.c
+++ /dev/null
@@ -1,337 +0,0 @@
-
-/* This file contains code for X-CHESS.
- Copyright (C) 1986 Free Software Foundation, Inc.
-
-This file is part of X-CHESS.
-
-X-CHESS is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY. No author or distributor
-accepts responsibility to anyone for the consequences of using it
-or for whether it serves any particular purpose or works at all,
-unless he says so in writing. Refer to the X-CHESS General Public
-License for full details.
-
-Everyone is granted permission to copy, modify and redistribute
-X-CHESS, but only under the conditions described in the
-X-CHESS General Public License. A copy of this license is
-supposed to have been given to you along with X-CHESS so you
-can know your rights and responsibilities. It should be in a
-file named COPYING. Among other things, the copyright notice
-and this notice must be preserved on all copies. */
-
-
-/* RCS Info: $Revision: 1.1.1.1 $ on $Date: 1993/06/12 14:41:15 $
- * $Source: /home/ncvs/src/gnu/games/chess/Xchess/button.c,v $
- * Copyright (c) 1986 Wayne A. Christopher, U. C. Berkeley CAD Group
- * Permission is granted to do anything with this code except sell it
- * or remove this message.
- *
- * Do stuff with the buttons.
- * The configuration we're using is: Draw Back Pause
- * Resign Fwd Flip
- * Reset Save Easy (Switch)
- */
-
-#include "xchess.h"
-
-typedef enum choice { NOCHOICE, DRAW, RESIGN, REPLAY, SWITCH, FORE, SAVE,
- STOP, FLIP, RESTART, EASY } choice;
-
-static struct but {
- char *label;
- int x, y;
- int width, height;
- choice which;
-} buts[] = {
- { "Draw", 0, 20, 108, 29, DRAW } ,
- { "Back", 109, 20, 108, 29, REPLAY } ,
- { "Pause", 219, 20, 108, 29, STOP } ,
- { "Resign", 0, 50, 108, 29, RESIGN } ,
- { "Fwd", 109, 50, 108, 29, FORE } ,
- { "Flip", 219, 50, 108, 29, FLIP } ,
- { "Reset", 0, 80, 108, 29, RESTART } ,
- { "Save", 109, 80, 108, 29, SAVE } ,
-#define EASY_OFFSET 8
- { "Switch", 219, 80, 108, 29, SWITCH }
-/* { "NoEasy", 219, 80, 108, 29, EASY }*/
-} ;
-static int easy = 1;
-
-void
-button_draw(win)
- windata *win;
-{
- int i, x, numbuts = sizeof (buts) / sizeof (struct but);
-
- XSetState(win->display, DefaultGC(win->display, 0),
- win->border.pixel, WhitePixel(win->display, 0),
- GXcopy, AllPlanes);
- XSetLineAttributes(win->display, DefaultGC(win->display, 0),
- BORDER_WIDTH, LineSolid, CapButt,
- JoinMiter);
-
- XDrawLine(win->display, win->buttonwin,
- DefaultGC(win->display, 0),
- 0, 29, BUTTON_WIDTH, 29);
- XDrawLine(win->display, win->buttonwin,
- DefaultGC(win->display, 0),
- 0, 60, BUTTON_WIDTH, 60);
- XDrawLine(win->display, win->buttonwin,
- DefaultGC(win->display, 0),
- 108, 0, 108, BUTTON_HEIGHT);
- XDrawLine(win->display, win->buttonwin,
- DefaultGC(win->display, 0),
- 219, 0, 219, BUTTON_HEIGHT);
-
- XSetFont(win->display, DefaultGC(win->display, 0), win->large->fid);
- XSetForeground(win->display, DefaultGC(win->display, 0),
- win->textcolor.pixel);
- XSetBackground(win->display, DefaultGC(win->display, 0),
- win->textback.pixel);
-
- for (i = 0; i < numbuts; i++) {
- x = (buts[i].width -
- XTextWidth(win->large, buts[i].label,
- strlen(buts[i].label))) / 2;
-
- XDrawImageString(win->display, win->buttonwin,
- DefaultGC(win->display, 0),
- buts[i].x + x, buts[i].y, buts[i].label,
- strlen(buts[i].label));
- }
- return;
-}
-
-void
-button_service(win, event)
- windata *win;
- XEvent *event;
-{
- XKeyEvent *ev = &event->xkey;
- choice c;
- int i, numbuts = sizeof (buts) / sizeof (struct but);
- char *s;
-
- ev->y += 15;
- for (i = 0; i < numbuts; i++)
- if ((ev->x >= buts[i].x) && (ev->x <= buts[i].x +
- buts[i].width) && (ev->y >= buts[i].y) &&
- (ev->y <= buts[i].y + buts[i].height)) {
- c = buts[i].which;
- break;
- }
- if ((i == numbuts) || (c == NOCHOICE)) {
- message_add(win, "Bad choice.\n", true);
- return;
- }
-
- if (loading_flag && (c != STOP)) {
- message_add(win, "You can only use PAUSE now\n", true);
- return;
- }
-
- switch (c) {
- case DRAW:
- if (!oneboard) {
- message_add(win, "Just a sec...\n", false);
- if (!pop_question(((win == win1) ? win2 : win1),
-"The other player wants\nto call the game a draw.\nDo you agree?\n")) {
- message_add(win,
- "The other player declines the draw\n", false);
- return;
- }
- }
- message_add(win1, "Draw agreed.\n", false);
- if (!oneboard)
- message_add(win2, "Draw agreed.\n", false);
- cleanup("Draw agreed.");
- break;
-
- case RESIGN:
- if (!pop_question(win, "Are you sure\nyou want to resign?"))
- return;
- if ((oneboard && !progflag) || (nexttomove == win->color)) {
- if (nexttomove == WHITE)
- s = "White resigns.";
- else
- s = "Black resigns.";
- if (oneboard) {
- message_add(win, s, false);
- message_add(win, "\n", false);
- } else {
- message_add(win1, s, false);
- message_add(win, "\n", false);
- message_add(win2, s, false);
- message_add(win, "\n", false);
- }
- sleep(5);
- cleanup(s);
- } else {
- message_add(win, "It's not your turn.\n", true);
- }
- break;
-
- case REPLAY:
- if (!oneboard) {
- message_add(win, "Just a sec...\n", false);
- if (!pop_question(((win == win1) ? win2 : win1),
-"The other player wants\nto take back his last move.\nDo you let him?\n")) {
- message_add(win,
- "The other player refuses...\n", false);
- return;
- }
- }
- if (!moves) {
- message_add(win, "Can't back up...\n", true);
- break;
- }
- message_add(win1, "Replaying...\n", false);
- if (!oneboard)
- message_add(win2, "Replaying...\n", false);
- replay();
- if (progflag)
- replay();
- break;
-
- case FORE:
- if (!oneboard) {
- message_add(win, "Just a sec...\n", false);
- if (!pop_question(((win == win1) ? win2 : win1),
-"The other player wants\nto do a 'fore'.\nIs that ok with you?\n")) {
- message_add(win,
- "The other player refuses...\n", false);
- return;
- }
- }
- if (!foremoves) {
- message_add(win, "Can't go forward...\n", true);
- break;
- }
- message_add(win1, "Moving forward...\n", false);
- if (!oneboard)
- message_add(win2, "Moving forward...\n", false);
- forward();
- break;
-
- case SWITCH:
- message_add(win, "You can't switch yet.\n", false);
- break;
-
- case SAVE:
- if (saveflag) {
- message_add(win,
- "Game is already being logged in file '", true);
- message_add(win, record_file, true);
- message_add(win, "'.\n", true);
- } else {
- message_add(win, "Saving game to file '", false);
- message_add(win, record_file, false);
- message_add(win, "'.\n", false);
- record_save();
- }
- break;
-
- case STOP:
- if (loading_flag) {
- loading_paused = (loading_paused ? false : true);
- message_add(win, loading_paused ?
- "Stopped.\nHit 'Pause' again to restart.\n" :
- "Restarted.\n", false);
- } else if (clock_started) {
- if (!oneboard) {
- message_add(win, "Just a sec...\n", false);
- if (!pop_question(((win == win1) ? win2 : win1),
-"The other player wants\nto stop the clock.\nDo you let him?\n")) {
- message_add(win,
- "The other player refuses to pause.\n",
- false);
- return;
- }
- }
- message_add(win1,
- "Clock stopped.\nHit 'Pause' again to restart.\n",
- false);
- if (!oneboard)
- message_add(win2,
- "Clock stopped.\nHit 'Pause' again to restart.\n",
- false);
- clock_started = false;
- } else {
- if (!oneboard) {
- message_add(win, "Just a sec...\n", false);
- if (!pop_question(((win == win1) ? win2 : win1),
-"The other player wants\nto start the clock again.\nIs that ok?\n")) {
- message_add(win,
- "The other player refuses to resume.\n",
- false);
- return;
- }
- }
- message_add(win1, "Clock restarted.\n", false);
- if (!oneboard)
- message_add(win2, "Clock restarted.\n", false);
- clock_started = true;
- }
- break;
-
- case FLIP:
- message_add(win, "Flipping window...\n", false);
- win->flipped = win->flipped ? false : true;
- win_redraw(win, (XEvent *) NULL);
- break;
-
- case RESTART:
- if (!oneboard) {
- message_add(win, "Just a sec...\n", false);
- if (!pop_question(((win == win1) ? win2 : win1),
-"The other player wants\nto restart the game.\nDo you agree?\n")) {
- message_add(win,
- "The other player refuses to reset\n", false);
- return;
- }
- }
- message_add(win, "Restarting game.\n", false);
- restart();
- break;
- case EASY:
- if (oneboard) {
- int x;
- if (easy)
- easy = 0;
- else
- easy = 1;
-
- if (easy)
- buts[EASY_OFFSET].label = " Easy ";
- else
- buts[EASY_OFFSET].label = "NoEasy";
-
- program_easy(easy);
-
- x = (buts[EASY_OFFSET].width -
- XTextWidth(win->large,
- buts[EASY_OFFSET].label,
- strlen(buts[EASY_OFFSET].label))) / 2;
-
- XSetFont(win->display, DefaultGC(win->display,
- 0), win->large->fid);
- XSetForeground(win->display,
- DefaultGC(win->display, 0),
- win->textcolor.pixel);
- XSetBackground(win->display,
- DefaultGC(win->display, 0),
- win->textback.pixel);
-
- XDrawImageString(win->display,
- win->buttonwin,
- DefaultGC(win->display, 0),
- buts[EASY_OFFSET].x + x,
- buts[EASY_OFFSET].y,
- buts[EASY_OFFSET].label,
- strlen(buts[EASY_OFFSET].label));
- }
- break;
- }
- return;
-}
-
diff --git a/gnu/games/chess/Xchess/clock.c b/gnu/games/chess/Xchess/clock.c
deleted file mode 100644
index 88228b0..0000000
--- a/gnu/games/chess/Xchess/clock.c
+++ /dev/null
@@ -1,291 +0,0 @@
-
-/* This file contains code for X-CHESS.
- Copyright (C) 1986 Free Software Foundation, Inc.
-
-This file is part of X-CHESS.
-
-X-CHESS is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY. No author or distributor
-accepts responsibility to anyone for the consequences of using it
-or for whether it serves any particular purpose or works at all,
-unless he says so in writing. Refer to the X-CHESS General Public
-License for full details.
-
-Everyone is granted permission to copy, modify and redistribute
-X-CHESS, but only under the conditions described in the
-X-CHESS General Public License. A copy of this license is
-supposed to have been given to you along with X-CHESS so you
-can know your rights and responsibilities. It should be in a
-file named COPYING. Among other things, the copyright notice
-and this notice must be preserved on all copies. */
-
-
-/* RCS Info: $Revision: 1.1.1.1 $ on $Date: 1993/06/12 14:41:08 $
- * $Source: /home/ncvs/src/gnu/games/chess/Xchess/clock.c,v $
- * Copyright (c) 1986 Wayne A. Christopher, U. C. Berkeley CAD Group
- * Permission is granted to do anything with this code except sell it
- * or remove this message.
- *
- * Do stuff with the clocks. The way things work is as follows. We call
- * clock_init to draw the clocks initially, but they don't actually start
- * running until we call clock_switch for the first time.
- */
-
-#include "xchess.h"
-
-int movesperunit = 0;
-int timeunit = 0;
-bool clock_started = false;
-int whiteseconds, blackseconds;
-
-static bool white_running = true;
-static long lastwhite, lastblack;
-static bool firstmove = true;
-
-extern void dohands(), hilight();
-
-#define PI 3.1415926535897932384
-
-void
-clock_draw(win, col)
- windata *win;
- color col;
-{
- int i;
- char buf[BSIZE];
- int x = CLOCK_WIDTH / 2, y = CLOCK_WIDTH / 2;
- int xp, yp;
- int rad = CLOCK_WIDTH / 2 - 10;
- Window w = ((col == WHITE) ? win->wclockwin : win->bclockwin);
-
- /* Draw a clock face and the hands. */
- XCircle(w, x, y, rad, 0.0, 0.0, 1, 1, win->textcolor.pixel, GXcopy,
- AllPlanes);
- rad -= 8;
-
- XSetFont(win->display, DefaultGC(win->display, 0),
- win->small->fid);
- XSetForeground(win->display, DefaultGC(win->display, 0),
- win->textcolor.pixel);
- XSetBackground(win->display, DefaultGC(win->display, 0),
- win->textback.pixel);
- for (i = 1; i <= 12; i++) {
- xp = x + rad * cos(PI * 3 / 2 + i * PI / 6) - 4;
- yp = y + rad * sin(PI * 3 / 2 + i * PI / 6) - 5;
- sprintf(buf, "%d", i);
- XDrawString(win->display, w, DefaultGC(win->display, 0),
- xp, yp, buf, strlen(buf));
- }
-
- dohands(win, col);
-
- if (white_running) {
- hilight(win, WHITE, true);
- hilight(win, BLACK, false);
- } else {
- hilight(win, WHITE, false);
- hilight(win, BLACK, true);
- }
- return;
-}
-
-void
-clock_init(win, col)
- windata *win;
- color col;
-{
- whiteseconds = blackseconds = 0;
- clock_started = false;
- firstmove = true;
- clock_draw(win, col);
-
- return;
-}
-
-void
-clock_update()
-{
- int now = time((long *) NULL);
- int i;
-
- if (!clock_started) {
- lastwhite = lastblack = now;
- return;
- }
-
- if (white_running) {
- whiteseconds += now - lastwhite;
- lastwhite = now;
- dohands(win1, WHITE);
- if (!oneboard)
- dohands(win2, WHITE);
- if (timeunit) {
- i = whiteseconds / timeunit;
- if ((i > 0) && (whiteseconds > i * timeunit) &&
- (whiteseconds < i * timeunit + 10) &&
- (movesperunit * i > movenum)) {
- message_add(win1,
- "White has exceeded his time limit\n",
- true);
- if (!oneboard) {
- message_add(win2,
- "White has exceeded his time limit\n",
- true);
- }
- timeunit = 0;
- }
- }
- } else {
- blackseconds += now - lastblack;
- lastblack = now;
- dohands(win1, BLACK);
- if (!oneboard)
- dohands(win2, BLACK);
- if (timeunit) {
- i = blackseconds / timeunit;
- if ((i > 0) && (blackseconds > i * timeunit) &&
- (blackseconds < i * timeunit + 10) &&
- (movesperunit * i > movenum)) {
- message_add(win1,
- "Black has exceeded his time limit\n",
- true);
- if (!oneboard) {
- message_add(win2,
- "Black has exceeded his time limit\n",
- true);
- }
- timeunit = 0;
- }
- }
- }
- return;
-}
-
-void
-clock_switch()
-{
- if (firstmove) {
- clock_started = true;
- firstmove = false;
- lastwhite = lastblack = time((long *) NULL);
- }
- if (white_running) {
- white_running = false;
- lastblack = time((long *) NULL);
- hilight(win1, WHITE, false);
- hilight(win1, BLACK, true);
- if (!oneboard) {
- hilight(win2, WHITE, false);
- hilight(win2, BLACK, true);
- }
- } else {
- white_running = true;
- lastwhite = time((long *) NULL);
- hilight(win1, WHITE, true);
- hilight(win1, BLACK, false);
- if (!oneboard) {
- hilight(win2, WHITE, true);
- hilight(win2, BLACK, false);
- }
- }
- return;
-}
-
-static void
-dohands(win, col)
- windata *win;
- color col;
-{
- int cx = CLOCK_WIDTH / 2, cy = CLOCK_WIDTH / 2;
- double *h = (col == WHITE) ? win->whitehands : win->blackhands;
- Window w = (col == WHITE) ? win->wclockwin : win->bclockwin;
- long secs = (col == WHITE) ? whiteseconds : blackseconds;
- int rad, x, y, i;
-
- /* First erase the old hands. */
- XSetState(win->display, DefaultGC(win->display, 0),
- win->textback.pixel, win->textback.pixel,
- GXcopy, AllPlanes);
-
- rad = CLOCK_WIDTH / 2 - 30;
- for (i = 0; i < 3; i++) {
- x = cx + rad * sin(PI - h[i]);
- y = cy + rad * cos(PI - h[i]);
- XSetLineAttributes(win->display,
- DefaultGC(win->display, 0),
- i, LineSolid, 0, 0);
- XDrawLine(win->display, w, DefaultGC(win->display, 0),
- cx, cy, x, y);
- rad -= 8;
- }
-
- h[0] = (secs % 60) * 2 * PI / 60;
- h[1] = ((secs / 60) % 60) * 2 * PI / 60;
- h[2] = ((secs / 3600) % 12) * 2 * PI / 12;
-
- /* Now draw the new ones. */
-
- XSetState(win->display, DefaultGC(win->display, 0),
- win->textcolor.pixel, win->textback.pixel,
- GXcopy, AllPlanes);
-
- rad = CLOCK_WIDTH / 2 - 30;
- for (i = 0; i < 3; i++) {
- x = cx + rad * sin(PI - h[i]);
- y = cy + rad * cos(PI - h[i]);
- XSetLineAttributes(win->display,
- DefaultGC(win->display, 0),
- i, LineSolid, 0, 0);
- XDrawLine(win->display, w, DefaultGC(win->display, 0),
- cx, cy, x, y);
- rad -= 8;
- }
- XFlush(win->display);
- return;
-}
-
-static void
-hilight(win, col, on)
- windata *win;
- color col;
- bool on;
-{
- Window w = (col == WHITE) ? win->wclockwin : win->bclockwin;
- char *s = (col == WHITE) ? " WHITE " : " BLACK ";
- int x;
-
-
- x = XTextWidth(win->large, s, strlen(s));
- if (on)
- XSetState(win->display, DefaultGC(win->display, 0),
- win->textback.pixel,
- win->textcolor.pixel,
- GXcopy,
- AllPlanes);
- else
- XSetState(win->display, DefaultGC(win->display, 0),
- win->textcolor.pixel,
- win->textback.pixel,
- GXcopy, AllPlanes);
-
- XSetLineAttributes(win->display, DefaultGC(win->display, 0),
- BORDER_WIDTH, LineSolid, CapButt, JoinMiter);
- XSetFont(win->display, DefaultGC(win->display, 0),
- win->large->fid);
-
- XDrawLine(win->display, w, DefaultGC(win->display, 0),
- 0, CLOCK_HEIGHT - 26,
- CLOCK_WIDTH, CLOCK_HEIGHT - 26);
-
- XDrawImageString(win->display, w, DefaultGC(win->display, 0),
- (CLOCK_WIDTH - x) / 2, CLOCK_HEIGHT,
- s, strlen(s));
-
- if (on)
- XSetState(win->display, DefaultGC(win->display, 0),
- win->textcolor.pixel,
- win->textback.pixel,
- GXcopy, AllPlanes);
- return;
-}
-
diff --git a/gnu/games/chess/Xchess/control.c b/gnu/games/chess/Xchess/control.c
deleted file mode 100644
index 7d23a76..0000000
--- a/gnu/games/chess/Xchess/control.c
+++ /dev/null
@@ -1,515 +0,0 @@
-/* This file contains code for X-CHESS.
- Copyright (C) 1986 Free Software Foundation, Inc.
-
-This file is part of X-CHESS.
-
-X-CHESS is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY. No author or distributor
-accepts responsibility to anyone for the consequences of using it
-or for whether it serves any particular purpose or works at all,
-unless he says so in writing. Refer to the X-CHESS General Public
-License for full details.
-
-Everyone is granted permission to copy, modify and redistribute
-X-CHESS, but only under the conditions described in the
-X-CHESS General Public License. A copy of this license is
-supposed to have been given to you along with X-CHESS so you
-can know your rights and responsibilities. It should be in a
-file named COPYING. Among other things, the copyright notice
-and this notice must be preserved on all copies. */
-
-
-/* RCS Info: $Revision: 1.1.1.1 $ on $Date: 1993/06/12 14:41:11 $
- * $Source: /home/ncvs/src/gnu/games/chess/Xchess/control.c,v $
- * Copyright (c) 1986 Wayne A. Christopher, U. C. Berkeley CAD Group
- * Permission is granted to do anything with this code except sell it
- * or remove this message.
- *
- * Deal with input from the user.
- */
-
-#include "xchess.h"
-
-move *moves;
-move *foremoves;
-color nexttomove = WHITE;
-bool noisyflag = false;
-
-move *lastmove;
-static move *thismove;
-
-static void screen_move();
-
-void
-button_pressed(event, win)
- XEvent *event;
- windata *win;
-{
- int x, y;
- XKeyEvent *ev = (XKeyEvent *) event;
-
- if (!oneboard && (win->color != nexttomove)) {
- message_add(win, "Wrong player!\n", true);
- return;
- }
- if (progflag && (nexttomove == (blackflag ? WHITE : BLACK))) {
- message_add(win, "Wait for the computer...\n", true);
- return;
- }
- if (loading_flag) {
- message_add(win, "You'd better not do that now...\n", true);
- return;
- }
-
- /* Figure out what piece he is pointing at. */
- x = ev->x / (SQUARE_WIDTH + BORDER_WIDTH);
- y = ev->y / (SQUARE_HEIGHT + BORDER_WIDTH);
-
- if (win->flipped) {
- y = SIZE - y - 1;
- x = SIZE - x - 1;
- }
-
- if ((x < 0) || (x >= SIZE) || (y < 0) || (y >= SIZE)) {
- fprintf(stderr, "Bad coords (%d, %d)\n", x, y);
- return;
- }
-
- if (oneboard && (chessboard->square[y][x].color != nexttomove)) {
- message_add(win, "Wrong player!\n", true);
- return;
- } else if (!oneboard && (chessboard->square[y][x].color !=
- win->color)) {
- message_add(win, "Can't move that\n", true);
- return;
- }
-
- thismove = alloc(move);
- thismove->fromx = x;
- thismove->fromy = y;
- thismove->piece.color = chessboard->square[y][x].color;
- thismove->piece.type = chessboard->square[y][x].type;
-
- if (debug)
- fprintf(stderr, "%s selected his %s at (%d, %d)...\n",
- colornames[(int) thismove->piece.color],
- piecenames[(int) thismove->piece.type],
- thismove->fromy, thismove->fromx);
- return;
-}
-
-void
-button_released(event, win)
- XEvent *event;
- windata *win;
-{
- int x, y;
- XKeyEvent *ev = (XKeyEvent *) event;
-
- if (!thismove) {
- /* fprintf(stderr, "Error: button hasn't been pressed\n"); */
- return;
- }
- if (loading_flag)
- return;
-
- /* Figure out what piece he is pointing at. */
- x = ev->x / (SQUARE_WIDTH + BORDER_WIDTH);
- y = ev->y / (SQUARE_HEIGHT + BORDER_WIDTH);
-
- if (win->flipped) {
- y = SIZE - y - 1;
- x = SIZE - x - 1;
- }
-
- if ((x < 0) || (x >= SIZE) || (y < 0) || (y >= SIZE)) {
- fprintf(stderr, "Bad coords (%d, %d)\n", x, y);
- return;
- }
-
- if ((thismove->fromx == x) && (thismove->fromy == y)) {
- message_add(win, "Hey, you touch it, you move it, buddy.\n",
- true);
- return;
- }
- if (chessboard->square[y][x].color == thismove->piece.color) {
- message_add(win, "Can't put one piece on top of another\n",
- true);
- return;
- }
-
- thismove->tox = x;
- thismove->toy = y;
- thismove->taken.color = chessboard->square[y][x].color;
- thismove->taken.type = chessboard->square[y][x].type;
- if (thismove->taken.color != NONE)
- thismove->type = CAPTURE;
- else if ((thismove->piece.type == KING) && (thismove->fromx == 4) &&
- (thismove->tox == 6) &&
- (thismove->toy == thismove->fromy))
- thismove->type = KCASTLE;
- else if ((thismove->piece.type == KING) && (thismove->tox == 2) &&
- (thismove->fromx == 4) &&
- (thismove->toy == thismove->fromy))
- thismove->type = QCASTLE;
- else
- thismove->type = MOVE;
-
- /* Now check the en-passant case... */
- if ((thismove->type == MOVE) && ((thismove->tox == thismove->fromx + 1)
- || (thismove->tox == thismove->fromx - 1)) &&
- (thismove->piece.type == PAWN) && lastmove &&
- (lastmove->tox == lastmove->fromx) && (lastmove->fromx
- == thismove->tox) && ((lastmove->fromy + lastmove->toy)
- / 2 == thismove->toy)) {
- thismove->type = CAPTURE;
- thismove->enpassant = true;
- thismove->taken = lastmove->piece;
- }
-
- if (!valid_move(thismove, chessboard)) {
- message_add(win, "Invalid move.\n", true);
- return;
- }
-
- if (debug)
- fprintf(stderr, "\t... and moved it to (%d, %d), type %s\n",
- thismove->toy, thismove->tox,
- movetypenames[(int) thismove->type]);
- move_piece(thismove);
-
- if (thismove->check) {
- message_add(win1, "Check.\n", true);
- if (!oneboard) {
- message_add(win2, "Check.\n", true);
- }
- }
-
- if (!moves)
- moves = lastmove = thismove;
- else
- lastmove = lastmove->next = thismove;
-
- if (progflag)
- program_send(thismove);
-
- thismove = NULL;
- nexttomove = ((nexttomove == WHITE) ? BLACK : WHITE);
- clock_switch();
-
- return;
-}
-
-void
-prog_move(m)
- move *m;
-{
- if (debug)
- fprintf(stderr, "program moves from (%d, %d) to (%d, %d)\n",
- m->fromy, m->fromx, m->toy, m->tox);
- move_piece(m);
-
- if (!moves)
- moves = lastmove = m;
- else
- lastmove = lastmove->next = m;
-
- nexttomove = ((nexttomove == WHITE) ? BLACK : WHITE);
- clock_switch();
-
- return;
-}
-
-void
-move_piece(m)
- move *m;
-{
- /* Update the screen... */
- screen_move(m);
-
- /* Move the piece on the board... */
- board_move(chessboard, m);
-
- /* And record it... */
- record_move(m);
-
- if (noisyflag) {
- XBell(win1->display, 50);
- XBell(win2->display, 50);
- }
- return;
-}
-
-static void
-screen_move(m)
- move *m;
-{
- piece pp;
-
- switch (m->type) {
- case CAPTURE:
- jail_add(&m->taken);
- /* FALLTHRU */
-
- case MOVE:
- win_erasepiece(m->fromy, m->fromx, WHITE);
- if (win_flashmove)
- win_flash(m, WHITE);
- win_drawpiece(&m->piece, m->toy, m->tox, WHITE);
- if (m->enpassant)
- win_erasepiece(m->toy + ((m->piece.color == WHITE) ?
- 1 : -1), m->tox, WHITE);
- if (!oneboard) {
- win_erasepiece(m->fromy, m->fromx, BLACK);
- if (win_flashmove)
- win_flash(m, BLACK);
- win_drawpiece(&m->piece, m->toy, m->tox, BLACK);
- if (m->enpassant)
- win_erasepiece(m->toy + ((m->piece.color ==
- WHITE) ? 1 : -1), m->tox, WHITE);
- }
- if ((m->piece.type == PAWN) && (((m->piece.color == BLACK) &&
- (m->toy == 7)) || ((m->piece.color == WHITE) &&
- (m->toy == 0)))) {
- pp.color = m->piece.color;
- pp.type = QUEEN;
- win_drawpiece(&pp, m->toy, m->tox, WHITE);
- if (!oneboard)
- win_drawpiece(&m->piece, m->toy, m->tox, BLACK);
- }
- break;
-
- case KCASTLE:
- if (m->piece.color == WHITE) {
- win_erasepiece(7, 4, WHITE);
- win_erasepiece(7, 7, WHITE);
- if (win_flashmove)
- win_flash(m, WHITE);
- win_drawpiece(&m->piece, 7, 6, WHITE);
- win_drawpiece(&chessboard->square[7][7], 7, 5, WHITE);
- if (!oneboard) {
- win_erasepiece(7, 4, BLACK);
- win_erasepiece(7, 7, BLACK);
- if (win_flashmove)
- win_flash(m, BLACK);
- win_drawpiece(&m->piece, 7, 6, BLACK);
- win_drawpiece(&chessboard->square[7][7], 7, 5,
- BLACK);
- }
- } else {
- win_erasepiece(0, 4, WHITE);
- win_erasepiece(0, 7, WHITE);
- if (win_flashmove)
- win_flash(m, WHITE);
- win_drawpiece(&m->piece, 0, 6, WHITE);
- win_drawpiece(&chessboard->square[0][7], 0, 5, WHITE);
- if (!oneboard) {
- win_erasepiece(0, 4, BLACK);
- win_erasepiece(0, 7, BLACK);
- if (win_flashmove)
- win_flash(m, BLACK);
- win_drawpiece(&m->piece, 0, 6, BLACK);
- win_drawpiece(&chessboard->square[0][7], 0, 5,
- BLACK);
- }
- }
- break;
-
- case QCASTLE:
- if (m->piece.color == WHITE) {
- win_erasepiece(7, 4, WHITE);
- win_erasepiece(7, 0, WHITE);
- if (win_flashmove)
- win_flash(m, WHITE);
- win_drawpiece(&m->piece, 7, 2, WHITE);
- win_drawpiece(&chessboard->square[7][0], 7, 3, WHITE);
- if (!oneboard) {
- win_erasepiece(7, 4, BLACK);
- win_erasepiece(7, 0, BLACK);
- if (win_flashmove)
- win_flash(m, BLACK);
- win_drawpiece(&m->piece, 7, 2, BLACK);
- win_drawpiece(&chessboard->square[7][7], 7, 3,
- BLACK);
- }
- } else {
- win_erasepiece(0, 4, WHITE);
- win_erasepiece(0, 0, WHITE);
- if (win_flashmove)
- win_flash(m, WHITE);
- win_drawpiece(&m->piece, 0, 2, WHITE);
- win_drawpiece(&chessboard->square[0][0], 0, 3, WHITE);
- if (!oneboard) {
- win_erasepiece(0, 4, BLACK);
- win_erasepiece(0, 0, BLACK);
- if (win_flashmove)
- win_flash(m, BLACK);
- win_drawpiece(&m->piece, 0, 2, BLACK);
- win_drawpiece(&chessboard->square[0][7], 0, 3,
- BLACK);
- }
- }
- break;
-
- default:
- fprintf(stderr, "Bad move type %d\n", m->type);
- }
- return;
-}
-
-/* Retract the last move made... */
-
-void
-replay()
-{
- move *m = lastmove, bm;
-
- memset(&bm, 0, sizeof(bm));
- switch (m->type) {
- case MOVE:
- bm.type = MOVE;
- bm.piece = m->piece;
- bm.fromx = m->tox;
- bm.fromy = m->toy;
- bm.tox = m->fromx;
- bm.toy = m->fromy;
- board_move(chessboard, &bm);
- screen_move(&bm);
- break;
-
- case CAPTURE:
- bm.type = MOVE;
- bm.piece = m->piece;
- bm.fromx = m->tox;
- bm.fromy = m->toy;
- bm.tox = m->fromx;
- bm.toy = m->fromy;
- board_move(chessboard, &bm);
- screen_move(&bm);
- chessboard->square[m->toy][m->tox] = m->taken;
- bm.piece = m->taken;
- bm.fromx = bm.tox = m->tox;
- bm.fromy = bm.toy = m->toy;
- screen_move(&bm);
- jail_remove(&m->taken);
- break;
-
- case KCASTLE:
- bm.type = MOVE;
- bm.piece.type = KING;
- bm.piece.color = m->piece.color;
- bm.fromx = 6;
- bm.tox = 4;
- bm.fromy = bm.toy = (m->piece.color == WHITE) ? 7 : 0;
- board_move(chessboard, &bm);
- screen_move(&bm);
- bm.type = MOVE;
- bm.piece.type = ROOK;
- bm.piece.color = m->piece.color;
- bm.fromx = 5;
- bm.tox = 7;
- bm.fromy = bm.toy = (m->piece.color == WHITE) ? 7 : 0;
- board_move(chessboard, &bm);
- screen_move(&bm);
- if (m->piece.color == WHITE)
- chessboard->white_cant_castle_k = false;
- else
- chessboard->black_cant_castle_k = false;
- break;
-
- case QCASTLE:
- bm.type = MOVE;
- bm.piece.type = KING;
- bm.piece.color = m->piece.color;
- bm.fromx = 2;
- bm.tox = 4;
- bm.fromy = bm.toy = (m->piece.color == WHITE) ? 7 : 0;
- board_move(chessboard, &bm);
- screen_move(&bm);
- bm.type = MOVE;
- bm.piece.type = ROOK;
- bm.piece.color = m->piece.color;
- bm.fromx = 3;
- bm.tox = 0;
- bm.fromy = bm.toy = (m->piece.color == WHITE) ? 7 : 0;
- board_move(chessboard, &bm);
- screen_move(&bm);
- if (m->piece.color == WHITE)
- chessboard->white_cant_castle_q = false;
- else
- chessboard->black_cant_castle_q = false;
- break;
- }
- record_back();
-
- nexttomove = ((nexttomove == WHITE) ? BLACK : WHITE);
- clock_switch();
-
- if (!moves->next) {
- moves->next = foremoves;
- foremoves = moves;
- moves = lastmove = NULL;
- } else {
- for (m = moves; m->next; m = m->next)
- lastmove = m;
- lastmove->next->next = foremoves;
- foremoves = lastmove->next;
- lastmove->next = NULL;
- }
-
- if (progflag)
- program_undo();
-
- return;
-}
-
-/* Put back the last move undone. */
-
-void
-forward()
-{
- prog_move(foremoves);
- foremoves = foremoves->next;
- return;
-}
-
-/* End the game. */
-
-void
-cleanup(s)
- char *s;
-{
- if (progflag)
- program_end();
- record_end(s);
- XSync(win1->display, 0);
- if (!oneboard) {
- XSync(win2->display, 0);
- }
- exit(0);
-}
-
-void
-restart()
-{
- moves = lastmove = thismove = NULL;
- nexttomove = WHITE;
-
- clock_init(win1, WHITE);
- clock_init(win1, BLACK);
- jail_init(win1);
- if (!oneboard) {
- clock_init(win2, WHITE);
- clock_init(win2, BLACK);
- jail_init(win2);
- }
- board_init(chessboard);
- win_restart();
- record_reset();
- if (progflag) {
- program_end();
- program_init(progname);
- }
- return;
-}
-
diff --git a/gnu/games/chess/Xchess/jail.c b/gnu/games/chess/Xchess/jail.c
deleted file mode 100644
index b3ed391..0000000
--- a/gnu/games/chess/Xchess/jail.c
+++ /dev/null
@@ -1,327 +0,0 @@
-
-/* This file contains code for X-CHESS.
- Copyright (C) 1986 Free Software Foundation, Inc.
-
-This file is part of X-CHESS.
-
-X-CHESS is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY. No author or distributor
-accepts responsibility to anyone for the consequences of using it
-or for whether it serves any particular purpose or works at all,
-unless he says so in writing. Refer to the X-CHESS General Public
-License for full details.
-
-Everyone is granted permission to copy, modify and redistribute
-X-CHESS, but only under the conditions described in the
-X-CHESS General Public License. A copy of this license is
-supposed to have been given to you along with X-CHESS so you
-can know your rights and responsibilities. It should be in a
-file named COPYING. Among other things, the copyright notice
-and this notice must be preserved on all copies. */
-
-
-/* RCS Info: $Revision: 1.1.1.1 $ on $Date: 1993/06/12 14:41:12 $
- * $Source: /home/ncvs/src/gnu/games/chess/Xchess/jail.c,v $
- * Copyright (c) 1986 Wayne A. Christopher, U. C. Berkeley CAD Group
- * Permission is granted to do anything with this code except sell it
- * or remove this message.
- *
- */
-
-#include "xchess.h"
-
-#include "pawn_small.bitmap"
-#include "rook_small.bitmap"
-#include "knight_small.bitmap"
-#include "bishop_small.bitmap"
-#include "queen_small.bitmap"
-#include "king_small.bitmap"
-
-#include "pawn_small_outline.bitmap"
-#include "rook_small_outline.bitmap"
-#include "knight_small_outline.bitmap"
-#include "bishop_small_outline.bitmap"
-#include "queen_small_outline.bitmap"
-#include "king_small_outline.bitmap"
-
-static bool pos[32];
-
-static piecetype pcs[] = { KING, QUEEN, ROOK, ROOK, BISHOP, BISHOP, KNIGHT,
- KNIGHT, PAWN, PAWN, PAWN, PAWN, PAWN, PAWN, PAWN, PAWN } ;
-
-extern int piecepos();
-extern char *bitsget();
-
-void
-jail_init(win)
- windata *win;
-{
- int i;
-
- for (i = 0; i < 32; i++)
- pos[i] = false;
- jail_draw(win);
- return;
-}
-
-#define JAIL_HEADER "Captured Pieces"
-
-void
-jail_draw(win)
- windata *win;
-{
- int i;
- char *bits;
- Pixmap tmpPM;
- piece p;
-
- i = XTextWidth(win->large, JAIL_HEADER, strlen(JAIL_HEADER));
- XSetFont(win->display, DefaultGC(win->display, 0),
- win->large->fid);
- XSetForeground(win->display, DefaultGC(win->display, 0),
- win->textcolor.pixel);
- XSetBackground(win->display, DefaultGC(win->display, 0),
- win->textback.pixel);
-
- XDrawImageString(win->display, win->jailwin,
- DefaultGC(win->display, 0),
- (JAIL_WIDTH - i) / 2, 20, JAIL_HEADER,
- strlen(JAIL_HEADER));
-
- XSetForeground(win->display, DefaultGC(win->display, 0),
- win->blackpiece.pixel);
- XSetBackground(win->display, DefaultGC(win->display, 0),
- win->textback.pixel);
- XSetFillStyle(win->display, DefaultGC(win->display, 0),
- FillSolid);
- XSetFunction(win->display, DefaultGC(win->display, 0),
- GXcopy);
-
- for (i = 0; i < 16; i++)
- if (pos[i]) {
- p.color = WHITE;
- p.type = pcs[i];
- bits = bitsget(&p);
- tmpPM = XCreateBitmapFromData(win->display,
- win->jailwin, bits,
- 32, 32);
-
- XCopyPlane(win->display, tmpPM, win->jailwin,
- DefaultGC(win->display, 0),
- 0, 0, 32, 32,
- 5 + (i % 8) * 32, 25 + (i / 8) * 32,
- 1);
- XFreePixmap(win->display, tmpPM);
- } else {
- XFillRectangle(win->display, win->jailwin,
- DefaultGC(win->display, 0),
- 5 + (i % 8) * 32,
- 25 + (i / 8) * 32,
- 32, 32);
- }
- for (i = 0; i < 16; i++)
- if (pos[i + 16]) {
- p.color = BLACK;
- p.type = pcs[i];
- bits = bitsget(&p);
- tmpPM = XCreateBitmapFromData(win->display,
- win->jailwin, bits,
- 32, 32);
-
- XCopyPlane(win->display, tmpPM, win->jailwin,
- DefaultGC(win->display, 0),
- 0, 0, 32, 32,
- 5 + (i % 8) * 32, 94 + (i / 8) * 32,
- 1);
- XFreePixmap(win->display, tmpPM);
- } else {
- XFillRectangle(win->display, win->jailwin,
- DefaultGC(win->display, 0),
- 5 + (i % 8) * 32, 94 + (i / 8) * 32,
- 32, 32);
- }
-
- return;
-}
-
-void
-jail_add(p)
- piece *p;
-{
- int i = piecepos(p, false);
- char *bits;
- Pixmap tmpPM;
-
- pos[i] = true;
-
- bits = bitsget(p);
-
- XSetState(win1->display, DefaultGC(win1->display, 0),
- win1->blackpiece.pixel,
- win1->textback.pixel,
- GXcopy,
- AllPlanes);
-
- tmpPM = XCreateBitmapFromData(win1->display,
- win1->jailwin, bits,
- 32, 32);
-
- XCopyPlane(win1->display, tmpPM, win1->jailwin,
- DefaultGC(win1->display, 0),
- 0, 0, 32, 32,
- 5 + (i % 8) * 32, ((i >= 16) ? 30 : 25) + (i / 8) * 32,
- 1);
- XFreePixmap(win1->display, tmpPM);
-
- if (!oneboard) {
- XSetState(win2->display, DefaultGC(win2->display, 0),
- win2->blackpiece.pixel,
- win2->textback.pixel,
- GXcopy,
- AllPlanes);
-
-
- tmpPM = XCreateBitmapFromData(win2->display,
- win2->jailwin, bits,
- 32, 32);
-
- XCopyPlane(win2->display, tmpPM, win2->jailwin,
- DefaultGC(win2->display, 0),
- 0, 0, 32, 32,
- 5 + (i % 8) * 32, ((i >= 16) ? 30 : 25) + (i / 8) * 32,
- 1);
- XFreePixmap(win2->display, tmpPM);
- }
-
- return;
-}
-
-void
-jail_remove(p)
- piece *p;
-{
- int i = piecepos(p, true);
-
- pos[i] = false;
-
-
- XSetForeground(win1->display,
- DefaultGC(win1->display, 0),
- win1->blackpiece.pixel);
- XSetBackground(win1->display,
- DefaultGC(win1->display, 0),
- win1->textback.pixel);
- XSetFillStyle(win1->display,
- DefaultGC(win1->display, 0),
- FillSolid);
-
- XFillRectangle(win1->display, win1->jailwin,
- DefaultGC(win1->display, 0),
- 5 + (i % 8) * 32,
- ((i >= 16) ? 30 : 25) + (i / 8) * 32,
- 32, 32);
-
- if (!oneboard) {
- XSetForeground(win2->display,
- DefaultGC(win2->display, 0),
- win2->blackpiece.pixel);
- XSetBackground(win2->display,
- DefaultGC(win2->display, 0),
- win2->textback.pixel);
- XSetFillStyle(win2->display,
- DefaultGC(win2->display, 0),
- FillSolid);
-
- XFillRectangle(win2->display, win2->jailwin,
- DefaultGC(win2->display, 0),
- 5 + (i % 8) * 32,
- ((i >= 16) ? 30 : 25) + (i / 8) * 32,
- 32, 32);
- }
-
- return;
-}
-
-static char *bitsget(p)
- piece *p;
-{
- char *bits;
-
- switch (p->type) {
- case PAWN:
- bits = (p->color == WHITE) ? pawn_small_outline_bits :
- pawn_small_bits;
- break;
-
- case ROOK:
- bits = (p->color == WHITE) ? rook_small_outline_bits :
- rook_small_bits;
- break;
-
- case KNIGHT:
- bits = (p->color == WHITE) ? knight_small_outline_bits :
- knight_small_bits;
- break;
-
- case BISHOP:
- bits = (p->color == WHITE) ? bishop_small_outline_bits :
- bishop_small_bits;
- break;
-
- case QUEEN:
- bits = (p->color == WHITE) ? queen_small_outline_bits :
- queen_small_bits;
- break;
-
- case KING:
- bits = (p->color == WHITE) ? king_small_outline_bits :
- king_small_bits;
- break;
- }
- return (bits);
-}
-
-static int
-piecepos(p, there)
- piece *p;
- bool there;
-{
- int i, base = (p->color == WHITE) ? 0 : 16;
-
- switch (p->type) {
- case PAWN:
- for (i = base + 8; (i < base + 15) && pos[i]; i++)
- ;
- if (there && !pos[i])
- i--;
- break;
-
- case KING:
- /* Hmm... */
- i = base;
- break;
-
- case QUEEN:
- i = base + 1;
- break;
-
- case ROOK:
- i = base + 2;
- if ((there && pos[i + 1]) || (!there && pos[i]))
- i++;
- break;
-
- case BISHOP:
- i = base + 4;
- if ((there && pos[i + 1]) || (!there && pos[i]))
- i++;
- break;
-
- case KNIGHT:
- i = base + 6;
- if ((there && pos[i + 1]) || (!there && pos[i]))
- i++;
- break;
- }
- return (i);
-}
diff --git a/gnu/games/chess/Xchess/message.c b/gnu/games/chess/Xchess/message.c
deleted file mode 100644
index 26df739..0000000
--- a/gnu/games/chess/Xchess/message.c
+++ /dev/null
@@ -1,101 +0,0 @@
-
-/* This file contains code for X-CHESS.
- Copyright (C) 1986 Free Software Foundation, Inc.
-
-This file is part of X-CHESS.
-
-X-CHESS is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY. No author or distributor
-accepts responsibility to anyone for the consequences of using it
-or for whether it serves any particular purpose or works at all,
-unless he says so in writing. Refer to the X-CHESS General Public
-License for full details.
-
-Everyone is granted permission to copy, modify and redistribute
-X-CHESS, but only under the conditions described in the
-X-CHESS General Public License. A copy of this license is
-supposed to have been given to you along with X-CHESS so you
-can know your rights and responsibilities. It should be in a
-file named COPYING. Among other things, the copyright notice
-and this notice must be preserved on all copies. */
-
-
-/* RCS Info: $Revision: 1.1.1.1 $ on $Date: 1993/06/12 14:41:14 $
- * $Source: /home/ncvs/src/gnu/games/chess/Xchess/message.c,v $
- * Copyright (c) 1986 Wayne A. Christopher, U. C. Berkeley CAD Group
- * Permission is granted to do anything with this code except sell it
- * or remove this message.
- *
- * Do stuff with the message window. Font 0 is the normal font, font 1
- * is large, and font 2 is normal red.
- */
-
-#include "xchess.h"
-
-#define MESSAGE_HEADER "\n1 XChess Messages0\n"
-
-void
-message_init(win)
- windata *win;
-{
- TxtGrab(win->display, win->messagewin, "xchess", win->medium,
- win->textback.pixel, win->textcolor.pixel,
- win->cursorcolor.pixel);
- TxtAddFont(win->display, win->messagewin, 1, win->large, win->textcolor.pixel);
- TxtAddFont(win->display, win->messagewin, 2, win->medium, win->errortext.pixel);
- TxtAddFont(win->display, win->messagewin, 3, win->medium, win->playertext.pixel);
-
- TxtWriteStr(win->display, win->messagewin, MESSAGE_HEADER);
- return;
-}
-
-void
-message_add(win, string, err)
- windata *win;
- char *string;
- bool err;
-{
- if (err) {
- TxtWriteStr(win->display, win->messagewin, "2");
- TxtWriteStr(win->display, win->messagewin, string);
- TxtWriteStr(win->display, win->messagewin, "0");
- XBell(win->display, 50);
- } else
- TxtWriteStr(win->display, win->messagewin, string);
-
- XSync(win->display, 0);
- return;
-}
-
-void
-message_send(win, event)
- windata *win;
- XEvent *event;
-{
- XKeyEvent *ev = &event->xkey;
- KeySym keysym;
- windata *ow = (win == win1) ? win2 : win1;
- char buf[BSIZE], *s;
- int i;
-
- i = XLookupString(ev, buf, sizeof(buf) - 1, &keysym, &s);
- buf[i] = '\0';
- for (s = buf; *s; s++)
- if (*s == '\r')
- *s = '\n';
- else if (*s == '\177')
- *s = '';
-
- TxtWriteStr(win->display, win->messagewin, "3");
- TxtWriteStr(win->display, win->messagewin, buf);
- TxtWriteStr(win->display, win->messagewin, "0");
- XSync(win->display, 0);
- if (ow) {
- TxtWriteStr(ow->display, ow->messagewin, "3");
- TxtWriteStr(ow->display, ow->messagewin, buf);
- TxtWriteStr(ow->display, ow->messagewin, "0");
- XSync(ow->display, 0);
- }
- return;
-}
-
diff --git a/gnu/games/chess/Xchess/parse.c b/gnu/games/chess/Xchess/parse.c
deleted file mode 100644
index 2dd94ed..0000000
--- a/gnu/games/chess/Xchess/parse.c
+++ /dev/null
@@ -1,386 +0,0 @@
-/* This file contains code for X-CHESS.
- Copyright (C) 1986 Free Software Foundation, Inc.
-
-This file is part of X-CHESS.
-
-X-CHESS is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY. No author or distributor
-accepts responsibility to anyone for the consequences of using it
-or for whether it serves any particular purpose or works at all,
-unless he says so in writing. Refer to the X-CHESS General Public
-License for full details.
-
-Everyone is granted permission to copy, modify and redistribute
-X-CHESS, but only under the conditions described in the
-X-CHESS General Public License. A copy of this license is
-supposed to have been given to you along with X-CHESS so you
-can know your rights and responsibilities. It should be in a
-file named COPYING. Among other things, the copyright notice
-and this notice must be preserved on all copies. */
-
-
-/* RCS Info: $Revision: 1.1.1.1 $ on $Date: 1993/06/12 14:41:06 $
- * $Source: /home/ncvs/src/gnu/games/chess/Xchess/parse.c,v $
- * Copyright (c) 1986 Wayne A. Christopher, U. C. Berkeley CAD Group
- * Permission is granted to do anything with this code except sell it
- * or remove this message.
- *
- * Parse a sequence of chess moves...
- */
-
-#include "xchess.h"
-
-bool loading_flag = false;
-bool loading_paused = false;
-
-static char *line;
-
-/* Load a record file in. This returns a number of things -- the board, the
- * list of moves, and whose turn it is.
- */
-
-void
-load_game(file)
- char *file;
-{
- FILE *fp;
- char buf[BSIZE];
- bool eflag;
- move *m;
- board *tmpboard = alloc(board);
-
- if (eq(file, "xchess.game") && saveflag) {
- message_add(win1,
- "Oops, I just overwrote the\nfile xchess.game...\n",
- true);
- message_add(win1, "I hope you had another copy.\n", true);
- return;
- }
- if (!(fp = fopen(file, "r"))) {
- perror(file);
- return;
- }
-
- /* Get a few lines... */
- fgets(buf, BSIZE, fp);
- message_add(win1, buf, false);
- if (!oneboard)
- message_add(win2, buf, false);
-
- fgets(buf, BSIZE, fp);
- message_add(win1, buf, false);
- if (!oneboard)
- message_add(win2, buf, false);
-
- fgets(buf, BSIZE, fp);
- if (eq(buf, "\tenglish\n"))
- eflag = true;
- else if (eq(buf, "\talgebraic\n"))
- eflag = false;
- else {
- fprintf(stderr, "Can't decide whether this is english...\n");
- return;
- }
-
- board_init(tmpboard);
- line = NULL;
- m = parse_file(fp, tmpboard, eflag);
- tfree(tmpboard);
-
- /* Now apply these moves to the board we were given... */
- loading_flag = true;
- while (m) {
- if (!quickflag)
- XSync(win1->display, 0);
- win_process(true);
- if (!quickflag)
- sleep(1);
- if (!loading_paused) {
- prog_move(m);
- m = m->next;
- }
- }
- loading_flag = false;
- if (line)
- message_add(win1, line, false);
-
- while (fgets(buf, BSIZE, fp))
- message_add(win1, buf, false);
-
- fclose(fp);
-
- return;
-}
-
-/* Given a starting position (usually the beginning board configuration),
- * read in a file of moves.
- */
-
-move *
-parse_file(fp, b, english)
- FILE *fp;
- board *b;
- bool english;
-{
- move *mvs = NULL, *end = NULL;
- char buf[BSIZE], *s, *t;
-
- while (fgets(buf, BSIZE, fp)) {
- if (*buf == '#')
- continue;
- s = buf;
-
- /* The move number... */
- if (!(t = gettok(&s)))
- break;
- if (!isdigit(*t)) {
- line = copy(buf);
- break;
- }
-
- if (!(t = gettok(&s)))
- break;
- if (end)
- end = end->next = (english ? parse_move(b, t, WHITE) :
- parse_imove(b, t, WHITE));
- else
- mvs = end = (english ? parse_move(b, t, WHITE) :
- parse_imove(b, t, WHITE));
- if (!end) {
- fprintf(stderr, "Can't parse %s\n", buf);
- return (NULL);
- }
- board_move(b, end);
-
- if (!(t = gettok(&s)))
- break;
- if (end)
- end = end->next = (english ? parse_move(b, t, BLACK) :
- parse_imove(b, t, BLACK));
- else
- mvs = end = (english ? parse_move(b, t, BLACK) :
- parse_imove(b, t, BLACK));
- if (!end) {
- fprintf(stderr, "Can't parse %s\n", buf);
- return (NULL);
- }
- board_move(b, end);
- }
-
- return (mvs);
-}
-
-/* Parse a move. The move format accepted is as follows -
- * move: spec-spec
- * capture: specxspec
- * kcastle: 2 o's
- * qcastle: 3 o's
- * A spec is either piece/pos, piece, or just pos. A pos consists of a column
- * name followed by a row number. If the column name is kr, kn, kb, k, q,
- * qb, qn, or qr, then the row number is according to the english system,
- * or if it is a-h then it is according to the international system.
- *
- *** As of now the spec must include the position.
- */
-
-move *
-parse_move(b, str, w)
- board *b;
- char *str;
- color w;
-{
- move *m = alloc(move);
- char *s;
- char spec1[16], spec2[16];
- int i, j;
-
-if (debug) fprintf(stderr, "parsing %s\n", str);
-
- /* Check for castles. */
- for (s = str, i = 0; *s; s++)
- if ((*s == 'o') || (*s == 'O'))
- i++;
- if (i == 2) {
- m->type = KCASTLE;
- m->piece.type = KING;
- m->piece.color = w;
- return (m);
- } else if (i == 3) {
- m->type = QCASTLE;
- m->piece.type = KING;
- m->piece.color = w;
- return (m);
- }
- if (index(str, '-'))
- m->type = MOVE;
- else if (index(str, 'x'))
- m->type = CAPTURE;
- else
- return (NULL);
- for (i = 0; str[i]; i++)
- if ((str[i] == 'x') || (str[i] == '-'))
- break;
- else
- spec1[i] = str[i];
- spec1[i] = '\0';
- for (i++, j = 0; str[i]; i++, j++)
- if ((str[i] == 'x') || (str[i] == '-'))
- break;
- else
- spec2[j] = str[i];
- spec2[j] = '\0';
-
- /* Now decode the specifications. */
- s = spec1;
- switch (*s) {
- case 'p': case 'P':
- m->piece.type = PAWN; break;
- case 'r': case 'R':
- m->piece.type = ROOK; break;
- case 'n': case 'N':
- m->piece.type = KNIGHT; break;
- case 'b': case 'B':
- m->piece.type = BISHOP; break;
- case 'q': case 'Q':
- m->piece.type = QUEEN; break;
- case 'k': case 'K':
- m->piece.type = KING; break;
- default:
- return (NULL);
- }
- m->piece.color = w;
- s += 2;
-
- /* Now get the {q,k}{,b,n,r}n string... */
- if ((s[0] == 'q') && (s[1] == 'r'))
- m->fromx = 0, s += 2;
- else if ((s[0] == 'q') && (s[1] == 'n'))
- m->fromx = 1, s += 2;
- else if ((s[0] == 'q') && (s[1] == 'b'))
- m->fromx = 2, s += 2;
- else if ((s[0] == 'q') && isdigit(s[1]))
- m->fromx = 3, s += 1;
- else if ((s[0] == 'k') && isdigit(s[1]))
- m->fromx = 4, s += 1;
- else if ((s[0] == 'k') && (s[1] == 'b'))
- m->fromx = 5, s += 2;
- else if ((s[0] == 'k') && (s[1] == 'n'))
- m->fromx = 6, s += 2;
- else if ((s[0] == 'k') && (s[1] == 'r'))
- m->fromx = 7, s += 2;
- m->fromy = ((w == WHITE) ? (SIZE - atoi(s)) : (atoi(s) - 1));
-
- if ((b->square[m->fromy][m->fromx].color != w) ||
- (b->square[m->fromy][m->fromx].type != m->piece.type)) {
- fprintf(stderr, "Error: bad stuff\n");
- return (NULL);
- }
-
- s = spec2;
- if (m->type == CAPTURE) {
- switch (*s) {
- case 'p': case 'P':
- m->taken.type = PAWN; break;
- case 'r': case 'R':
- m->taken.type = ROOK; break;
- case 'n': case 'N':
- m->taken.type = KNIGHT; break;
- case 'b': case 'B':
- m->taken.type = BISHOP; break;
- case 'q': case 'Q':
- m->taken.type = QUEEN; break;
- case 'k': case 'K':
- m->taken.type = KING; break;
- default:
- return (NULL);
- }
- m->taken.color = ((w == WHITE) ? BLACK : WHITE);
- s += 2;
- }
-
- /* Now get the {q,k}{,b,n,r}n string... */
- if ((s[0] == 'q') && (s[1] == 'r'))
- m->tox = 0, s += 2;
- else if ((s[0] == 'q') && (s[1] == 'n'))
- m->tox = 1, s += 2;
- else if ((s[0] == 'q') && (s[1] == 'b'))
- m->tox = 2, s += 2;
- else if ((s[0] == 'q') && isdigit(s[1]))
- m->tox = 3, s += 1;
- else if ((s[0] == 'k') && isdigit(s[1]))
- m->tox = 4, s += 1;
- else if ((s[0] == 'k') && (s[1] == 'b'))
- m->tox = 5, s += 2;
- else if ((s[0] == 'k') && (s[1] == 'n'))
- m->tox = 6, s += 2;
- else if ((s[0] == 'k') && (s[1] == 'r'))
- m->tox = 7, s += 2;
- m->toy = ((w == WHITE) ? (SIZE - atoi(s)) : (atoi(s) - 1));
-
- if ((m->type == CAPTURE) && ((b->square[m->toy][m->tox].color !=
- m->taken.color) || (b->square[m->toy][m->tox].type !=
- m->taken.type))) {
- fprintf(stderr, "Error: bad stuff\n");
- return (NULL);
- }
-
- return (m);
-}
-
-/* Parse an algebraic notation move. This is a lot easier... */
-
-move *
-parse_imove(b, buf, w)
- board *b;
- char *buf;
- color w;
-{
- char *s;
- move *m = alloc(move);
- int n;
-
-if (debug) fprintf(stderr, "(alg) parsing %s\n", buf);
-
- for (s = buf, n = 0; *s; s++)
- if ((*s == 'o') || (*s == 'O'))
- n++;
- s = buf;
-
- if (n == 2)
- m->type = KCASTLE;
- else if (n == 3)
- m->type = QCASTLE;
- else {
- m->fromx = *s++ - 'a';
- m->fromy = SIZE - (*s++ - '0');
- m->tox = *s++ - 'a';
- m->toy = SIZE - (*s++ - '0');
- m->piece = b->square[m->fromy][m->fromx];
- m->taken = b->square[m->toy][m->tox];
- if (m->taken.color == NONE)
- m->type = MOVE;
- else
- m->type = CAPTURE;
- /* for pawns we must account for en passant */
- if (m->piece.type == PAWN) {
- if (m->type == MOVE && m->fromx != m->tox) {
- m->enpassant = 1;
- m->type = CAPTURE;
- }
- }
- }
-
- if (m->piece.color != w) {
- fprintf(stderr, "Error: parse_imove: piece of wrong color!\n");
- return (NULL);
- }
- if ((m->piece.type == KING) && (m->fromy == m->toy) && (m->fromx == 4)
- && (m->tox == 6))
- m->type = KCASTLE;
- else if ((m->piece.type == KING) && (m->fromy == m->toy) &&
- (m->fromx == 4) && (m->tox == 2))
- m->type = QCASTLE;
-
- return (m);
-}
-
diff --git a/gnu/games/chess/Xchess/popup.c b/gnu/games/chess/Xchess/popup.c
deleted file mode 100644
index 0995638..0000000
--- a/gnu/games/chess/Xchess/popup.c
+++ /dev/null
@@ -1,112 +0,0 @@
-
-/* This file contains code for X-CHESS.
- Copyright (C) 1986 Free Software Foundation, Inc.
-
-This file is part of X-CHESS.
-
-X-CHESS is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY. No author or distributor
-accepts responsibility to anyone for the consequences of using it
-or for whether it serves any particular purpose or works at all,
-unless he says so in writing. Refer to the X-CHESS General Public
-License for full details.
-
-Everyone is granted permission to copy, modify and redistribute
-X-CHESS, but only under the conditions described in the
-X-CHESS General Public License. A copy of this license is
-supposed to have been given to you along with X-CHESS so you
-can know your rights and responsibilities. It should be in a
-file named COPYING. Among other things, the copyright notice
-and this notice must be preserved on all copies. */
-
-
-/* RCS Info: $Revision: 1.1.1.1 $ on $Date: 1993/06/12 14:41:13 $
- * $Source: /home/ncvs/src/gnu/games/chess/Xchess/popup.c,v $
- * Copyright (c) 1986 Wayne A. Christopher, U. C. Berkeley CAD Group
- * faustus@cad.berkeley.edu, ucbvax!faustus
- * Permission is granted to modify and re-distribute this code in any manner
- * as long as this notice is preserved. All standard disclaimers apply.
- *
- * A simple pop-up menu system.
- */
-
-#include "xchess.h"
-
-/* Open a small window with some text in it and two buttons -- yes and no.
- * Use black and white pixel, and the medium font.
- */
-
-bool
-pop_question(win, text)
- windata *win;
- char *text;
-{
- char *s, *t;
- int nlines = 1, ncols = 0, i = 0, j;
- int x, y;
- Window w;
- bool ch;
- XEvent ev;
-
- for (s = text; *s; s++) {
- if ((*s == '\n') && s[1])
- nlines++;
- if ((*s == '\n') || !s[1]) {
- if (i > ncols)
- ncols = i;
- i = 0;
- } else
- i++;
- }
-
- if (ncols < 12)
- ncols = 12;
- nlines += 4;
- ncols += 4;
-
- x = (BASE_WIDTH - ncols * win->medium->max_bounds.width) / 2;
- y = (BASE_HEIGHT - nlines * win->medium->max_bounds.ascent) / 2;
-
- w = XCreateSimpleWindow(win->display, win->basewin,
- x, y, ncols * win->medium->max_bounds.width,
- nlines * win->medium->ascent,
- BORDER_WIDTH, win->border.pixel,
- win->textback.pixel);
- XMapRaised(win->display, w);
- XSetFont(win->display, DefaultGC(win->display, 0),
- win->medium->fid);
-
- for (i = 0, s = text; i < nlines - 4; i++) {
- for (t = s, j = 0; *t && (*t != '\n'); t++, j++)
- ;
- XDrawString(win->display, w, DefaultGC(win->display, 0),
- (ncols - j) / 2 * win->medium->max_bounds.width,
- (i + 1) * win->medium->ascent,
- s, j);
- s = t + 1;
- }
- XDrawString(win->display, w, DefaultGC(win->display, 0),
- (ncols - 8) * win->medium->max_bounds.width / 4,
- (nlines - 2) * win->medium->ascent,
- "YES", 3);
- XDrawString(win->display, w, DefaultGC(win->display, 0),
- (ncols - 4) * win->medium->max_bounds.width * 3 / 4,
- (nlines - 2) * win->medium->ascent,
- "NO", 2);
-
- XSync(win->display, 0);
- XSelectInput(win->display, w, ButtonPressMask);
- XWindowEvent(win->display, w, ButtonPressMask, &ev);
- x = ev.xkey.x;
- y = ev.xkey.y;
-
- if (x > ncols * win->medium->max_bounds.width / 2)
- ch = false;
- else
- ch = true;
-
- XDestroyWindow(win->display, w);
- XSync(win->display, 0);
- return (ch);
-}
-
diff --git a/gnu/games/chess/Xchess/program.c b/gnu/games/chess/Xchess/program.c
deleted file mode 100644
index e2eb186..0000000
--- a/gnu/games/chess/Xchess/program.c
+++ /dev/null
@@ -1,204 +0,0 @@
-
-/* This file contains code for X-CHESS.
- Copyright (C) 1986 Free Software Foundation, Inc.
-
-This file is part of X-CHESS.
-
-X-CHESS is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY. No author or distributor
-accepts responsibility to anyone for the consequences of using it
-or for whether it serves any particular purpose or works at all,
-unless he says so in writing. Refer to the X-CHESS General Public
-License for full details.
-
-Everyone is granted permission to copy, modify and redistribute
-X-CHESS, but only under the conditions described in the
-X-CHESS General Public License. A copy of this license is
-supposed to have been given to you along with X-CHESS so you
-can know your rights and responsibilities. It should be in a
-file named COPYING. Among other things, the copyright notice
-and this notice must be preserved on all copies. */
-
-
-/* RCS Info: $Revision: 1.3 $ on $Date: 1994/11/04 02:11:30 $
- * $Source: /home/ncvs/src/gnu/games/chess/Xchess/program.c,v $
- * Copyright (c) 1986 Wayne A. Christopher, U. C. Berkeley CAD Group
- * Permission is granted to do anything with this code except sell it
- * or remove this message.
- *
- * The interface to whichever chess playing program we are using...
- */
-
-#include "xchess.h"
-#include <signal.h>
-#include <sys/time.h>
-
-static int pid;
-static FILE *from;
-static FILE *to;
-static bool easy = 1;
-
-bool
-program_init(name)
- char *name;
-{
- int toprog[2], fromprog[2];
- char buf[BSIZE];
- char time[10];
- char moves[10];
-
- pipe(toprog);
- pipe(fromprog);
-
- if (!(pid = fork())) {
- /* Start up the program. */
- dup2(toprog[0], 0);
- dup2(fromprog[1], 1);
- close(toprog[0]);
- close(toprog[1]);
- close(fromprog[0]);
- close(fromprog[1]);
- sprintf (time, "%d", timeunit/60);
- sprintf (moves, "%d", movesperunit);
- if (proghost)
- execl("/usr/ucb/rsh", "rsh", proghost, name,
- moves, time,
- (char *) NULL);
- else
- execl(name, name, moves, time, (char *) NULL);
- perror(name);
- exit(1);
- }
-
- close(toprog[0]);
- close(fromprog[1]);
-
- from = fdopen(fromprog[0], "r");
- setbuf(from, NULL);
- to = fdopen(toprog[1], "w");
- setbuf(to, NULL);
-
- /* Get the first line... */
- fgets(buf, BSIZE, from);
- if (debug)
- fprintf(stderr, "program says %s", buf);
- if (blackflag) {
- fputs("switch\n", to);
- fflush(to);
- fgets(buf, BSIZE, from);
- if (debug)
- fprintf(stderr, "program says %s", buf);
- message_add(win1, "GNU Chess playing white\n", false);
- } else
- message_add(win1, "GNU Chess playing black\n", false);
-
- return (true);
-}
-
-void
-program_end()
-{
- fclose(from);
- fclose(to);
- kill(pid, SIGTERM);
- return;
-}
-
-void
-program_send(m)
- move *m;
-{
- char buf[BSIZE];
-
- if ((m->type == MOVE) || (m->type == CAPTURE))
- sprintf(buf, "%c%d%c%d\n", 'a' + m->fromx, SIZE - m->fromy,
- 'a' + m->tox, SIZE - m->toy);
- else if (m->type == KCASTLE)
- strcpy(buf, (m->piece.color == WHITE) ? "e1g1\n" : "e8g8\n");
- else if (m->type == QCASTLE)
- strcpy(buf, (m->piece.color == WHITE) ? "e1c1\n" : "e8c8\n");
-
- if (debug)
- fprintf(stderr, "sending program %s", buf);
- if (!easy)
- kill (pid, SIGINT);
-
- fputs(buf, to);
- fflush(to);
-
- /* One junk line... */
- fgets(buf, BSIZE, from);
- if (debug)
- fprintf(stderr, "program says %s", buf);
- return;
-}
-
-move *
-program_get()
-{
- int rfd = (1 << fileno(from)), wfd = 0, xfd = 0;
- static struct timeval notime = { 0, 0 };
- char buf[BSIZE], *s;
- move *m;
- int i;
-
- /* Do a poll... */
-
-#ifdef __FreeBSD__
- if (!(i = select(32, &rfd, &wfd, &xfd, &notime))) {
-#else
- if (!(i = select(32, &rfd, &wfd, &xfd, &notime)) &&
- !from->_cnt) { /* Bad stuff... */
-#endif
- if (debug)
- fprintf(stderr, "poll: nothing\n");
- return (NULL);
- }
- if (i == -1) {
- perror("select");
- return (NULL);
- }
-
- fgets(buf, BSIZE, from);
- if (*buf == '\n' || *buf == '\0') {
- message_add(win1, "program died", false);
- return (NULL);
- }
-
- if (debug)
- fprintf(stderr, "got from program %s", buf);
-
- for (s = buf; !isalpha(*s); s++)
- ;
- m = parse_imove(chessboard, s, nexttomove);
- if (m == NULL)
- return (NULL);
-
- if (!valid_move(m, chessboard)) {
- fprintf(stderr, "Error: move %s is invalid!!\n", buf);
- return (NULL);
- }
-
- /*
- fgets(buf, BSIZE, from);
- if (debug)
- fprintf(stderr, "program says %s", buf);
- */
- message_add(win1, buf, false);
- return (m);
-}
-
-void
-program_undo()
-{
- fputs("undo\n", to);
- return;
-}
-void
-program_easy (mode)
- bool mode;
-
-{
- fputs("easy\n", to);
- easy = mode;
-}
diff --git a/gnu/games/chess/Xchess/record.c b/gnu/games/chess/Xchess/record.c
deleted file mode 100644
index b2fcea1..0000000
--- a/gnu/games/chess/Xchess/record.c
+++ /dev/null
@@ -1,315 +0,0 @@
-
-/* This file contains code for X-CHESS.
- Copyright (C) 1986 Free Software Foundation, Inc.
-
-This file is part of X-CHESS.
-
-X-CHESS is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY. No author or distributor
-accepts responsibility to anyone for the consequences of using it
-or for whether it serves any particular purpose or works at all,
-unless he says so in writing. Refer to the X-CHESS General Public
-License for full details.
-
-Everyone is granted permission to copy, modify and redistribute
-X-CHESS, but only under the conditions described in the
-X-CHESS General Public License. A copy of this license is
-supposed to have been given to you along with X-CHESS so you
-can know your rights and responsibilities. It should be in a
-file named COPYING. Among other things, the copyright notice
-and this notice must be preserved on all copies. */
-
-
-/* RCS Info: $Revision: 1.1.1.1 $ on $Date: 1993/06/12 14:41:09 $
- * $Source: /home/ncvs/src/gnu/games/chess/Xchess/record.c,v $
- * Copyright (c) 1986 Wayne A. Christopher, U. C. Berkeley CAD Group
- * Permission is granted to do anything with this code except sell it
- * or remove this message.
- *
- * Deal with recording moves.
- */
-
-#include "xchess.h"
-
-#undef smartass
-
-bool record_english = true;
-char *record_file = DEF_RECORD_FILE;
-int movenum = 0;
-bool saveflag = false;
-
-static char *colnames[] = { "qr", "qn", "qb", "q", "k", "kb", "kn", "kr" } ;
-static char *pcnames[] = { "P", "R", "N", "B", "Q", "K" } ;
-
-static char *movestring();
-static char *tstring();
-static FILE *backup;
-
-#define RECORD_HEADER "\n1 XChess Game Record0\n"
-
-void
-record_init(win)
- windata *win;
-{
- int i;
-
- i = XTextWidth(win->medium, RECORD_HEADER,
- sizeof(RECORD_HEADER) - 1);
- i = (40 * win->small->max_bounds.width - i *
- win->medium->max_bounds.width) /
- win->medium->max_bounds.width / 2;
- TxtGrab(win->display, win->recwin, "xchess", win->small, win->textback.pixel,
- win->textcolor.pixel, win->cursorcolor.pixel);
- TxtAddFont(win->display, win->recwin, 1, win->medium, win->textcolor.pixel);
- for (; i > 0; i++)
- TxtWriteStr(win->display, win->recwin, " ");
- TxtWriteStr(win->display, win->recwin, RECORD_HEADER);
-
- if (saveflag) {
- if (!(backup = fopen(record_file, "w"))) {
- perror(record_file);
- saveflag = false;
- } else {
- fprintf(backup, "X Chess -- %s\n", datestring());
- if (dispname2)
- fprintf(backup, "\tWhite on %s, black on %s\n",
- dispname1, dispname2);
- else
- fprintf(backup, "\tGame played on %s\n",
- dispname1);
- fprintf(backup, "\t%s\n", record_english ? "english" :
- "algebraic");
- fflush(backup);
- }
- }
-
- movenum = 0;
- return;
-}
-
-void
-record_reset()
-{
- TxtWriteStr(win1->display, win1->recwin, "\n\n1 New Game0\n\n");
- if (!oneboard) {
- TxtWriteStr(win2->display, win2->recwin, "\n\n1 New Game0\n\n");
- }
- movenum = 0;
- if (saveflag) {
- fprintf(backup, "\n\nNew Game\n\n");
- fflush(backup);
- }
- return;
-}
-
-void
-record_end(s)
- char *s;
-{
- char buf[BSIZE];
-
- sprintf(buf, "\n%s\n", s);
- TxtWriteStr(win1->display, win1->recwin, s);
- if (!oneboard) {
- TxtWriteStr(win2->display, win2->recwin, s);
- }
- if (saveflag) {
- fprintf(backup, "\n%s\n", s);
- fprintf(backup, "Time: white: %s, ", tstring(whiteseconds));
- fprintf(backup, "black: %s\n", tstring(blackseconds));
- fclose(backup);
- }
- return;
-}
-
-void
-record_save()
-{
- move *m;
- FILE *fp;
- int i;
- char *s;
-
- if (!(fp = fopen(record_file, "w"))) {
- perror(record_file);
- return;
- }
- fprintf(fp, "X Chess -- %s\n", datestring());
- if (dispname2)
- fprintf(fp, "\tWhite on %s, black on %s\n",
- dispname1, dispname2);
- else
- fprintf(fp, "\tGame played on %s\n", dispname1);
- fprintf(fp, "\t%s\n", record_english ? "english" : "algebraic");
-
- for (m = moves, i = 1; m; i++) {
- s = movestring(m);
- fprintf(fp, "%2d. %-16s ", i, s);
- m = m->next;
- if (m)
- s = movestring(m);
- else
- s = "";
- fprintf(fp, "%s\n", s);
- if (m)
- m = m->next;
- }
- fclose(fp);
- return;
-}
-
-void
-record_move(m)
- move *m;
-{
- char *s, buf[BSIZE];
-
- s = movestring(m);
-
- if (m->piece.color == WHITE) {
- movenum++;
- sprintf(buf, "%2d. %-16s ", movenum, s);
- } else {
- sprintf(buf, "%s\n", s);
- }
- TxtWriteStr(win1->display, win1->recwin, buf);
- if (!oneboard) {
- TxtWriteStr(win2->display, win2->recwin, buf);
- }
- if (saveflag) {
- fprintf(backup, "%s", buf);
- fflush(backup);
- }
-
- return;
-}
-
-void
-record_back()
-{
- extern move *lastmove;
- move *m = lastmove;
- char *s = movestring(m);
- char buf[BSIZE];
- long i;
-
- if (m->piece.color == WHITE) {
- sprintf(buf, "%2d. %-16s ", movenum, s);
- } else {
- sprintf(buf, "%s\n", s);
- }
- s = buf;
- for (i = 0; *s != '\0'; i++)
- *s++ = ''; /* control H, backspace */
-
- TxtWriteStr(win1->display, win1->recwin, buf);
- if (!oneboard) {
- TxtWriteStr(win2->display, win2->recwin, buf);
- }
-
- if (nexttomove == BLACK)
- movenum--;
- if (saveflag) {
- fseek(backup, -i, 1);
- fflush(backup);
- }
-
- return;
-}
-
-static char *
-movestring(m)
- move *m;
-{
- int fy, ty;
- static char buf[BSIZE];
-
- if (!record_english || (m->piece.color == WHITE)) {
- fy = SIZE - m->fromy;
- ty = SIZE - m->toy;
- } else {
- fy = m->fromy + 1;
- ty = m->toy + 1;
- }
-
- switch (m->type) {
- case MOVE:
- if (record_english)
- sprintf(buf, "%s/%s%d-%s%d%s", pcnames[(int) m->piece.
- type], colnames[m->fromx], fy,
- colnames[m->tox], ty, m->check ? "+" :
- "");
- else
- sprintf(buf, "%c%d%c%d", 'a' + m->fromx, fy, 'a' +
- m->tox, ty);
- break;
- case CAPTURE:
- if (record_english)
- sprintf(buf, "%s/%s%dx%s/%s%d%s%s",
- pcnames[(int) m->piece.type],
- colnames[m->fromx], fy,
- pcnames[(int) m->taken.type],
- colnames[m->tox], ty,
- m->enpassant ? "e.p." : "",
- m->check ? "+" : "");
- else
- sprintf(buf, "%c%d%c%d", 'a' + m->fromx, fy, 'a' +
- m->tox, ty);
- break;
-
- case KCASTLE:
- if (record_english)
- sprintf(buf, "O-O%s", m->check ? "ch" : "");
- else if (m->piece.color == WHITE)
- strcpy(buf, "e1g1");
- else
- strcpy(buf, "e8g8");
- break;
-
- case QCASTLE:
- if (record_english)
- sprintf(buf, "O-O-O%s", m->check ? "ch" : "");
- else if (m->piece.color == WHITE)
- strcpy(buf, "e1c1");
- else
- strcpy(buf, "e8c8");
- break;
-
- default:
- sprintf(buf, "something strange");
- break;
- }
- if ((m->piece.type == PAWN) && (((m->piece.color == BLACK) &&
- (m->toy == 7)) || ((m->piece.color == WHITE) &&
- (m->toy == 0))))
- strcat(buf, "(Q)");
-
-#ifdef smartass
- if (!(random() % 50))
- strcat(buf, "?");
- else if (!(random() % 50))
- strcat(buf, "!");
- else if (!(random() % 500))
- strcat(buf, "???");
- else if (!(random() % 500))
- strcat(buf, "!!!");
-#endif smartass
-
- return (buf);
-}
-
-static char *
-tstring(s)
- int s;
-{
- static char buf[64];
-
- if (s > 3600)
- sprintf(buf, "%dh %dm %ds", s / 3600, (s % 3600) / 60, s % 60);
- else if (s > 60)
- sprintf(buf, "%dm %ds", (s % 3600) / 60, s % 60);
- else
- sprintf(buf, "%ds", s);
- return (buf);
-}
-
diff --git a/gnu/games/chess/Xchess/scrollText.c b/gnu/games/chess/Xchess/scrollText.c
deleted file mode 100644
index b8484dd..0000000
--- a/gnu/games/chess/Xchess/scrollText.c
+++ /dev/null
@@ -1,1877 +0,0 @@
-/*
- * A Scrollable Text Output Window
- *
- * David Harrison
- * University of California, Berkeley
- * 1986
- *
- * The following is an implementation for a scrollable text output
- * system. It handles exposure events only (other interactions are
- * under user control). For scrolling, a always present scroll bar
- * is implemented. It detects size changes and compensates accordingly.
- */
-
-#include <X11/X.h>
-#include <X11/Xlib.h>
-#include <X11/X10.h>
-#include <sys/types.h>
-#include "scrollText.h"
-
-extern char *malloc();
-extern char *realloc();
-#define alloc(type) (type *) malloc(sizeof(type))
-#define numalloc(type, num) (type *) malloc((unsigned) (num * sizeof(type)))
-#define MAXINT 2147483647
-
-extern XAssocTable *XCreateAssocTable();
-extern caddr_t XLookUpAssoc();
-
-static XAssocTable *textWindows = (XAssocTable *) 0;
-
-#define NOOPTION -1 /* Option hasn't been set yet */
-#define NORMSCROLL 0 /* Smooth scroll on LineToTop and TopToHere */
-#define JUMPSCROLL 1 /* Jump scrolling on LineToTop and TopToHere */
-
-static int ScrollOption = NOOPTION;
-
-typedef char *Generic;
-
-#define DEFAULT_GC textInfo->fontGC[textInfo->curFont]
-
-#define BARSIZE 15
-#define BARBORDER 1
-#define MAXFONTS 8
-#define INITBUFSIZE 1024
-#define INITLINES 50
-#define INITEXPARY 50
-#define XPADDING 2
-#define YPADDING 2
-#define INTERLINE 5
-#define INTERSPACE 1
-#define CURSORWIDTH 2
-#define EXPANDPERCENT 40
-#define BUFSIZE 1024
-#define CUROFFSET 1
-#define MAXFOREIGN 250
-#define NOINDEX -1
-
-/* The wrap line indicator */
-#define WRAPINDSIZE 7
-#define STEMOFFSET 5
-#define arrow_width 7
-#define arrow_height 5
-static char arrow_bits[] = {
- 0x24, 0x26, 0x3f, 0x06, 0x04};
-
-#define NEWLINE '\n'
-#define BACKSPACE '\010'
-#define NEWFONT '\006'
-#define LOWCHAR '\040'
-#define HIGHCHAR '\176'
-
-#define CHARMASK 0x00ff /* Character mask */
-#define FONTMASK 0x0700 /* Character font */
-#define FONTSHIFT 8 /* Shift amount */
-
-#define WRAPFLAG 0x01 /* Line wrap flag */
-
-/*
- * Lines are represented by a pointer into the overall array of
- * 16-bit characters. The lower eight bits is used to indicate the character
- * (in ASCII), and the next two bits are used to indicate the font
- * the character should be drawn in.
- */
-
-typedef struct txtLine {
- int lineLength; /* Current line length */
- int lineHeight; /* Full height of line in pixels */
- int lineBaseLine; /* Current baseline of the line */
- int lineWidth; /* Drawing position at end of line */
- int lineText; /* Offset into master buffer */
- int lineFlags; /* Line wrap flag is here */
-};
-
-
-/*
- * For ExposeCopy events, we queue up the redraw requests collapsing
- * them into line redraw requests until the CopyExpose event arrives.
- * The queue is represented as a dynamic array of the following
- * structure:
- */
-
-typedef struct expEvent {
- int lineIndex; /* Index of line to redraw */
- int ypos; /* Drawing position of line */
-};
-
-
-/*
- * The text buffer is represented using a dynamic counted array
- * of 16-bit quantities. This array expands as needed.
- * For the screen representation, a dynamic counted array
- * of line structures is used. This array points into the
- * text buffer to denote the start of each line and its parameters.
- * The windows are configured as one overall window which contains
- * the scroll bar as a sub-window along its right edge. Thus,
- * the text drawing space is actually w-BARSIZE.
- */
-
-#define NOTATBOTTOM 0x01 /* Need to scroll to bottom before appending */
-#define FONTNUMWAIT 0x02 /* Waiting for font number */
-#define COPYEXPOSE 0x04 /* Need to process a copy expose event */
-#define SCREENWRONG 0x08 /* TxtJamStr has invalidated screen contents */
-
-typedef struct txtWin {
- /* Basic text buffer */
- int bufAlloc; /* Allocated size of buffer */
- int bufSpot; /* Current writing position in buffer */
- short *mainBuffer; /* Main buffer of text */
-
- /* Line information */
- int numLines; /* Number of display lines in buffer */
- int allocLines; /* Number of lines allocated */
- struct txtLine **txtBuffer; /* Dynamic array of lines */
-
- /* Current Window display information */
- Window mainWindow; /* Text display window */
- Window scrollBar; /* Subwindow for scroll bar */
- Pixmap arrowMap; /* line wrap indicator */
- int bgPix, fgPix; /* Background and cursor */
- GC CursorGC; /* gc for the cursor */
- GC bgGC; /* gc for erasing things */
- GC fontGC[MAXFONTS]; /* gc for doing fonts */
- XFontStruct theFonts[MAXFONTS];/* Display fonts */
- int theColors[MAXFONTS]; /* foregrounds of the fonts */
- int curFont; /* current font for tracking */
- int w, h; /* Current size */
- int startLine; /* Top line in display */
- int endLine; /* Bottom line in display */
- int bottomSpace; /* Space at bottom of screen */
- int flagWord; /* If non-zero, not at end */
-
- /* For handling ExposeCopy events */
- int exposeSize; /* Current size of array */
- int exposeAlloc; /* Allocated size */
- struct expEvent **exposeAry;/* Array of line indices */
-
- /* Drawing position information */
- int curLine; /* Current line in buffer */
- int curX; /* Current horizontal positi */
- int curY; /* Current vertical drawing */
-};
-
-/* Flags for the various basic character handling functions */
-
-#define DODISP 0x01 /* Update the display */
-#define NONEWLINE 0x02 /* Dont append newline */
-
-
-
-static int InitLine(newLine)
-struct txtLine *newLine; /* Newly created line structure */
-/*
- * This routine initializes a newly created line structure.
- */
-{
- newLine->lineLength = 0;
- newLine->lineHeight = 0;
- newLine->lineBaseLine = 0;
- newLine->lineWidth = XPADDING;
- newLine->lineText = NOINDEX;
- newLine->lineFlags = 0;
- return 1;
-}
-
-
-
-
-int TxtGrab(display, txtWin, program, mainFont, bg, fg, cur)
-Display *display; /* display window is on */
-Window txtWin; /* Window to take over as scrollable text */
-char *program; /* Program name for Xdefaults */
-XFontStruct *mainFont; /* Primary text font */
-int bg, fg, cur; /* Background, foreground, and cursor colors */
-/*
- * This routine takes control of 'txtWin' and makes it into a scrollable
- * text output window. It will create a sub-window for the scroll bar
- * with a background of 'bg' and an bar with color 'fg'. Both fixed width
- * and variable width fonts are supported. Additional fonts can be loaded
- * using 'TxtAddFont'. Returns 0 if there were problems, non-zero if
- * everything went ok.
- */
-{
- struct txtWin *newWin; /* Text package specific information */
- XWindowAttributes winInfo; /* Window information */
- int index;
- XGCValues gc_val;
-
- if (textWindows == (XAssocTable *) 0) {
- textWindows = XCreateAssocTable(32);
- if (textWindows == (XAssocTable *) 0) return(0);
- }
- if (XGetWindowAttributes(display, txtWin, &winInfo) == 0) return 0;
-
- if (ScrollOption == NOOPTION) {
- /* Read to see if the user wants jump scrolling or not */
- if (XGetDefault(display, program, "JumpScroll")) {
- ScrollOption = JUMPSCROLL;
- } else {
- ScrollOption = NORMSCROLL;
- }
- }
-
- /* Initialize local structure */
- newWin = alloc(struct txtWin);
-
- /* Initialize arrow pixmap */
- newWin->arrowMap = XCreatePixmapFromBitmapData(display, txtWin,
- arrow_bits,
- arrow_width, arrow_height,
- cur, bg,
- DisplayPlanes(display, 0));
-
- newWin->bufAlloc = INITBUFSIZE;
- newWin->bufSpot = 0;
- newWin->mainBuffer = numalloc(short, INITBUFSIZE);
-
- newWin->numLines = 1;
- newWin->allocLines = INITLINES;
- newWin->txtBuffer = numalloc(struct txtLine *, INITLINES);
- for (index = 0; index < INITLINES; index++) {
- newWin->txtBuffer[index] = alloc(struct txtLine);
- InitLine(newWin->txtBuffer[index]);
- }
-
- /* Window display information */
- newWin->mainWindow = txtWin;
- newWin->w = winInfo.width;
- newWin->h = winInfo.height;
- newWin->startLine = 0;
- newWin->endLine = 0;
- newWin->bottomSpace = winInfo.height
- - YPADDING - mainFont->ascent - mainFont->descent - INTERLINE;
- newWin->flagWord = 0;
- newWin->bgPix = bg;
- newWin->fgPix = fg;
-
- /* Scroll Bar Creation */
- newWin->scrollBar = XCreateSimpleWindow(display, txtWin,
- winInfo.width - BARSIZE,
- 0, BARSIZE - (2*BARBORDER),
- winInfo.height - (2*BARBORDER),
- BARBORDER,
- fg, bg);
- XSelectInput(display, newWin->scrollBar, ExposureMask|ButtonReleaseMask);
- XMapRaised(display, newWin->scrollBar);
-
- /* Font and Color Initialization */
- newWin->theFonts[0] = *mainFont;
- newWin->theColors[0] = fg;
- gc_val.function = GXcopy;
- gc_val.plane_mask = AllPlanes;
- gc_val.foreground = fg;
- gc_val.background = bg;
- gc_val.graphics_exposures = 1;
- gc_val.font = mainFont->fid;
- gc_val.line_width = 1;
- gc_val.line_style = LineSolid;
-
- newWin->fontGC[0] = XCreateGC(display, txtWin,
- GCFunction | GCPlaneMask |
- GCForeground | GCBackground |
- GCGraphicsExposures | GCFont,
- &gc_val);
-
- gc_val.foreground = cur;
- newWin->CursorGC = XCreateGC(display, txtWin,
- GCFunction | GCPlaneMask |
- GCForeground | GCBackground |
- GCLineStyle | GCLineWidth,
- &gc_val);
-
- gc_val.foreground = bg;
- newWin->bgGC = XCreateGC(display, txtWin,
- GCFunction | GCPlaneMask |
- GCForeground | GCBackground |
- GCGraphicsExposures | GCFont,
- &gc_val);
-
-
- for (index = 1; index < MAXFONTS; index++) {
- newWin->theFonts[index].fid = 0;
- newWin->fontGC[index] = 0;
- }
-
-
- /* Initialize size of first line */
- newWin->txtBuffer[0]->lineHeight = newWin->theFonts[0].ascent +
- newWin->theFonts[0].descent;
- newWin->txtBuffer[0]->lineText = 0;
-
- /* ExposeCopy array initialization */
- newWin->exposeSize = 0;
- newWin->exposeAlloc = INITEXPARY;
- newWin->exposeAry = numalloc(struct expEvent *, INITEXPARY);
- for (index = 0; index < newWin->exposeAlloc; index++)
- newWin->exposeAry[index] = alloc(struct expEvent);
- /* Put plus infinity in last slot for sorting purposes */
- newWin->exposeAry[0]->lineIndex = MAXINT;
-
- /* Drawing Position Information */
- newWin->curLine = 0;
- newWin->curX = 0;
- newWin->curY = YPADDING + mainFont->ascent + mainFont->descent;
-
- /* Attach it to both windows */
- XMakeAssoc(display, textWindows, (XID) txtWin, (caddr_t) newWin);
- XMakeAssoc(display, textWindows, (XID) newWin->scrollBar, (caddr_t) newWin);
- return 1;
-}
-
-
-int TxtRelease(display, w)
-Display *display;
-Window w; /* Window to release */
-/*
- * This routine releases all resources associated with the
- * specified window which are consumed by the text
- * window package. This includes the entire text buffer, line start
- * array, and the scroll bar window. However, the window
- * itself is NOT destroyed. The routine will return zero if
- * the window is not owned by the text window package.
- */
-{
- struct txtWin *textInfo;
- int index;
-
- if ((textInfo = (struct txtWin *) XLookUpAssoc(display,
- textWindows, (XID) w)) == 0)
- return 0;
-
- for (index = 0; index < MAXFONTS; index++)
- if (textInfo->fontGC[index] != 0)
- XFreeGC(display, textInfo->fontGC[index]);
-
- free((Generic) textInfo->mainBuffer);
- for (index = 0; index < textInfo->numLines; index++) {
- free((Generic) textInfo->txtBuffer[index]);
- }
- free((Generic) textInfo->txtBuffer);
- XDestroyWindow(display, textInfo->scrollBar);
- for (index = 0; index < textInfo->exposeSize; index++) {
- free((Generic) textInfo->exposeAry[index]);
- }
- free((Generic) textInfo->exposeAry);
- XDeleteAssoc(display, textWindows, (XID) w);
- free((Generic) textInfo);
- return 1;
-}
-
-
-
-static int RecompBuffer(textInfo)
-struct txtWin *textInfo; /* Text window information */
-/*
- * This routine recomputes all line breaks in a buffer after
- * a change in window size or font. This is done by throwing
- * away the old line start array and recomputing it. Although
- * a lot of this work is also done elsewhere, it has been included
- * inline here for efficiency.
- */
-{
- int startPos, endSize, linenum;
- register int index, chsize, curfont;
- register short *bufptr;
- register XFontStruct *fontptr;
- register struct txtLine *lineptr;
- char theChar;
-
- /* Record the old position so we can come back to it */
- for (startPos = textInfo->txtBuffer[textInfo->startLine]->lineText;
- (startPos > 0) && (textInfo->mainBuffer[startPos] != '\n');
- startPos--)
- /* null loop body */;
-
- /* Clear out the old line start array */
- for (index = 0; index < textInfo->numLines; index++) {
- InitLine(textInfo->txtBuffer[index]);
- }
-
- /* Initialize first line */
- textInfo->txtBuffer[0]->lineHeight =
- textInfo->theFonts[0].ascent + textInfo->theFonts[0].descent;
- textInfo->txtBuffer[0]->lineText = 0;
-
- /* Process the text back into lines */
- endSize = textInfo->w - BARSIZE - WRAPINDSIZE;
- bufptr = textInfo->mainBuffer;
- lineptr = textInfo->txtBuffer[0];
- linenum = 0;
- fontptr = &(textInfo->theFonts[0]);
- curfont = 0;
- for (index = 0; index < textInfo->bufSpot; index++) {
- theChar = bufptr[index] & CHARMASK;
-
- if ((bufptr[index] & FONTMASK) != curfont) {
- int newFontNum, heightDiff;
-
- /* Switch fonts */
- newFontNum = (bufptr[index] & FONTMASK) >> FONTSHIFT;
- if (textInfo->theFonts[newFontNum].fid != 0) {
- /* Valid font */
- curfont = bufptr[index] & FONTMASK;
- fontptr = &(textInfo->theFonts[newFontNum]);
- heightDiff = (fontptr->ascent + fontptr->descent) -
- lineptr->lineHeight;
- if (heightDiff < 0) heightDiff = 0;
- lineptr->lineHeight += heightDiff;
- }
- }
- if (theChar == '\n') {
- /* Handle new line */
- if (linenum >= textInfo->allocLines-1)
- /* Expand number of lines */
- ExpandLines(textInfo);
- linenum++;
- lineptr = textInfo->txtBuffer[linenum];
- /* Initialize next line */
- lineptr->lineHeight = fontptr->ascent + fontptr->descent;
- lineptr->lineText = index+1;
- /* Check to see if its the starting line */
- if (index == startPos) textInfo->startLine = linenum;
- } else {
- /* Handle normal character */
- chsize = CharSize(textInfo, linenum, index);
- if (lineptr->lineWidth + chsize > endSize) {
- /* Handle line wrap */
- lineptr->lineFlags |= WRAPFLAG;
- if (linenum >= textInfo->allocLines-1)
- /* Expand number of lines */
- ExpandLines(textInfo);
- linenum++;
- lineptr = textInfo->txtBuffer[linenum];
- /* Initialize next line */
- lineptr->lineHeight = fontptr->ascent + fontptr->descent;
- lineptr->lineText = index;
- lineptr->lineLength = 1;
- lineptr->lineWidth += chsize;
- } else {
- /* Handle normal addition of character */
- lineptr->lineLength += 1;
- lineptr->lineWidth += chsize;
- }
- }
- }
- /* We now have a valid line array. Let's clean up some other fields. */
- textInfo->numLines = linenum+1;
- if (startPos == 0) {
- textInfo->startLine = 0;
- }
- textInfo->endLine = FindEndLine(textInfo, &(textInfo->bottomSpace));
- textInfo->curLine = linenum;
- /* Check to see if we are at the bottom */
- if (textInfo->endLine >= textInfo->numLines-1) {
- textInfo->curY = textInfo->h - textInfo->bottomSpace -
- lineptr->lineHeight;
- textInfo->flagWord &= (~NOTATBOTTOM);
- } else {
- textInfo->flagWord |= NOTATBOTTOM;
- }
- return 1;
-}
-
-
-
-
-int TxtAddFont(display, textWin, fontNumber, newFont, newColor)
-Display *display;
-Window textWin; /* Scrollable text window */
-int fontNumber; /* Place to add font (0-7) */
-XFontStruct *newFont; /* Font to add */
-int newColor; /* Color of font */
-/*
- * This routine loads a new font so that it can be used in a previously
- * created text window. There are eight font slots numbered 0 through 7.
- * If there is already a font in the specified slot, it will be replaced
- * and an automatic redraw of the window will take place. See TxtWriteStr
- * for details on using alternate fonts. The color specifies the foreground
- * color of the text. The default foreground color is used if this
- * parameter is TXT_NO_COLOR. Returns a non-zero value if
- * everything went well.
- */
-{
- struct txtWin *textInfo;
- int redrawFlag;
- XGCValues gc_val;
-
- if ((fontNumber < 0) || (fontNumber >= MAXFONTS)) return 0;
- if ((textInfo = (struct txtWin *)
- XLookUpAssoc(display, textWindows, (XID) textWin)) == 0)
- return 0;
- if (newColor == TXT_NO_COLOR) {
- newColor = textInfo->fgPix;
- }
-
- gc_val.font = newFont->fid;
- gc_val.foreground = newColor;
- gc_val.background = textInfo->bgPix;
- gc_val.plane_mask = AllPlanes;
- gc_val.graphics_exposures = 1;
- gc_val.function = GXcopy;
-
- if (textInfo->fontGC[fontNumber] != 0)
- {
- XChangeGC(display, textInfo->fontGC[fontNumber],
- GCFont | GCForeground, &gc_val);
- }
- else
- textInfo->fontGC[fontNumber] = XCreateGC(display, textWin,
- GCFont |
- GCForeground |
- GCBackground |
- GCFunction |
- GCPlaneMask |
- GCGraphicsExposures,
- &gc_val);
-
-
- redrawFlag = (textInfo->theFonts[fontNumber].fid != 0) &&
- (((newFont) && (newFont->fid != textInfo->theFonts[fontNumber].fid)) ||
- (newColor != textInfo->theColors[fontNumber]));
- if (newFont) {
- textInfo->theFonts[fontNumber] = *newFont;
- }
- textInfo->theColors[fontNumber] = newColor;
-
- if (redrawFlag) {
- RecompBuffer(textInfo);
- XClearWindow(display, textWin);
- TxtRepaint(display, textWin);
- }
- return 1;
-}
-
-
-
-int TxtWinP(display, w)
-Display *display;
-Window w;
-/*
- * Returns a non-zero value if the window has been previously grabbed
- * using TxtGrab and 0 if it has not.
- */
-{
- if (XLookUpAssoc(display, textWindows, (XID) w))
- return(1);
- else return(0);
-}
-
-
-
-static int FindEndLine(textInfo, botSpace)
-struct txtWin *textInfo;
-int *botSpace;
-/*
- * Given the starting line in 'textInfo->startLine', this routine
- * determines the index of the last line that can be drawn given the
- * current size of the screen. If there are not enough lines to
- * fill the screen, the index of the last line will be returned.
- * The amount of empty bottom space is returned in 'botSpace'.
- */
-{
- int index, height, lineHeight;
-
- height = YPADDING;
- index = textInfo->startLine;
- while (index < textInfo->numLines) {
- lineHeight = textInfo->txtBuffer[index]->lineHeight + INTERLINE;
- if (height + lineHeight > textInfo->h) break;
- height += lineHeight;
- index++;
- }
- if (botSpace) {
- *botSpace = textInfo->h - height;
- }
- return index - 1;
-}
-
-
-
-static int UpdateScroll(display, textInfo)
-Display *display;
-struct txtWin *textInfo; /* Text window information */
-/*
- * This routine computes the current extent of the scroll bar
- * indicator and repaints the bar with the correct information.
- */
-{
- int top, bottom;
-
- if (textInfo->numLines > 1) {
- top = textInfo->startLine * (textInfo->h - 2*BARBORDER) /
- (textInfo->numLines - 1);
- bottom = textInfo->endLine * (textInfo->h - 2*BARBORDER) /
- (textInfo->numLines - 1);
- } else {
- top = 0;
- bottom = textInfo->h - (2*BARBORDER);
- }
-
- /* Draw it - make sure there is a little padding */
- if (top == 0) top++;
- if (bottom == textInfo->h-(2*BARBORDER)) bottom--;
-
- XFillRectangle(display, textInfo->scrollBar,
- textInfo->bgGC,
- 0, 0, BARSIZE, top-1);
-#ifdef __FreeBSD__
- XFillRectangle(display, textInfo->scrollBar,
- DEFAULT_GC, top, BARSIZE - (2*BARBORDER) - 2,
- BARSIZE, bottom - top);
-#else
- XFillRectangle(display, textInfo->scrollBar,
- DEFAULT_GC, top, BARSIZE - (2*BARBORDER) - 2,
- bottom - top);
-#endif
- XFillRectangle(display, textInfo->scrollBar, DEFAULT_GC,
- 0, bottom+1, BARSIZE,
- textInfo->h - (2 * BARBORDER) - bottom);
-
- return 1;
-}
-
-
-
-
-int TxtClear(display, w)
-Display *display;
-Window w;
-/*
- * This routine clears a scrollable text window. It resets the current
- * writing position to the upper left hand corner of the screen.
- * NOTE: THIS ALSO CLEARS THE CONTENTS OF THE TEXT WINDOW BUFFER AND
- * RESETS THE SCROLL BAR. Returns 0 if the window is not a text window.
- * This should be used *instead* of XClear.
- */
-{
- struct txtWin *textInfo;
- int index;
-
- if ((textInfo = (struct txtWin *) XLookUpAssoc(display, textWindows, (XID) w)) == 0)
- return 0;
-
- /* Zero out the arrays */
- textInfo->bufSpot = 0;
- for (index = 0; index < textInfo->numLines; index++) {
- InitLine(textInfo->txtBuffer[index]);
- }
- textInfo->txtBuffer[0]->lineHeight =
- textInfo->theFonts[textInfo->curFont].ascent +
- textInfo->theFonts[textInfo->curFont].descent;
-
- textInfo->numLines = 1;
- textInfo->startLine = 0;
- textInfo->endLine = 0;
- textInfo->curLine = 0;
- textInfo->curX = 0;
- textInfo->curY = YPADDING + textInfo->theFonts[textInfo->curFont].ascent
- + textInfo->theFonts[textInfo->curFont].descent;
-
- textInfo->bottomSpace = textInfo->h - YPADDING -
- textInfo->theFonts[textInfo->curFont].ascent - INTERLINE -
- textInfo->theFonts[textInfo->curFont].descent;
- /* Actually clear the window */
- XClearWindow(display, w);
-
- /* Draw the current cursor */
- XFillRectangle(display, w, textInfo->CursorGC,
- XPADDING + CUROFFSET, textInfo->curY,
- CURSORWIDTH,
- textInfo->theFonts[textInfo->curFont].ascent +
- textInfo->theFonts[textInfo->curFont].descent);
-
- /* Update the scroll bar */
- UpdateScroll(display, textInfo);
- return 1;
-}
-
-
-static int WarpToBottom(display, textInfo)
-Display *display;
-struct txtWin *textInfo; /* Text Information */
-/*
- * This routine causes the specified text window to display its
- * last screen of information. It updates the scroll bar
- * to the appropriate spot. The implementation scans backward
- * through the buffer to find an appropriate starting spot for
- * the window.
- */
-{
- int index, height, lineHeight;
-
- index = textInfo->numLines-1;
- height = 0;
- while (index >= 0) {
- lineHeight = textInfo->txtBuffer[index]->lineHeight + INTERLINE;
- if (height + lineHeight > textInfo->h) break;
- height += lineHeight;
- index--;
- }
- textInfo->startLine = index + 1;
- textInfo->endLine = FindEndLine(textInfo, &(textInfo->bottomSpace));
- textInfo->curY = textInfo->h - textInfo->bottomSpace -
- textInfo->txtBuffer[textInfo->endLine]->lineHeight;
- XClearWindow(display, textInfo->mainWindow);
- TxtRepaint(display, textInfo->mainWindow);
- return 1;
-}
-
-
-
-static int UpdateExposures(display, textInfo)
-Display *display;
-struct txtWin *textInfo; /* Text window information */
-/*
- * Before a new scrolling action occurs, the text window package
- * must handle all COPYEXPOSE events generated by the last scrolling
- * action. This routine is called to do this. Foreign events (those
- * not handled by TxtFilter) are queued up and replaced on the queue
- * after the processing of the exposure events is complete.
- */
-{
-#if 0
- XEvent foreignQueue[MAXFOREIGN];
- int index, lastItem = 0;
-
- while (textInfo->flagWord & COPYEXPOSE) {
- XNextEvent(display, &(foreignQueue[lastItem]));
- if (!TxtFilter(display, &(foreignQueue[lastItem])))
- lastItem++;
- if (lastItem >= MAXFOREIGN) {
- printf("Too many foreign events to queue!\n");
- textInfo->flagWord &= (~COPYEXPOSE);
- }
- }
- for (index = 0; index < lastItem; index++) {
- XPutBackEvent(display, &(foreignQueue[index]));
- }
-#endif
- return 1;
-}
-
-
-static int ScrollDown(display,textInfo)
-Display *display;
-struct txtWin *textInfo; /* Text window information */
-/*
- * This routine scrolls the indicated text window down by one
- * line. The line below the current line must exist. The window
- * is scrolled so that the line below the last line is fully
- * displayed. This may cause many lines to scroll off the top.
- * Scrolling is done using XCopyArea. The exposure events should
- * be caught using ExposeCopy.
- */
-{
- int lineSum, index, targetSpace, freeSpace, updateFlag;
-
- lineSum = 0;
- if (textInfo->endLine + 1 >= textInfo->numLines) return 0;
- targetSpace = textInfo->txtBuffer[textInfo->endLine+1]->lineHeight +
- INTERLINE;
- if (textInfo->bottomSpace < targetSpace) {
- index = textInfo->startLine;
- while (index < textInfo->endLine) {
- lineSum += (textInfo->txtBuffer[index]->lineHeight + INTERLINE);
- if (textInfo->bottomSpace + lineSum >= targetSpace) break;
- index++;
- }
-
- /* Must move upward by 'lineSum' pixels */
- XCopyArea(display, textInfo->mainWindow, textInfo->mainWindow,
- DEFAULT_GC, 0, lineSum,
- textInfo->w - BARSIZE, textInfo->h,
- 0, 0);
-
- textInfo->flagWord |= COPYEXPOSE;
- /* Repair the damage to the structures */
- textInfo->startLine = index + 1;
- updateFlag = 1;
- } else {
- updateFlag = 0;
- }
- /* More lines might be able to fit. Let's check. */
- freeSpace = textInfo->bottomSpace + lineSum - targetSpace;
- index = textInfo->endLine + 1;
- while (index < textInfo->numLines-1) {
- if (freeSpace - textInfo->txtBuffer[index+1]->lineHeight - INTERLINE < 0)
- break;
- freeSpace -= (textInfo->txtBuffer[index+1]->lineHeight + INTERLINE);
- index++;
- }
- textInfo->endLine = index;
- textInfo->bottomSpace = freeSpace;
- if (updateFlag) {
- UpdateExposures(display, textInfo);
- }
- UpdateScroll(display, textInfo);
- return 1;
-}
-
-
-
-
-static int ExpandLines(textInfo)
-struct txtWin *textInfo; /* Text Information */
-/*
- * This routine allocates and initializes additional space in
- * the line start array (txtBuffer). The new space
- * is allocated using realloc. The expansion factor is a percentage
- * given by EXPANDPERCENT.
- */
-{
- int newSize, index;
-
- newSize = textInfo->allocLines;
- newSize += (newSize * EXPANDPERCENT) / 100;
-
- textInfo->txtBuffer = (struct txtLine **)
- realloc((char *) textInfo->txtBuffer,
- (unsigned) (newSize * sizeof(struct txtLine *)));
- for (index = textInfo->allocLines; index < newSize; index++) {
- textInfo->txtBuffer[index] = alloc(struct txtLine);
- InitLine(textInfo->txtBuffer[index]);
- }
- textInfo->allocLines = newSize;
- return 1;
-}
-
-static int ExpandBuffer(textInfo)
-struct txtWin *textInfo; /* Text information */
-/*
- * Expands the basic character buffer using realloc. The expansion
- * factor is a percentage given by EXPANDPERCENT.
- */
-{
- int newSize;
-
- newSize = textInfo->bufAlloc + (textInfo->bufAlloc * EXPANDPERCENT) / 100;
- textInfo->mainBuffer = (short *)
- realloc((char *) textInfo->mainBuffer, (unsigned) newSize * sizeof(short));
- textInfo->bufAlloc = newSize;
- return 1;
-}
-
-
-
-static int HandleNewLine(display, textInfo, flagWord)
-Display *display;
-struct txtWin *textInfo; /* Text Information */
-int flagWord; /* DODISP or NONEWLINE or both */
-/*
- * This routine initializes the next line for drawing by setting
- * its height to the current font height, scrolls the screen down
- * one line, and updates the current drawing position to the
- * left edge of the newly cleared line. If DODISP is specified,
- * the screen will be updated (otherwise not). If NONEWLINE is
- * specified, no newline character will be added to the text buffer
- * (this is for line wrap).
- */
-{
- struct txtLine *curLine, *nextLine;
-
- /* Check to see if a new line must be allocated */
- if (textInfo->curLine >= textInfo->allocLines-1)
- /* Expand the number of lines */
- ExpandLines(textInfo);
- textInfo->numLines += 1;
-
- /* Then we initialize the next line */
- nextLine = textInfo->txtBuffer[textInfo->numLines-1];
- nextLine->lineHeight =
- textInfo->theFonts[textInfo->curFont].ascent +
- textInfo->theFonts[textInfo->curFont].descent;
-
- curLine = textInfo->txtBuffer[textInfo->curLine];
- if (flagWord & DODISP) {
- /* Scroll down a line if required */
- if ((textInfo->curY + curLine->lineHeight +
- nextLine->lineHeight + (INTERLINE * 2)) > textInfo->h)
- {
- ScrollDown(display, textInfo);
- }
- else
- {
- /* Update the bottom space appropriately */
- textInfo->bottomSpace -= (nextLine->lineHeight + INTERLINE);
- textInfo->endLine += 1;
- }
- /* Update drawing position */
- textInfo->curY = textInfo->h -
- (textInfo->bottomSpace + nextLine->lineHeight);
- }
-
- /* Move down a line */
- textInfo->curLine += 1;
- if (!(flagWord & NONEWLINE)) {
- /* Append end-of-line to text buffer */
- if (textInfo->bufSpot >= textInfo->bufAlloc) {
- /* Allocate more space in main text buffer */
- ExpandBuffer(textInfo);
- }
- textInfo->mainBuffer[(textInfo->bufSpot)++] =
- (textInfo->curFont << FONTSHIFT) | '\n';
- }
- nextLine->lineText = textInfo->bufSpot;
- textInfo->curX = 0;
- return 1;
-}
-
-
-
-static int CharSize(textInfo, lineNum, charNum)
-struct txtWin *textInfo; /* Current Text Information */
-int lineNum; /* Line in buffer */
-int charNum; /* Character in line */
-/*
- * This routine determines the size of the specified character.
- * It takes in account the font of the character and whether its
- * fixed or variable. The size includes INTERSPACE spacing between
- * the characters.
- */
-{
- register XFontStruct *charFont;
- register short *theLine;
- register short theChar;
-
- theLine = &(textInfo->mainBuffer[textInfo->txtBuffer[lineNum]->lineText]);
- theChar = theLine[charNum] & CHARMASK;
- charFont = &(textInfo->theFonts[(theChar & FONTMASK) >> FONTSHIFT]);
- if (theChar <= charFont->min_char_or_byte2 ||
- theChar >= charFont->max_char_or_byte2 ||
- charFont->per_char == 0)
- return charFont->max_bounds.width + 1;
- else
- return charFont->per_char[theChar].width + 1;
-}
-
-
-
-
-
-static int HandleBackspace(display, textInfo, flagWord)
-Display *display;
-struct txtWin *textInfo; /* Text Information */
-int flagWord; /* DODISP or nothing */
-/*
- * This routine handles a backspace found in the input stream. The
- * character before the current writing position will be erased and
- * the drawing position will move back one character. If the writing
- * position is at the left margin, the drawing position will move
- * up to the previous line. If it is a line that has been wrapped,
- * the character at the end of the previous line will be erased.
- */
-{
- struct txtLine *thisLine, *prevLine;
- int chSize;
-
- thisLine = textInfo->txtBuffer[textInfo->curLine];
- /* First, determine whether we need to go back a line */
- if (thisLine->lineLength == 0) {
- /* Bleep if at top of buffer */
- if (textInfo->curLine == 0) {
- XBell(display, 50);
- return 0;
- }
-
- /* See if we have to scroll in the other direction */
- if ((flagWord & DODISP) && (textInfo->curY <= YPADDING)) {
- /* This will display the last lines of the buffer */
- WarpToBottom(display, textInfo);
- }
-
- /* Set drawing position at end of previous line */
- textInfo->curLine -= 1;
- prevLine = textInfo->txtBuffer[textInfo->curLine];
- textInfo->numLines -= 1;
- if (flagWord & DODISP) {
- textInfo->curY -= (prevLine->lineHeight + INTERLINE);
- textInfo->bottomSpace += (thisLine->lineHeight + INTERLINE);
- textInfo->endLine -= 1;
- }
-
- /* We are unlinewrapping if the previous line has flag set */
- if (prevLine->lineFlags & WRAPFLAG) {
- /* Get rid of line wrap indicator */
- if (flagWord & DODISP) {
- XFillRectangle(display, textInfo->mainWindow,
- textInfo->bgGC,
- textInfo->w - BARSIZE - WRAPINDSIZE,
- textInfo->curY, WRAPINDSIZE,
- prevLine->lineHeight);
- }
- prevLine->lineFlags &= (~WRAPFLAG);
- /* Call recursively to wipe out the ending character */
- HandleBackspace(display, textInfo, flagWord);
- } else {
- /* Delete the end-of-line in the primary buffer */
- textInfo->bufSpot -= 1;
- }
- } else {
- /* Normal deletion of character */
- chSize =
- CharSize(textInfo, textInfo->curLine,
- textInfo->txtBuffer[textInfo->curLine]->lineLength - 1);
- /* Move back appropriate amount and wipe it out */
- thisLine->lineWidth -= chSize;
- if (flagWord & DODISP) {
- XFillRectangle(display, textInfo->mainWindow,
- textInfo->bgGC,
- thisLine->lineWidth, textInfo->curY,
- chSize, thisLine->lineHeight);
- }
- /* Delete from buffer */
- textInfo->txtBuffer[textInfo->curLine]->lineLength -= 1;
- textInfo->bufSpot -= 1;
- }
- return 1;
-}
-
-
-
-static int DrawLineWrap(display, win, x, y, h, col)
-Display *display;
-Window win; /* What window to draw it in */
-int x, y; /* Position of upper left corner */
-int h; /* Height of indicator */
-int col; /* Color of indicator */
-/*
- * This routine draws a line wrap indicator at the end of a line.
- * Visually, it is an arrow of the specified height directly against
- * the scroll bar border. The bitmap used for the arrow is stored
- * in 'arrowMap' with size 'arrow_width' and 'arrow_height'.
- */
-{
- struct txtWin *textInfo;
-
- textInfo = (struct txtWin *)XLookUpAssoc(display, textWindows,
- (XID) win);
-
- /* First, draw the arrow */
-#ifdef __FreeBSD__
- XCopyArea(display, textInfo->arrowMap, textInfo->mainWindow,
- textInfo->CursorGC,
- 0, 0, arrow_width, arrow_height,
- x, y + h - arrow_height);
-#else
- XCopyArea(display, textInfo->arrowMap, textInfo->mainWindow,
- textInfo->CursorGC,
- 0, 0, arrow_width, arrow_height,
- x, y + h - arrow_height, 1);
-#endif
-
- /* Then draw the stem */
- XDrawLine(display, textInfo->mainWindow, textInfo->CursorGC,
- x + STEMOFFSET, y,
- x + STEMOFFSET, y + h - arrow_height);
- return 1;
-}
-
-
-
-
-static int DrawLine(display, textInfo, lineIndex, ypos)
-Display *display;
-struct txtWin *textInfo; /* Text window information */
-int lineIndex; /* Index of line to draw */
-int ypos; /* Y position for line */
-/*
- * This routine destructively draws the indicated line in the
- * indicated window at the indicated position. It does not
- * clear to end of line however. It draws a line wrap indicator
- * if needed but does not draw a cursor.
- */
-{
- int index, startPos, curFont, theColor, curX, saveX, fontIndex;
- struct txtLine *someLine;
- char lineBuffer[BUFSIZE], *glyph;
- short *linePointer;
- XFontStruct *theFont;
- XGCValues gc;
-
- /* First, we draw the text */
- index = 0;
- curX = XPADDING;
- someLine = textInfo->txtBuffer[lineIndex];
- linePointer = &(textInfo->mainBuffer[someLine->lineText]);
- while (index < someLine->lineLength) {
- startPos = index;
- saveX = curX;
- curFont = linePointer[index] & FONTMASK;
- fontIndex = curFont >> FONTSHIFT;
- theFont = &(textInfo->theFonts[fontIndex]);
- theColor = textInfo->theColors[fontIndex];
- glyph = &(lineBuffer[0]);
- while ((index < someLine->lineLength) &&
- ((linePointer[index] & FONTMASK) == curFont))
- {
- *glyph = linePointer[index] & CHARMASK;
- index++;
- curX += CharSize(textInfo, lineIndex, index);
- glyph++;
- }
-
- /* Flush out the glyphs */
- XFillRectangle(display, textInfo->mainWindow,
- textInfo->bgGC,
- saveX, ypos,
- textInfo->w - BARSIZE,
- someLine->lineHeight + YPADDING + INTERLINE);
-
- XDrawString(display, textInfo->mainWindow,
- textInfo->fontGC[fontIndex],
- saveX, ypos,
- lineBuffer, someLine->lineLength);
- }
- /* Then the line wrap indicator (if needed) */
- if (someLine->lineFlags & WRAPFLAG) {
- DrawLineWrap(display, textInfo->mainWindow,
- textInfo->w - BARSIZE - WRAPINDSIZE,
- ypos, someLine->lineHeight,
- textInfo->fgPix);
- }
- return 1;
-}
-
-
-
-
-static int HandleNewFont(display, fontNum, textInfo, flagWord)
-Display *display;
-int fontNum; /* Font number */
-struct txtWin *textInfo; /* Text information */
-int flagWord; /* DODISP or nothing */
-/*
- * This routine handles a new font request. These requests take
- * the form "^F<digit>". The parsing is done in TxtWriteStr.
- * This routine is called only if the form is valid. It may return
- * a failure (0 status) if the requested font is not loaded.
- * If the new font is larger than any of the current
- * fonts on the line, it will change the line height and redisplay
- * the line.
- */
-{
- struct txtLine *thisLine;
- int heightDiff, baseDiff, redrawFlag;
-
- if (textInfo->theFonts[fontNum].fid == 0) {
- return 0;
- } else {
- thisLine = textInfo->txtBuffer[textInfo->curLine];
- textInfo->curFont = fontNum;
- redrawFlag = 0;
- heightDiff = textInfo->theFonts[fontNum].ascent +
- textInfo->theFonts[fontNum].descent -
- thisLine->lineHeight;
-
- if (heightDiff > 0) {
- redrawFlag = 1;
- } else {
- heightDiff = 0;
- }
-
- if (redrawFlag) {
- if (flagWord & DODISP) {
- /* Clear current line */
- XFillRectangle(display, textInfo->mainWindow,
- textInfo->bgGC,
- 0, textInfo->curY, textInfo->w,
- thisLine->lineHeight);
-
- /* Check to see if it requires scrolling */
- if ((textInfo->curY + thisLine->lineHeight + heightDiff +
- INTERLINE) > textInfo->h)
- {
- /*
- * General approach: "unscroll" the last line up
- * and then call ScrollDown to do the right thing.
- */
- textInfo->endLine -= 1;
- textInfo->bottomSpace += thisLine->lineHeight +
- INTERLINE;
-
- XFillRectangle(display, textInfo->mainWindow,
- textInfo->bgGC,
- 0, textInfo->h - textInfo->bottomSpace,
- textInfo->w, textInfo->bottomSpace);
-
- thisLine->lineHeight += heightDiff;
- ScrollDown(display, textInfo);
- textInfo->curY = textInfo->h -
- (textInfo->bottomSpace + INTERLINE +
- thisLine->lineHeight);
- }
- else
- {
- /* Just update bottom space */
- textInfo->bottomSpace -= heightDiff;
- thisLine->lineHeight += heightDiff;
- }
- /* Redraw the current line */
- DrawLine(display, textInfo, textInfo->curLine, textInfo->curY);
- } else {
- /* Just update line height */
- thisLine->lineHeight += heightDiff;
- }
- }
- return 1;
- }
-}
-
-
-
-int TxtWriteStr(display, w, str)
-Display *display;
-Window w; /* Text window */
-register char *str; /* 0 terminated string */
-/*
- * This routine writes a string to the specified text window.
- * The following notes apply:
- * - Text is always appended to the end of the text buffer.
- * - If the scroll bar is positioned such that the end of the
- * text is not visible, an automatic scroll to the bottom
- * will be done before the appending of text.
- * - Non-printable ASCII characters are not displayed.
- * - The '\n' character causes the current text position to
- * advance one line and start at the left.
- * - Tabs are not supported.
- * - Lines too long for the screen will be wrapped and a line wrap
- * indication will be drawn.
- * - Backspace clears the previous character. It will do the right
- * thing if asked to backspace past a wrapped line.
- * - A new font can be chosen using the sequence '^F<digit>' where
- * <digit> is 0-7. The directive will be ignored if
- * there is no font in the specified slot.
- * Returns 0 if something went wrong.
- */
-{
- register int fontIndex;
- register struct txtWin *textInfo;
- register struct txtLine *thisLine;
-
- if ((textInfo = (struct txtWin *) XLookUpAssoc(display, textWindows, (XID) w)) == 0)
- return 0;
-
- /* See if screen needs to be updated */
- if (textInfo->flagWord & SCREENWRONG) {
- TxtRepaint(display, textInfo->mainWindow);
- }
-
- /* See if we have to scroll down to the bottom */
- if (textInfo->flagWord & NOTATBOTTOM) {
- WarpToBottom(display, textInfo);
- textInfo->flagWord &= (~NOTATBOTTOM);
- }
-
- /* Undraw the current cursor */
- thisLine = textInfo->txtBuffer[textInfo->curLine];
-
- XFillRectangle(display, w, textInfo->bgGC,
- thisLine->lineWidth + CUROFFSET,
- textInfo->curY,
- CURSORWIDTH,
- thisLine->lineHeight);
-
- for ( /* str is ok */ ; (*str != 0) ; str++) {
- /* Check to see if we are waiting on a font */
- if (textInfo->flagWord & FONTNUMWAIT) {
- textInfo->flagWord &= (~FONTNUMWAIT);
- fontIndex = *str - '0';
- if ((fontIndex >= 0) && (fontIndex < MAXFONTS)) {
- /* Handle font -- go get next character */
- if (HandleNewFont(display, fontIndex, textInfo, DODISP))
- continue;
- }
- }
-
- /* Inline code for handling normal character case */
- if ((*str >= LOWCHAR) && (*str <= HIGHCHAR)) {
- register XFontStruct *thisFont;
- register struct txtLine *thisLine;
- register int charWidth;
- int thisColor;
-
- /* Determine size of character */
- thisFont = &(textInfo->theFonts[textInfo->curFont]);
- thisColor = textInfo->theColors[textInfo->curFont];
- if (*str <= thisFont->min_char_or_byte2 ||
- *str >= thisFont->max_char_or_byte2 ||
- thisFont->per_char == 0)
- charWidth = thisFont->max_bounds.width + 1;
- else
- charWidth = thisFont->per_char[*str].width + 1;
-
- /* Check to see if line wrap is required */
- thisLine = textInfo->txtBuffer[textInfo->curLine];
- if (thisLine->lineWidth + charWidth >
- (textInfo->w-BARSIZE-WRAPINDSIZE))
- {
- DrawLineWrap(display, textInfo->mainWindow,
- textInfo->w-BARSIZE-WRAPINDSIZE,
- textInfo->curY, thisLine->lineHeight,
- textInfo->fgPix);
- thisLine->lineFlags |= WRAPFLAG;
- /* Handle the spacing problem the same way as a newline */
- HandleNewLine(display, textInfo, DODISP | NONEWLINE);
- thisLine = textInfo->txtBuffer[textInfo->curLine];
- }
-
- /* Ready to draw character */
- XDrawString(display, textInfo->mainWindow,
- DEFAULT_GC,
- textInfo->curX += charWidth,
- textInfo->curY + thisLine->lineHeight,
- str, 1);
-
- /* Append character onto main buffer */
- if (textInfo->bufSpot >= textInfo->bufAlloc)
- /* Make room for more characters */
- ExpandBuffer(textInfo);
- textInfo->mainBuffer[(textInfo->bufSpot)++] =
- (textInfo->curFont << FONTSHIFT) | (*str);
-
- /* Update the line start array */
- thisLine->lineLength += 1;
- thisLine->lineWidth += charWidth;
- } else if (*str == NEWLINE) {
- HandleNewLine(display, textInfo, DODISP);
- } else if (*str == NEWFONT) {
- /* Go into waiting for font number mode */
- textInfo->flagWord |= FONTNUMWAIT;
- } else if (*str == BACKSPACE) {
- HandleBackspace(display, textInfo, DODISP);
- } else {
- /* Ignore all others */
- }
- }
- /* Draw the cursor in its new position */
- thisLine = textInfo->txtBuffer[textInfo->curLine];
-
- XFillRectangle(display, w, textInfo->CursorGC,
- thisLine->lineWidth + CUROFFSET,
- textInfo->curY /* + thisLine->lineHeight */,
- CURSORWIDTH, thisLine->lineHeight);
-
- return 1;
-}
-
-
-
-int TxtJamStr(display, w, str)
-Display *display;
-Window w; /* Text window */
-register char *str; /* NULL terminated string */
-/*
- * This is the same as TxtWriteStr except the screen is NOT updated.
- * After a call to this routine, TxtRepaint should be called to
- * update the screen. This routine is meant to be used to load
- * a text buffer with information and then allow the user to
- * scroll through it at will.
- */
-{
- register int fontIndex;
- register struct txtWin *textInfo;
-
- if ((textInfo = (struct txtWin *) XLookUpAssoc(display, textWindows, (XID) w)
- ) == 0)
- return 0;
-
- for ( /* str is ok */ ; (*str != 0) ; str++) {
- /* Check to see if we are waiting on a font */
- if (textInfo->flagWord & FONTNUMWAIT) {
- textInfo->flagWord &= (~FONTNUMWAIT);
- fontIndex = *str - '0';
- if ((fontIndex >= 0) && (fontIndex < MAXFONTS)) {
- if (HandleNewFont(display, fontIndex, textInfo, 0)) {
- /* Handled font -- go get next character */
- continue;
- }
- }
- }
- /* Inline code for handling normal character case */
- if ((*str >= LOWCHAR) && (*str <= HIGHCHAR)) {
- register XFontStruct *thisFont;
- register struct txtLine *thisLine;
- register int charWidth;
-
- /* Determine size of character */
- thisFont = &(textInfo->theFonts[textInfo->curFont]);
-
- if (*str <= thisFont->min_char_or_byte2 ||
- *str >= thisFont->max_char_or_byte2 ||
- thisFont->per_char == 0)
- charWidth = thisFont->max_bounds.width + 1;
- else
- charWidth = thisFont->per_char[*str].width + 1;
-
- /* Check to see if line wrap is required */
- thisLine = textInfo->txtBuffer[textInfo->curLine];
- if (thisLine->lineWidth + charWidth >
- (textInfo->w-BARSIZE-WRAPINDSIZE))
- {
- thisLine->lineFlags |= WRAPFLAG;
- /* Handle the spacing problem the same way as a newline */
- HandleNewLine(display, textInfo, NONEWLINE);
- thisLine = textInfo->txtBuffer[textInfo->curLine];
- }
- /* Append character onto main buffer */
- if (textInfo->bufSpot >= textInfo->bufAlloc)
- /* Make room for more characters */
- ExpandBuffer(textInfo);
- textInfo->mainBuffer[(textInfo->bufSpot)++] =
- (textInfo->curFont << FONTSHIFT) | (*str);
-
- /* Update the line start array */
- thisLine->lineLength += 1;
- thisLine->lineWidth += charWidth;
- } else if (*str == NEWLINE) {
- HandleNewLine(display, textInfo, 0);
- } else if (*str == NEWFONT) {
- /* Go into waiting for font number mode */
- textInfo->flagWord |= FONTNUMWAIT;
- } else if (*str == BACKSPACE) {
- HandleBackspace(display, textInfo, 0);
- } else {
- /* Ignore all others */
- }
- }
- textInfo->flagWord |= SCREENWRONG;
- return 1;
-}
-
-
-
-int TxtRepaint(display,w)
-Display *display;
-Window w;
-/*
- * Repaints the given scrollable text window. The routine repaints
- * the entire window. For handling exposure events, the TxtFilter
- * routine should be used.
- */
-{
- struct txtWin *textInfo;
- int index, ypos;
-
- if ((textInfo = (struct txtWin *) XLookUpAssoc(display, textWindows, (XID) w)
- ) == 0)
- return 0;
-
- /* Check to see if the screen is up to date */
- if (textInfo->flagWord & SCREENWRONG) {
- textInfo->endLine = FindEndLine(textInfo, &(textInfo->bottomSpace));
- textInfo->flagWord &= (~SCREENWRONG);
- }
-
- ypos = YPADDING;
- index = textInfo->startLine;
- for (;;) {
- DrawLine(display, textInfo, index, ypos);
- if (index >= textInfo->endLine) break;
- ypos += (textInfo->txtBuffer[index]->lineHeight + INTERLINE);
- index++;
- }
- /* Draw the cursor (if on screen) */
- if (textInfo->endLine == textInfo->curLine) {
- XFillRectangle(display, w, textInfo->CursorGC,
- textInfo->txtBuffer[index]->lineWidth + CUROFFSET,
- ypos /* + textInfo->txtBuffer[index]->lineHeight */,
- CURSORWIDTH, textInfo->txtBuffer[index]->lineHeight);
-
- }
- /* Update the scroll bar */
- UpdateScroll(display, textInfo);
- return 1;
-}
-
-
-
-static int InsertIndex(textInfo, thisIndex, ypos)
-struct txtWin *textInfo; /* Text Window Information */
-int thisIndex; /* Line index of exposed line */
-int ypos; /* Drawing position of line */
-/*
- * This routine inserts the supplied line index into the copy
- * exposure array for 'textInfo'. The array is kept sorted
- * from lowest to highest using insertion sort. The array
- * is dynamically expanded if needed.
- */
-{
- struct expEvent *newItem;
- int newSize, index, downIndex;
-
- /* Check to see if we need to expand it */
- if ((textInfo->exposeSize + 3) >= textInfo->exposeAlloc) {
- newSize = textInfo->exposeAlloc +
- (textInfo->exposeAlloc * EXPANDPERCENT / 100);
- textInfo->exposeAry = (struct expEvent **)
- realloc((char *) textInfo->exposeAry,
- (unsigned) (newSize * sizeof(struct expEvent *)));
- for (index = textInfo->exposeAlloc; index < newSize; index++)
- textInfo->exposeAry[index] = alloc(struct expEvent);
- textInfo->exposeAlloc = newSize;
- }
- /* Find spot for insertion. NOTE: last spot has big number */
- for (index = 0; index <= textInfo->exposeSize; index++) {
- if (textInfo->exposeAry[index]->lineIndex >= thisIndex) {
- if (textInfo->exposeAry[index]->lineIndex > thisIndex) {
- /* Insert before this entry */
- newItem = textInfo->exposeAry[textInfo->exposeSize+1];
- for (downIndex = textInfo->exposeSize;
- downIndex >= index;
- downIndex--)
- {
- textInfo->exposeAry[downIndex+1] =
- textInfo->exposeAry[downIndex];
- }
- /* Put a free structure at this spot */
- textInfo->exposeAry[index] = newItem;
- /* Fill it in */
- textInfo->exposeAry[index]->lineIndex = thisIndex;
- textInfo->exposeAry[index]->ypos = ypos;
- /* Break out of loop */
- textInfo->exposeSize += 1;
- }
- break;
- }
- }
- return 1;
-}
-
-
-
-static int ScrollUp(display, textInfo)
-Display *display;
-struct txtWin *textInfo; /* Text window information */
-/*
- * This routine scrolls the indicated text window up by one
- * line. The line above the current line must exist. The
- * window is scrolled so that the line above the start line
- * is displayed at the top of the screen. This may cause
- * many lines to scroll off the bottom. The scrolling is
- * done using XCopyArea. The exposure events should be caught
- * by ExposeCopy.
- */
-{
- int targetSpace;
-
- /* Make sure all exposures have been handled by now */
- if (textInfo->startLine == 0) return 0;
- targetSpace = textInfo->txtBuffer[textInfo->startLine-1]->lineHeight +
- INTERLINE;
- /* Move the area downward by the target amount */
- XCopyArea(display, textInfo->mainWindow, textInfo->mainWindow,
- DEFAULT_GC,
- 0, YPADDING, textInfo->w - BARSIZE,
- textInfo->h, 0, targetSpace);
-
- textInfo->flagWord |= COPYEXPOSE;
- /* Update the text window parameters */
- textInfo->startLine -= 1;
- textInfo->endLine = FindEndLine(textInfo, &(textInfo->bottomSpace));
-
- /* Clear out bottom space region */
-#ifdef __FreeBSD__
- XClearArea(display, textInfo->mainWindow,
- 0, textInfo->h - textInfo->bottomSpace,
- textInfo->w, textInfo->bottomSpace, 1);
-#else
- XClearArea(display, textInfo->mainWindow,
- 0, textInfo->h - textInfo->bottomSpace,
- textInfo->w, textInfo->bottomSpace);
-#endif
-
- UpdateExposures(display, textInfo);
- UpdateScroll(display, textInfo);
-
- return 1;
-}
-
-
-static int ScrollToSpot(display, textInfo, ySpot)
-Display *display;
-struct txtWin *textInfo; /* Text window information */
-int ySpot; /* Button position in scroll window */
-/*
- * This routine scrolls the specified text window relative to the
- * position of the mouse in the scroll bar. The center of the screen
- * will be positioned to correspond to the mouse position.
- */
-{
- int targetLine, aboveLines;
-
- targetLine = textInfo->numLines * ySpot / textInfo->h;
- textInfo->startLine = targetLine;
- textInfo->endLine = FindEndLine(textInfo, &(textInfo->bottomSpace));
- aboveLines = 0;
- /* Make the target line the *center* of the window */
- while ((textInfo->startLine > 0) &&
- (aboveLines < textInfo->endLine - targetLine))
- {
- textInfo->startLine -= 1;
- textInfo->endLine = FindEndLine(textInfo, &(textInfo->bottomSpace));
- aboveLines++;
- }
- if (textInfo->endLine == textInfo->numLines-1) {
- WarpToBottom(display, textInfo);
- } else {
- XClearWindow(display, textInfo->mainWindow);
- TxtRepaint(display, textInfo->mainWindow);
- }
- return 1;
-}
-
-
-
-static int LineToTop(display, textInfo, pos)
-Display *display;
-struct txtWin *textInfo; /* Text window information */
-int pos; /* Y position of mouse */
-/*
- * This routine scrolls the screen down until the line at the
- * mouse position is at the top of the screen. It stops
- * if it can't scroll the buffer down that far. If the
- * global 'ScrollOption' is NORMSCROLL, a smooth scroll
- * is used. Otherwise, it jumps to the right position
- * and repaints the screen.
- */
-{
- int index, sum;
-
- /* First, we find the current line */
- sum = 0;
- for (index = textInfo->startLine; index <= textInfo->endLine; index++) {
- if (sum + textInfo->txtBuffer[index]->lineHeight + INTERLINE> pos) break;
- sum += textInfo->txtBuffer[index]->lineHeight + INTERLINE;
- }
- /* We always want to scroll down at least one line */
- if (index == textInfo->startLine) index++;
- if (ScrollOption == NORMSCROLL) {
- /* Scroll down until 'index' is the starting line */
- while ((textInfo->startLine < index) && ScrollDown(display, textInfo))
- {
- /* Empty Loop Body */
- }
- } else {
- /* Immediately jump to correct spot */
- textInfo->startLine = index;
- textInfo->endLine = FindEndLine(textInfo, &(textInfo->bottomSpace));
- if (textInfo->endLine == textInfo->numLines-1) {
- WarpToBottom(display, textInfo);
- } else {
- XClearWindow(display, textInfo->mainWindow);
- TxtRepaint(display, textInfo->mainWindow);
- }
- }
- /* Check to see if at end of buffer */
- if (textInfo->endLine >= textInfo->numLines-1) {
- textInfo->flagWord &= (~NOTATBOTTOM);
- }
- return 1;
-}
-
-
-
-static int TopToHere(display, textInfo, pos)
-Display *display;
-struct txtWin *textInfo; /* Text window information */
-int pos; /* Y position of mouse */
-/*
- * This routine scrolls the screen up until the top line of
- * the screen is at the current Y position of the mouse. Again,
- * it will stop if it can't scroll that far. If the global
- * 'ScrollOption' is NORMSCROLL, a smooth scroll is used.
- * If it's not, it will simply redraw the screen at the
- * correct spot.
- */
-{
- int sum, target, linesup, index;
-
- target = pos - textInfo->txtBuffer[textInfo->startLine]->lineHeight;
- /* We always want to scroll up at least one line */
- if (target <= 0) target = 1;
- sum = 0;
- linesup = 0;
- /* Check to see if we are at the top anyway */
- if (textInfo->startLine == 0) return 0;
- if (ScrollOption == NORMSCROLL) {
- /* Scroll up until sum of new top lines greater than target */
- while ((sum < target) && ScrollUp(display, textInfo)) {
- sum += textInfo->txtBuffer[textInfo->startLine]->lineHeight;
- linesup++;
- }
- } else {
- /* Search backward to find index */
- index = textInfo->startLine - 1;
- while ((index > 0) && (sum < target)) {
- sum += textInfo->txtBuffer[index]->lineHeight;
- linesup++;
- index--;
- }
- /* Go directly to the index */
- textInfo->startLine = index;
- textInfo->endLine = FindEndLine(textInfo, &(textInfo->bottomSpace));
- XClearWindow(display, textInfo->mainWindow);
- TxtRepaint(display, textInfo->mainWindow);
- }
- /* If we scrolled, assert we are not at bottom of buffer */
- if (linesup > 0) {
- textInfo->flagWord |= NOTATBOTTOM;
- }
- return 1;
-}
-
-
-
-int TxtFilter(display, evt)
-Display *display;
-XEvent *evt;
-/*
- * This routine handles events associated with scrollable text windows.
- * It will handle all exposure events and any button released events
- * in the scroll bar of a text window. It does NOT handle any other
- * events. If it cannot handle the event, it will return 0.
- */
-{
- XExposeEvent *expose = &evt->xexpose;
- XButtonEvent *btEvt = &evt->xbutton;
- XGraphicsExposeEvent *gexpose = &evt->xgraphicsexpose;
- XNoExposeEvent *noexpose = &evt->xnoexpose;
- struct txtWin *textInfo;
- int index, ypos;
- Window w, sw;
-
- if (textWindows == (XAssocTable *) 0) {
- textWindows = XCreateAssocTable(32);
- if (textWindows == (XAssocTable *) 0) return(0);
- }
- if (evt->type == Expose) {
- w = expose->window;
- sw = 0;
- }
- else if (evt->type == GraphicsExpose) {
- w = gexpose->drawable;
- sw = 0;
- }
- else if (evt->type == NoExpose) {
- w = noexpose->drawable;
- sw = 0;
- }
- else if (evt->type == ButtonRelease) {
- w = btEvt->window;
- sw = btEvt->subwindow;
- }
- else
- return 0;
-
- if ((textInfo = (struct txtWin *)
- XLookUpAssoc(display, textWindows, (XID) w)) == 0)
- return 0;
-
- /* Determine whether it's main window or not */
- if ((w == textInfo->mainWindow) && (sw == 0)) {
- /* Main Window - handle exposures */
- switch (evt->type) {
- case Expose:
- ypos = 0 /*YPADDING*/;
- for (index = textInfo->startLine;
- index <= textInfo->endLine;
- index++)
- {
- int lh = textInfo->txtBuffer[index]->lineHeight;
-
- if (((ypos + lh) >= expose->y) &&
- (ypos <= (expose->y + expose->height)))
- {
- /* Intersection region */
- /* Draw line immediately */
- DrawLine(display, textInfo, index, ypos);
- /* And possibly draw cursor */
- if (textInfo->curLine == index) {
- XFillRectangle(display, w, textInfo->CursorGC,
- textInfo->txtBuffer[index]->lineWidth +
- CUROFFSET,
- ypos,
- CURSORWIDTH,
- lh);
- }
- }
- ypos += lh + INTERLINE;
- }
- break;
- case GraphicsExpose:
- ypos = 0 /*YPADDING*/;
- for (index = textInfo->startLine;
- index <= textInfo->endLine;
- index++)
- {
- int lh = textInfo->txtBuffer[index]->lineHeight;
-
- if (((ypos + lh) >= gexpose->y) &&
- (ypos <= (gexpose->y + gexpose->height)))
- {
- /* Intersection region */
- /* Draw line immediately */
- DrawLine(display, textInfo, index, ypos);
- /* And possibly draw cursor */
- if (textInfo->curLine == index) {
- XFillRectangle(display, w, textInfo->CursorGC,
- textInfo->txtBuffer[index]->lineWidth +
- CUROFFSET,
- ypos,
- CURSORWIDTH,
- lh);
- }
- }
- ypos += lh + INTERLINE;
- }
- break;
- case NoExpose:
- break;
- default:
- /* Not one of our events */
- return 0;
- }
- } else {
- switch (evt->type) {
- case Expose:
- UpdateScroll(display, textInfo);
- break;
- case ButtonRelease:
- /* Find out which button */
- switch (btEvt->button) {
- case Button1:
- /* Scroll up until top line is at mouse position */
- TopToHere(display, textInfo, btEvt->y);
- break;
- case Button2:
- /* Scroll to spot relative to position */
- ScrollToSpot(display, textInfo, btEvt->y);
- if (textInfo->endLine >= textInfo->numLines-1) {
- textInfo->flagWord &= (~NOTATBOTTOM);
- } else {
- textInfo->flagWord |= NOTATBOTTOM;
- }
- break;
- case Button3:
- /* Scroll down until pointed line is at top */
- LineToTop(display, textInfo, btEvt->y);
- break;
- }
- break;
- default:
- /* Not one of our events */
- return 0;
- }
- }
- return 1;
-}
diff --git a/gnu/games/chess/Xchess/scrollText/scrollText.c b/gnu/games/chess/Xchess/scrollText/scrollText.c
deleted file mode 100644
index aefb599..0000000
--- a/gnu/games/chess/Xchess/scrollText/scrollText.c
+++ /dev/null
@@ -1,1858 +0,0 @@
-/*
- * A Scrollable Text Output Window
- *
- * David Harrison
- * University of California, Berkeley
- * 1986
- *
- * The following is an implementation for a scrollable text output
- * system. It handles exposure events only (other interactions are
- * under user control). For scrolling, a always present scroll bar
- * is implemented. It detects size changes and compensates accordingly.
- */
-
-#include <X11/X.h>
-#include <X11/Xlib.h>
-#include <X11/X10.h>
-#include <sys/types.h>
-#include "scrollText.h"
-
-extern char *malloc();
-extern char *realloc();
-#define alloc(type) (type *) malloc(sizeof(type))
-#define numalloc(type, num) (type *) malloc((unsigned) (num * sizeof(type)))
-#define MAXINT 2147483647
-
-extern XAssocTable *XCreateAssocTable();
-extern caddr_t XLookUpAssoc();
-
-static XAssocTable *textWindows = (XAssocTable *) 0;
-
-#define NOOPTION -1 /* Option hasn't been set yet */
-#define NORMSCROLL 0 /* Smooth scroll on LineToTop and TopToHere */
-#define JUMPSCROLL 1 /* Jump scrolling on LineToTop and TopToHere */
-
-static int ScrollOption = NOOPTION;
-
-typedef char *Generic;
-
-#define DEFAULT_GC textInfo->fontGC[textInfo->curFont]
-
-#define BARSIZE 15
-#define BARBORDER 1
-#define MAXFONTS 8
-#define INITBUFSIZE 1024
-#define INITLINES 50
-#define INITEXPARY 50
-#define XPADDING 2
-#define YPADDING 2
-#define INTERLINE 5
-#define INTERSPACE 1
-#define CURSORWIDTH 2
-#define EXPANDPERCENT 40
-#define BUFSIZE 1024
-#define CUROFFSET 1
-#define MAXFOREIGN 250
-#define NOINDEX -1
-
-/* The wrap line indicator */
-#define WRAPINDSIZE 7
-#define STEMOFFSET 5
-#define arrow_width 7
-#define arrow_height 5
-static char arrow_bits[] = {
- 0x24, 0x26, 0x3f, 0x06, 0x04};
-
-#define NEWLINE '\n'
-#define BACKSPACE '\010'
-#define NEWFONT '\006'
-#define LOWCHAR '\040'
-#define HIGHCHAR '\176'
-
-#define CHARMASK 0x00ff /* Character mask */
-#define FONTMASK 0x0700 /* Character font */
-#define FONTSHIFT 8 /* Shift amount */
-
-#define WRAPFLAG 0x01 /* Line wrap flag */
-
-/*
- * Lines are represented by a pointer into the overall array of
- * 16-bit characters. The lower eight bits is used to indicate the character
- * (in ASCII), and the next two bits are used to indicate the font
- * the character should be drawn in.
- */
-
-typedef struct txtLine {
- int lineLength; /* Current line length */
- int lineHeight; /* Full height of line in pixels */
- int lineBaseLine; /* Current baseline of the line */
- int lineWidth; /* Drawing position at end of line */
- int lineText; /* Offset into master buffer */
- int lineFlags; /* Line wrap flag is here */
-};
-
-
-/*
- * For ExposeCopy events, we queue up the redraw requests collapsing
- * them into line redraw requests until the CopyExpose event arrives.
- * The queue is represented as a dynamic array of the following
- * structure:
- */
-
-typedef struct expEvent {
- int lineIndex; /* Index of line to redraw */
- int ypos; /* Drawing position of line */
-};
-
-
-/*
- * The text buffer is represented using a dynamic counted array
- * of 16-bit quantities. This array expands as needed.
- * For the screen representation, a dynamic counted array
- * of line structures is used. This array points into the
- * text buffer to denote the start of each line and its parameters.
- * The windows are configured as one overall window which contains
- * the scroll bar as a sub-window along its right edge. Thus,
- * the text drawing space is actually w-BARSIZE.
- */
-
-#define NOTATBOTTOM 0x01 /* Need to scroll to bottom before appending */
-#define FONTNUMWAIT 0x02 /* Waiting for font number */
-#define COPYEXPOSE 0x04 /* Need to process a copy expose event */
-#define SCREENWRONG 0x08 /* TxtJamStr has invalidated screen contents */
-
-typedef struct txtWin {
- /* Basic text buffer */
- int bufAlloc; /* Allocated size of buffer */
- int bufSpot; /* Current writing position in buffer */
- short *mainBuffer; /* Main buffer of text */
-
- /* Line information */
- int numLines; /* Number of display lines in buffer */
- int allocLines; /* Number of lines allocated */
- struct txtLine **txtBuffer; /* Dynamic array of lines */
-
- /* Current Window display information */
- Window mainWindow; /* Text display window */
- Window scrollBar; /* Subwindow for scroll bar */
- Pixmap arrowMap; /* line wrap indicator */
- int bgPix, fgPix; /* Background and cursor */
- GC CursorGC; /* gc for the cursor */
- GC bgGC; /* gc for erasing things */
- GC fontGC[MAXFONTS]; /* gc for doing fonts */
- XFontStruct theFonts[MAXFONTS];/* Display fonts */
- int theColors[MAXFONTS]; /* foregrounds of the fonts */
- int curFont; /* current font for tracking */
- int w, h; /* Current size */
- int startLine; /* Top line in display */
- int endLine; /* Bottom line in display */
- int bottomSpace; /* Space at bottom of screen */
- int flagWord; /* If non-zero, not at end */
-
- /* For handling ExposeCopy events */
- int exposeSize; /* Current size of array */
- int exposeAlloc; /* Allocated size */
- struct expEvent **exposeAry;/* Array of line indices */
-
- /* Drawing position information */
- int curLine; /* Current line in buffer */
- int curX; /* Current horizontal positi */
- int curY; /* Current vertical drawing */
-};
-
-/* Flags for the various basic character handling functions */
-
-#define DODISP 0x01 /* Update the display */
-#define NONEWLINE 0x02 /* Dont append newline */
-
-
-
-static int InitLine(newLine)
-struct txtLine *newLine; /* Newly created line structure */
-/*
- * This routine initializes a newly created line structure.
- */
-{
- newLine->lineLength = 0;
- newLine->lineHeight = 0;
- newLine->lineBaseLine = 0;
- newLine->lineWidth = XPADDING;
- newLine->lineText = NOINDEX;
- newLine->lineFlags = 0;
- return 1;
-}
-
-
-
-
-int TxtGrab(display, txtWin, program, mainFont, bg, fg, cur)
-Display *display; /* display window is on */
-Window txtWin; /* Window to take over as scrollable text */
-char *program; /* Program name for Xdefaults */
-XFontStruct *mainFont; /* Primary text font */
-int bg, fg, cur; /* Background, foreground, and cursor colors */
-/*
- * This routine takes control of 'txtWin' and makes it into a scrollable
- * text output window. It will create a sub-window for the scroll bar
- * with a background of 'bg' and an bar with color 'fg'. Both fixed width
- * and variable width fonts are supported. Additional fonts can be loaded
- * using 'TxtAddFont'. Returns 0 if there were problems, non-zero if
- * everything went ok.
- */
-{
- struct txtWin *newWin; /* Text package specific information */
- XWindowAttributes winInfo; /* Window information */
- int index;
- XGCValues gc_val;
-
- if (textWindows == (XAssocTable *) 0) {
- textWindows = XCreateAssocTable(32);
- if (textWindows == (XAssocTable *) 0) return(0);
- }
- if (XGetWindowAttributes(display, txtWin, &winInfo) == 0) return 0;
-
- if (ScrollOption == NOOPTION) {
- /* Read to see if the user wants jump scrolling or not */
- if (XGetDefault(display, program, "JumpScroll")) {
- ScrollOption = JUMPSCROLL;
- } else {
- ScrollOption = NORMSCROLL;
- }
- }
-
- /* Initialize local structure */
- newWin = alloc(struct txtWin);
-
- /* Initialize arrow pixmap */
- newWin->arrowMap = XCreatePixmapFromBitmapData(display, txtWin,
- arrow_bits,
- arrow_width, arrow_height,
- cur, bg,
- DisplayPlanes(display, 0));
-
- newWin->bufAlloc = INITBUFSIZE;
- newWin->bufSpot = 0;
- newWin->mainBuffer = numalloc(short, INITBUFSIZE);
-
- newWin->numLines = 1;
- newWin->allocLines = INITLINES;
- newWin->txtBuffer = numalloc(struct txtLine *, INITLINES);
- for (index = 0; index < INITLINES; index++) {
- newWin->txtBuffer[index] = alloc(struct txtLine);
- InitLine(newWin->txtBuffer[index]);
- }
-
- /* Window display information */
- newWin->mainWindow = txtWin;
- newWin->w = winInfo.width;
- newWin->h = winInfo.height;
- newWin->startLine = 0;
- newWin->endLine = 0;
- newWin->bottomSpace = winInfo.height
- - YPADDING - mainFont->ascent - mainFont->descent - INTERLINE;
- newWin->flagWord = 0;
- newWin->bgPix = bg;
- newWin->fgPix = fg;
-
- /* Scroll Bar Creation */
- newWin->scrollBar = XCreateSimpleWindow(display, txtWin,
- winInfo.width - BARSIZE,
- 0, BARSIZE - (2*BARBORDER),
- winInfo.height - (2*BARBORDER),
- BARBORDER,
- fg, bg);
- XSelectInput(display, newWin->scrollBar, ExposureMask|ButtonReleaseMask);
- XMapRaised(display, newWin->scrollBar);
-
- /* Font and Color Initialization */
- newWin->theFonts[0] = *mainFont;
- newWin->theColors[0] = fg;
- gc_val.function = GXcopy;
- gc_val.plane_mask = AllPlanes;
- gc_val.foreground = fg;
- gc_val.background = bg;
- gc_val.graphics_exposures = 1;
- gc_val.font = mainFont->fid;
- gc_val.line_width = 1;
- gc_val.line_style = LineSolid;
-
- newWin->fontGC[0] = XCreateGC(display, txtWin,
- GCFunction | GCPlaneMask |
- GCForeground | GCBackground |
- GCGraphicsExposures | GCFont,
- &gc_val);
-
- gc_val.foreground = cur;
- newWin->CursorGC = XCreateGC(display, txtWin,
- GCFunction | GCPlaneMask |
- GCForeground | GCBackground |
- GCLineStyle | GCLineWidth,
- &gc_val);
-
- gc_val.foreground = bg;
- newWin->bgGC = XCreateGC(display, txtWin,
- GCFunction | GCPlaneMask |
- GCForeground | GCBackground |
- GCGraphicsExposures | GCFont,
- &gc_val);
-
-
- for (index = 1; index < MAXFONTS; index++) {
- newWin->theFonts[index].fid = 0;
- newWin->fontGC[index] = 0;
- }
-
-
- /* Initialize size of first line */
- newWin->txtBuffer[0]->lineHeight = newWin->theFonts[0].ascent +
- newWin->theFonts[0].descent;
- newWin->txtBuffer[0]->lineText = 0;
-
- /* ExposeCopy array initialization */
- newWin->exposeSize = 0;
- newWin->exposeAlloc = INITEXPARY;
- newWin->exposeAry = numalloc(struct expEvent *, INITEXPARY);
- for (index = 0; index < newWin->exposeAlloc; index++)
- newWin->exposeAry[index] = alloc(struct expEvent);
- /* Put plus infinity in last slot for sorting purposes */
- newWin->exposeAry[0]->lineIndex = MAXINT;
-
- /* Drawing Position Information */
- newWin->curLine = 0;
- newWin->curX = 0;
- newWin->curY = YPADDING + mainFont->ascent + mainFont->descent;
-
- /* Attach it to both windows */
- XMakeAssoc(display, textWindows, (XID) txtWin, (caddr_t) newWin);
- XMakeAssoc(display, textWindows, (XID) newWin->scrollBar, (caddr_t) newWin);
- return 1;
-}
-
-
-int TxtRelease(display, w)
-Display *display;
-Window w; /* Window to release */
-/*
- * This routine releases all resources associated with the
- * specified window which are consumed by the text
- * window package. This includes the entire text buffer, line start
- * array, and the scroll bar window. However, the window
- * itself is NOT destroyed. The routine will return zero if
- * the window is not owned by the text window package.
- */
-{
- struct txtWin *textInfo;
- int index;
-
- if ((textInfo = (struct txtWin *) XLookUpAssoc(display,
- textWindows, (XID) w)) == 0)
- return 0;
-
- for (index = 0; index < MAXFONTS; index++)
- if (textInfo->fontGC[index] != 0)
- XFreeGC(display, textInfo->fontGC[index]);
-
- free((Generic) textInfo->mainBuffer);
- for (index = 0; index < textInfo->numLines; index++) {
- free((Generic) textInfo->txtBuffer[index]);
- }
- free((Generic) textInfo->txtBuffer);
- XDestroyWindow(display, textInfo->scrollBar);
- for (index = 0; index < textInfo->exposeSize; index++) {
- free((Generic) textInfo->exposeAry[index]);
- }
- free((Generic) textInfo->exposeAry);
- XDeleteAssoc(display, textWindows, (XID) w);
- free((Generic) textInfo);
- return 1;
-}
-
-
-
-static int RecompBuffer(textInfo)
-struct txtWin *textInfo; /* Text window information */
-/*
- * This routine recomputes all line breaks in a buffer after
- * a change in window size or font. This is done by throwing
- * away the old line start array and recomputing it. Although
- * a lot of this work is also done elsewhere, it has been included
- * inline here for efficiency.
- */
-{
- int startPos, endSize, linenum;
- register int index, chsize, curfont;
- register short *bufptr;
- register XFontStruct *fontptr;
- register struct txtLine *lineptr;
- char theChar;
-
- /* Record the old position so we can come back to it */
- for (startPos = textInfo->txtBuffer[textInfo->startLine]->lineText;
- (startPos > 0) && (textInfo->mainBuffer[startPos] != '\n');
- startPos--)
- /* null loop body */;
-
- /* Clear out the old line start array */
- for (index = 0; index < textInfo->numLines; index++) {
- InitLine(textInfo->txtBuffer[index]);
- }
-
- /* Initialize first line */
- textInfo->txtBuffer[0]->lineHeight =
- textInfo->theFonts[0].ascent + textInfo->theFonts[0].descent;
- textInfo->txtBuffer[0]->lineText = 0;
-
- /* Process the text back into lines */
- endSize = textInfo->w - BARSIZE - WRAPINDSIZE;
- bufptr = textInfo->mainBuffer;
- lineptr = textInfo->txtBuffer[0];
- linenum = 0;
- fontptr = &(textInfo->theFonts[0]);
- curfont = 0;
- for (index = 0; index < textInfo->bufSpot; index++) {
- theChar = bufptr[index] & CHARMASK;
-
- if ((bufptr[index] & FONTMASK) != curfont) {
- int newFontNum, heightDiff;
-
- /* Switch fonts */
- newFontNum = (bufptr[index] & FONTMASK) >> FONTSHIFT;
- if (textInfo->theFonts[newFontNum].fid != 0) {
- /* Valid font */
- curfont = bufptr[index] & FONTMASK;
- fontptr = &(textInfo->theFonts[newFontNum]);
- heightDiff = (fontptr->ascent + fontptr->descent) -
- lineptr->lineHeight;
- if (heightDiff < 0) heightDiff = 0;
- lineptr->lineHeight += heightDiff;
- }
- }
- if (theChar == '\n') {
- /* Handle new line */
- if (linenum >= textInfo->allocLines-1)
- /* Expand number of lines */
- ExpandLines(textInfo);
- linenum++;
- lineptr = textInfo->txtBuffer[linenum];
- /* Initialize next line */
- lineptr->lineHeight = fontptr->ascent + fontptr->descent;
- lineptr->lineText = index+1;
- /* Check to see if its the starting line */
- if (index == startPos) textInfo->startLine = linenum;
- } else {
- /* Handle normal character */
- chsize = CharSize(textInfo, linenum, index);
- if (lineptr->lineWidth + chsize > endSize) {
- /* Handle line wrap */
- lineptr->lineFlags |= WRAPFLAG;
- if (linenum >= textInfo->allocLines-1)
- /* Expand number of lines */
- ExpandLines(textInfo);
- linenum++;
- lineptr = textInfo->txtBuffer[linenum];
- /* Initialize next line */
- lineptr->lineHeight = fontptr->ascent + fontptr->descent;
- lineptr->lineText = index;
- lineptr->lineLength = 1;
- lineptr->lineWidth += chsize;
- } else {
- /* Handle normal addition of character */
- lineptr->lineLength += 1;
- lineptr->lineWidth += chsize;
- }
- }
- }
- /* We now have a valid line array. Let's clean up some other fields. */
- textInfo->numLines = linenum+1;
- if (startPos == 0) {
- textInfo->startLine = 0;
- }
- textInfo->endLine = FindEndLine(textInfo, &(textInfo->bottomSpace));
- textInfo->curLine = linenum;
- /* Check to see if we are at the bottom */
- if (textInfo->endLine >= textInfo->numLines-1) {
- textInfo->curY = textInfo->h - textInfo->bottomSpace -
- lineptr->lineHeight;
- textInfo->flagWord &= (~NOTATBOTTOM);
- } else {
- textInfo->flagWord |= NOTATBOTTOM;
- }
- return 1;
-}
-
-
-
-
-int TxtAddFont(display, textWin, fontNumber, newFont, newColor)
-Display *display;
-Window textWin; /* Scrollable text window */
-int fontNumber; /* Place to add font (0-7) */
-XFontStruct *newFont; /* Font to add */
-int newColor; /* Color of font */
-/*
- * This routine loads a new font so that it can be used in a previously
- * created text window. There are eight font slots numbered 0 through 7.
- * If there is already a font in the specified slot, it will be replaced
- * and an automatic redraw of the window will take place. See TxtWriteStr
- * for details on using alternate fonts. The color specifies the foreground
- * color of the text. The default foreground color is used if this
- * parameter is TXT_NO_COLOR. Returns a non-zero value if
- * everything went well.
- */
-{
- struct txtWin *textInfo;
- int redrawFlag;
- XGCValues gc_val;
-
- if ((fontNumber < 0) || (fontNumber >= MAXFONTS)) return 0;
- if ((textInfo = (struct txtWin *)
- XLookUpAssoc(display, textWindows, (XID) textWin)) == 0)
- return 0;
- if (newColor == TXT_NO_COLOR) {
- newColor = textInfo->fgPix;
- }
-
- gc_val.font = newFont->fid;
- gc_val.foreground = newColor;
- gc_val.background = textInfo->bgPix;
- gc_val.plane_mask = AllPlanes;
- gc_val.graphics_exposures = 1;
- gc_val.function = GXcopy;
-
- if (textInfo->fontGC[fontNumber] != 0)
- {
- XChangeGC(display, textInfo->fontGC[fontNumber],
- GCFont | GCForeground, &gc_val);
- }
- else
- textInfo->fontGC[fontNumber] = XCreateGC(display, textWin,
- GCFont |
- GCForeground |
- GCBackground |
- GCFunction |
- GCPlaneMask |
- GCGraphicsExposures,
- &gc_val);
-
-
- redrawFlag = (textInfo->theFonts[fontNumber].fid != 0) &&
- (((newFont) && (newFont->fid != textInfo->theFonts[fontNumber].fid)) ||
- (newColor != textInfo->theColors[fontNumber]));
- if (newFont) {
- textInfo->theFonts[fontNumber] = *newFont;
- }
- textInfo->theColors[fontNumber] = newColor;
-
- if (redrawFlag) {
- RecompBuffer(textInfo);
- XClearWindow(display, textWin);
- TxtRepaint(display, textWin);
- }
- return 1;
-}
-
-
-
-int TxtWinP(display, w)
-Display *display;
-Window w;
-/*
- * Returns a non-zero value if the window has been previously grabbed
- * using TxtGrab and 0 if it has not.
- */
-{
- if (XLookUpAssoc(display, textWindows, (XID) w))
- return(1);
- else return(0);
-}
-
-
-
-static int FindEndLine(textInfo, botSpace)
-struct txtWin *textInfo;
-int *botSpace;
-/*
- * Given the starting line in 'textInfo->startLine', this routine
- * determines the index of the last line that can be drawn given the
- * current size of the screen. If there are not enough lines to
- * fill the screen, the index of the last line will be returned.
- * The amount of empty bottom space is returned in 'botSpace'.
- */
-{
- int index, height, lineHeight;
-
- height = YPADDING;
- index = textInfo->startLine;
- while (index < textInfo->numLines) {
- lineHeight = textInfo->txtBuffer[index]->lineHeight + INTERLINE;
- if (height + lineHeight > textInfo->h) break;
- height += lineHeight;
- index++;
- }
- if (botSpace) {
- *botSpace = textInfo->h - height;
- }
- return index - 1;
-}
-
-
-
-static int UpdateScroll(display, textInfo)
-Display *display;
-struct txtWin *textInfo; /* Text window information */
-/*
- * This routine computes the current extent of the scroll bar
- * indicator and repaints the bar with the correct information.
- */
-{
- int top, bottom;
-
- if (textInfo->numLines > 1) {
- top = textInfo->startLine * (textInfo->h - 2*BARBORDER) /
- (textInfo->numLines - 1);
- bottom = textInfo->endLine * (textInfo->h - 2*BARBORDER) /
- (textInfo->numLines - 1);
- } else {
- top = 0;
- bottom = textInfo->h - (2*BARBORDER);
- }
-
- /* Draw it - make sure there is a little padding */
- if (top == 0) top++;
- if (bottom == textInfo->h-(2*BARBORDER)) bottom--;
-
- XFillRectangle(display, textInfo->scrollBar,
- textInfo->bgGC,
- 0, 0, BARSIZE, top-1);
- XFillRectangle(display, textInfo->scrollBar,
- DEFAULT_GC, top, BARSIZE - (2*BARBORDER) - 2,
- bottom - top);
- XFillRectangle(display, textInfo->scrollBar, DEFAULT_GC,
- 0, bottom+1, BARSIZE,
- textInfo->h - (2 * BARBORDER) - bottom);
-
- return 1;
-}
-
-
-
-
-int TxtClear(display, w)
-Display *display;
-Window w;
-/*
- * This routine clears a scrollable text window. It resets the current
- * writing position to the upper left hand corner of the screen.
- * NOTE: THIS ALSO CLEARS THE CONTENTS OF THE TEXT WINDOW BUFFER AND
- * RESETS THE SCROLL BAR. Returns 0 if the window is not a text window.
- * This should be used *instead* of XClear.
- */
-{
- struct txtWin *textInfo;
- int index;
-
- if ((textInfo = (struct txtWin *) XLookUpAssoc(display, textWindows, (XID) w)) == 0)
- return 0;
-
- /* Zero out the arrays */
- textInfo->bufSpot = 0;
- for (index = 0; index < textInfo->numLines; index++) {
- InitLine(textInfo->txtBuffer[index]);
- }
- textInfo->txtBuffer[0]->lineHeight =
- textInfo->theFonts[textInfo->curFont].ascent +
- textInfo->theFonts[textInfo->curFont].descent;
-
- textInfo->numLines = 1;
- textInfo->startLine = 0;
- textInfo->endLine = 0;
- textInfo->curLine = 0;
- textInfo->curX = 0;
- textInfo->curY = YPADDING + textInfo->theFonts[textInfo->curFont].ascent
- + textInfo->theFonts[textInfo->curFont].descent;
-
- textInfo->bottomSpace = textInfo->h - YPADDING -
- textInfo->theFonts[textInfo->curFont].ascent - INTERLINE -
- textInfo->theFonts[textInfo->curFont].descent;
- /* Actually clear the window */
- XClearWindow(display, w);
-
- /* Draw the current cursor */
- XFillRectangle(display, w, textInfo->CursorGC,
- XPADDING + CUROFFSET, textInfo->curY,
- CURSORWIDTH,
- textInfo->theFonts[textInfo->curFont].ascent +
- textInfo->theFonts[textInfo->curFont].descent);
-
- /* Update the scroll bar */
- UpdateScroll(display, textInfo);
- return 1;
-}
-
-
-static int WarpToBottom(display, textInfo)
-Display *display;
-struct txtWin *textInfo; /* Text Information */
-/*
- * This routine causes the specified text window to display its
- * last screen of information. It updates the scroll bar
- * to the appropriate spot. The implementation scans backward
- * through the buffer to find an appropriate starting spot for
- * the window.
- */
-{
- int index, height, lineHeight;
-
- index = textInfo->numLines-1;
- height = 0;
- while (index >= 0) {
- lineHeight = textInfo->txtBuffer[index]->lineHeight + INTERLINE;
- if (height + lineHeight > textInfo->h) break;
- height += lineHeight;
- index--;
- }
- textInfo->startLine = index + 1;
- textInfo->endLine = FindEndLine(textInfo, &(textInfo->bottomSpace));
- textInfo->curY = textInfo->h - textInfo->bottomSpace -
- textInfo->txtBuffer[textInfo->endLine]->lineHeight;
- XClearWindow(display, textInfo->mainWindow);
- TxtRepaint(display, textInfo->mainWindow);
- return 1;
-}
-
-
-
-static int UpdateExposures(display, textInfo)
-Display *display;
-struct txtWin *textInfo; /* Text window information */
-/*
- * Before a new scrolling action occurs, the text window package
- * must handle all COPYEXPOSE events generated by the last scrolling
- * action. This routine is called to do this. Foreign events (those
- * not handled by TxtFilter) are queued up and replaced on the queue
- * after the processing of the exposure events is complete.
- */
-{
-#if 0
- XEvent foreignQueue[MAXFOREIGN];
- int index, lastItem = 0;
-
- while (textInfo->flagWord & COPYEXPOSE) {
- XNextEvent(display, &(foreignQueue[lastItem]));
- if (!TxtFilter(display, &(foreignQueue[lastItem])))
- lastItem++;
- if (lastItem >= MAXFOREIGN) {
- printf("Too many foreign events to queue!\n");
- textInfo->flagWord &= (~COPYEXPOSE);
- }
- }
- for (index = 0; index < lastItem; index++) {
- XPutBackEvent(display, &(foreignQueue[index]));
- }
-#endif
- return 1;
-}
-
-
-static int ScrollDown(display,textInfo)
-Display *display;
-struct txtWin *textInfo; /* Text window information */
-/*
- * This routine scrolls the indicated text window down by one
- * line. The line below the current line must exist. The window
- * is scrolled so that the line below the last line is fully
- * displayed. This may cause many lines to scroll off the top.
- * Scrolling is done using XCopyArea. The exposure events should
- * be caught using ExposeCopy.
- */
-{
- int lineSum, index, targetSpace, freeSpace, updateFlag;
-
- lineSum = 0;
- if (textInfo->endLine + 1 >= textInfo->numLines) return 0;
- targetSpace = textInfo->txtBuffer[textInfo->endLine+1]->lineHeight +
- INTERLINE;
- if (textInfo->bottomSpace < targetSpace) {
- index = textInfo->startLine;
- while (index < textInfo->endLine) {
- lineSum += (textInfo->txtBuffer[index]->lineHeight + INTERLINE);
- if (textInfo->bottomSpace + lineSum >= targetSpace) break;
- index++;
- }
-
- /* Must move upward by 'lineSum' pixels */
- XCopyArea(display, textInfo->mainWindow, textInfo->mainWindow,
- DEFAULT_GC, 0, lineSum,
- textInfo->w - BARSIZE, textInfo->h,
- 0, 0);
-
- textInfo->flagWord |= COPYEXPOSE;
- /* Repair the damage to the structures */
- textInfo->startLine = index + 1;
- updateFlag = 1;
- } else {
- updateFlag = 0;
- }
- /* More lines might be able to fit. Let's check. */
- freeSpace = textInfo->bottomSpace + lineSum - targetSpace;
- index = textInfo->endLine + 1;
- while (index < textInfo->numLines-1) {
- if (freeSpace - textInfo->txtBuffer[index+1]->lineHeight - INTERLINE < 0)
- break;
- freeSpace -= (textInfo->txtBuffer[index+1]->lineHeight + INTERLINE);
- index++;
- }
- textInfo->endLine = index;
- textInfo->bottomSpace = freeSpace;
- if (updateFlag) {
- UpdateExposures(display, textInfo);
- }
- UpdateScroll(display, textInfo);
- return 1;
-}
-
-
-
-
-static int ExpandLines(textInfo)
-struct txtWin *textInfo; /* Text Information */
-/*
- * This routine allocates and initializes additional space in
- * the line start array (txtBuffer). The new space
- * is allocated using realloc. The expansion factor is a percentage
- * given by EXPANDPERCENT.
- */
-{
- int newSize, index;
-
- newSize = textInfo->allocLines;
- newSize += (newSize * EXPANDPERCENT) / 100;
-
- textInfo->txtBuffer = (struct txtLine **)
- realloc((char *) textInfo->txtBuffer,
- (unsigned) (newSize * sizeof(struct txtLine *)));
- for (index = textInfo->allocLines; index < newSize; index++) {
- textInfo->txtBuffer[index] = alloc(struct txtLine);
- InitLine(textInfo->txtBuffer[index]);
- }
- textInfo->allocLines = newSize;
- return 1;
-}
-
-static int ExpandBuffer(textInfo)
-struct txtWin *textInfo; /* Text information */
-/*
- * Expands the basic character buffer using realloc. The expansion
- * factor is a percentage given by EXPANDPERCENT.
- */
-{
- int newSize;
-
- newSize = textInfo->bufAlloc + (textInfo->bufAlloc * EXPANDPERCENT) / 100;
- textInfo->mainBuffer = (short *)
- realloc((char *) textInfo->mainBuffer, (unsigned) newSize * sizeof(short));
- textInfo->bufAlloc = newSize;
- return 1;
-}
-
-
-
-static int HandleNewLine(display, textInfo, flagWord)
-Display *display;
-struct txtWin *textInfo; /* Text Information */
-int flagWord; /* DODISP or NONEWLINE or both */
-/*
- * This routine initializes the next line for drawing by setting
- * its height to the current font height, scrolls the screen down
- * one line, and updates the current drawing position to the
- * left edge of the newly cleared line. If DODISP is specified,
- * the screen will be updated (otherwise not). If NONEWLINE is
- * specified, no newline character will be added to the text buffer
- * (this is for line wrap).
- */
-{
- struct txtLine *curLine, *nextLine;
-
- /* Check to see if a new line must be allocated */
- if (textInfo->curLine >= textInfo->allocLines-1)
- /* Expand the number of lines */
- ExpandLines(textInfo);
- textInfo->numLines += 1;
-
- /* Then we initialize the next line */
- nextLine = textInfo->txtBuffer[textInfo->numLines-1];
- nextLine->lineHeight =
- textInfo->theFonts[textInfo->curFont].ascent +
- textInfo->theFonts[textInfo->curFont].descent;
-
- curLine = textInfo->txtBuffer[textInfo->curLine];
- if (flagWord & DODISP) {
- /* Scroll down a line if required */
- if ((textInfo->curY + curLine->lineHeight +
- nextLine->lineHeight + (INTERLINE * 2)) > textInfo->h)
- {
- ScrollDown(display, textInfo);
- }
- else
- {
- /* Update the bottom space appropriately */
- textInfo->bottomSpace -= (nextLine->lineHeight + INTERLINE);
- textInfo->endLine += 1;
- }
- /* Update drawing position */
- textInfo->curY = textInfo->h -
- (textInfo->bottomSpace + nextLine->lineHeight);
- }
-
- /* Move down a line */
- textInfo->curLine += 1;
- if (!(flagWord & NONEWLINE)) {
- /* Append end-of-line to text buffer */
- if (textInfo->bufSpot >= textInfo->bufAlloc) {
- /* Allocate more space in main text buffer */
- ExpandBuffer(textInfo);
- }
- textInfo->mainBuffer[(textInfo->bufSpot)++] =
- (textInfo->curFont << FONTSHIFT) | '\n';
- }
- nextLine->lineText = textInfo->bufSpot;
- textInfo->curX = 0;
- return 1;
-}
-
-
-
-static int CharSize(textInfo, lineNum, charNum)
-struct txtWin *textInfo; /* Current Text Information */
-int lineNum; /* Line in buffer */
-int charNum; /* Character in line */
-/*
- * This routine determines the size of the specified character.
- * It takes in account the font of the character and whether its
- * fixed or variable. The size includes INTERSPACE spacing between
- * the characters.
- */
-{
- register XFontStruct *charFont;
- register short *theLine;
- register short theChar;
-
- theLine = &(textInfo->mainBuffer[textInfo->txtBuffer[lineNum]->lineText]);
- theChar = theLine[charNum] & CHARMASK;
- charFont = &(textInfo->theFonts[(theChar & FONTMASK) >> FONTSHIFT]);
- if (theChar <= charFont->min_char_or_byte2 ||
- theChar >= charFont->max_char_or_byte2 ||
- charFont->per_char == 0)
- return charFont->max_bounds.width + 1;
- else
- return charFont->per_char[theChar].width + 1;
-}
-
-
-
-
-
-static int HandleBackspace(display, textInfo, flagWord)
-Display *display;
-struct txtWin *textInfo; /* Text Information */
-int flagWord; /* DODISP or nothing */
-/*
- * This routine handles a backspace found in the input stream. The
- * character before the current writing position will be erased and
- * the drawing position will move back one character. If the writing
- * position is at the left margin, the drawing position will move
- * up to the previous line. If it is a line that has been wrapped,
- * the character at the end of the previous line will be erased.
- */
-{
- struct txtLine *thisLine, *prevLine;
- int chSize;
-
- thisLine = textInfo->txtBuffer[textInfo->curLine];
- /* First, determine whether we need to go back a line */
- if (thisLine->lineLength == 0) {
- /* Bleep if at top of buffer */
- if (textInfo->curLine == 0) {
- XBell(display, 50);
- return 0;
- }
-
- /* See if we have to scroll in the other direction */
- if ((flagWord & DODISP) && (textInfo->curY <= YPADDING)) {
- /* This will display the last lines of the buffer */
- WarpToBottom(display, textInfo);
- }
-
- /* Set drawing position at end of previous line */
- textInfo->curLine -= 1;
- prevLine = textInfo->txtBuffer[textInfo->curLine];
- textInfo->numLines -= 1;
- if (flagWord & DODISP) {
- textInfo->curY -= (prevLine->lineHeight + INTERLINE);
- textInfo->bottomSpace += (thisLine->lineHeight + INTERLINE);
- textInfo->endLine -= 1;
- }
-
- /* We are unlinewrapping if the previous line has flag set */
- if (prevLine->lineFlags & WRAPFLAG) {
- /* Get rid of line wrap indicator */
- if (flagWord & DODISP) {
- XFillRectangle(display, textInfo->mainWindow,
- textInfo->bgGC,
- textInfo->w - BARSIZE - WRAPINDSIZE,
- textInfo->curY, WRAPINDSIZE,
- prevLine->lineHeight);
- }
- prevLine->lineFlags &= (~WRAPFLAG);
- /* Call recursively to wipe out the ending character */
- HandleBackspace(display, textInfo, flagWord);
- } else {
- /* Delete the end-of-line in the primary buffer */
- textInfo->bufSpot -= 1;
- }
- } else {
- /* Normal deletion of character */
- chSize =
- CharSize(textInfo, textInfo->curLine,
- textInfo->txtBuffer[textInfo->curLine]->lineLength - 1);
- /* Move back appropriate amount and wipe it out */
- thisLine->lineWidth -= chSize;
- if (flagWord & DODISP) {
- XFillRectangle(display, textInfo->mainWindow,
- textInfo->bgGC,
- thisLine->lineWidth, textInfo->curY,
- chSize, thisLine->lineHeight);
- }
- /* Delete from buffer */
- textInfo->txtBuffer[textInfo->curLine]->lineLength -= 1;
- textInfo->bufSpot -= 1;
- }
- return 1;
-}
-
-
-
-static int DrawLineWrap(display, win, x, y, h, col)
-Display *display;
-Window win; /* What window to draw it in */
-int x, y; /* Position of upper left corner */
-int h; /* Height of indicator */
-int col; /* Color of indicator */
-/*
- * This routine draws a line wrap indicator at the end of a line.
- * Visually, it is an arrow of the specified height directly against
- * the scroll bar border. The bitmap used for the arrow is stored
- * in 'arrowMap' with size 'arrow_width' and 'arrow_height'.
- */
-{
- struct txtWin *textInfo;
-
- textInfo = (struct txtWin *)XLookUpAssoc(display, textWindows,
- (XID) win);
-
- /* First, draw the arrow */
- XCopyArea(display, textInfo->arrowMap, textInfo->mainWindow,
- textInfo->CursorGC,
- 0, 0, arrow_width, arrow_height,
- x, y + h - arrow_height, 1);
-
- /* Then draw the stem */
- XDrawLine(display, textInfo->mainWindow, textInfo->CursorGC,
- x + STEMOFFSET, y,
- x + STEMOFFSET, y + h - arrow_height);
- return 1;
-}
-
-
-
-
-static int DrawLine(display, textInfo, lineIndex, ypos)
-Display *display;
-struct txtWin *textInfo; /* Text window information */
-int lineIndex; /* Index of line to draw */
-int ypos; /* Y position for line */
-/*
- * This routine destructively draws the indicated line in the
- * indicated window at the indicated position. It does not
- * clear to end of line however. It draws a line wrap indicator
- * if needed but does not draw a cursor.
- */
-{
- int index, startPos, curFont, theColor, curX, saveX, fontIndex;
- struct txtLine *someLine;
- char lineBuffer[BUFSIZE], *glyph;
- short *linePointer;
- XFontStruct *theFont;
- XGCValues gc;
-
- /* First, we draw the text */
- index = 0;
- curX = XPADDING;
- someLine = textInfo->txtBuffer[lineIndex];
- linePointer = &(textInfo->mainBuffer[someLine->lineText]);
- while (index < someLine->lineLength) {
- startPos = index;
- saveX = curX;
- curFont = linePointer[index] & FONTMASK;
- fontIndex = curFont >> FONTSHIFT;
- theFont = &(textInfo->theFonts[fontIndex]);
- theColor = textInfo->theColors[fontIndex];
- glyph = &(lineBuffer[0]);
- while ((index < someLine->lineLength) &&
- ((linePointer[index] & FONTMASK) == curFont))
- {
- *glyph = linePointer[index] & CHARMASK;
- index++;
- curX += CharSize(textInfo, lineIndex, index);
- glyph++;
- }
-
- /* Flush out the glyphs */
- XFillRectangle(display, textInfo->mainWindow,
- textInfo->bgGC,
- saveX, ypos,
- textInfo->w - BARSIZE,
- someLine->lineHeight + YPADDING + INTERLINE);
-
- XDrawString(display, textInfo->mainWindow,
- textInfo->fontGC[fontIndex],
- saveX, ypos,
- lineBuffer, someLine->lineLength);
- }
- /* Then the line wrap indicator (if needed) */
- if (someLine->lineFlags & WRAPFLAG) {
- DrawLineWrap(display, textInfo->mainWindow,
- textInfo->w - BARSIZE - WRAPINDSIZE,
- ypos, someLine->lineHeight,
- textInfo->fgPix);
- }
- return 1;
-}
-
-
-
-
-static int HandleNewFont(display, fontNum, textInfo, flagWord)
-Display *display;
-int fontNum; /* Font number */
-struct txtWin *textInfo; /* Text information */
-int flagWord; /* DODISP or nothing */
-/*
- * This routine handles a new font request. These requests take
- * the form "^F<digit>". The parsing is done in TxtWriteStr.
- * This routine is called only if the form is valid. It may return
- * a failure (0 status) if the requested font is not loaded.
- * If the new font is larger than any of the current
- * fonts on the line, it will change the line height and redisplay
- * the line.
- */
-{
- struct txtLine *thisLine;
- int heightDiff, baseDiff, redrawFlag;
-
- if (textInfo->theFonts[fontNum].fid == 0) {
- return 0;
- } else {
- thisLine = textInfo->txtBuffer[textInfo->curLine];
- textInfo->curFont = fontNum;
- redrawFlag = 0;
- heightDiff = textInfo->theFonts[fontNum].ascent +
- textInfo->theFonts[fontNum].descent -
- thisLine->lineHeight;
-
- if (heightDiff > 0) {
- redrawFlag = 1;
- } else {
- heightDiff = 0;
- }
-
- if (redrawFlag) {
- if (flagWord & DODISP) {
- /* Clear current line */
- XFillRectangle(display, textInfo->mainWindow,
- textInfo->bgGC,
- 0, textInfo->curY, textInfo->w,
- thisLine->lineHeight);
-
- /* Check to see if it requires scrolling */
- if ((textInfo->curY + thisLine->lineHeight + heightDiff +
- INTERLINE) > textInfo->h)
- {
- /*
- * General approach: "unscroll" the last line up
- * and then call ScrollDown to do the right thing.
- */
- textInfo->endLine -= 1;
- textInfo->bottomSpace += thisLine->lineHeight +
- INTERLINE;
-
- XFillRectangle(display, textInfo->mainWindow,
- textInfo->bgGC,
- 0, textInfo->h - textInfo->bottomSpace,
- textInfo->w, textInfo->bottomSpace);
-
- thisLine->lineHeight += heightDiff;
- ScrollDown(display, textInfo);
- textInfo->curY = textInfo->h -
- (textInfo->bottomSpace + INTERLINE +
- thisLine->lineHeight);
- }
- else
- {
- /* Just update bottom space */
- textInfo->bottomSpace -= heightDiff;
- thisLine->lineHeight += heightDiff;
- }
- /* Redraw the current line */
- DrawLine(display, textInfo, textInfo->curLine, textInfo->curY);
- } else {
- /* Just update line height */
- thisLine->lineHeight += heightDiff;
- }
- }
- return 1;
- }
-}
-
-
-
-int TxtWriteStr(display, w, str)
-Display *display;
-Window w; /* Text window */
-register char *str; /* 0 terminated string */
-/*
- * This routine writes a string to the specified text window.
- * The following notes apply:
- * - Text is always appended to the end of the text buffer.
- * - If the scroll bar is positioned such that the end of the
- * text is not visible, an automatic scroll to the bottom
- * will be done before the appending of text.
- * - Non-printable ASCII characters are not displayed.
- * - The '\n' character causes the current text position to
- * advance one line and start at the left.
- * - Tabs are not supported.
- * - Lines too long for the screen will be wrapped and a line wrap
- * indication will be drawn.
- * - Backspace clears the previous character. It will do the right
- * thing if asked to backspace past a wrapped line.
- * - A new font can be chosen using the sequence '^F<digit>' where
- * <digit> is 0-7. The directive will be ignored if
- * there is no font in the specified slot.
- * Returns 0 if something went wrong.
- */
-{
- register int fontIndex;
- register struct txtWin *textInfo;
- register struct txtLine *thisLine;
-
- if ((textInfo = (struct txtWin *) XLookUpAssoc(display, textWindows, (XID) w)) == 0)
- return 0;
-
- /* See if screen needs to be updated */
- if (textInfo->flagWord & SCREENWRONG) {
- TxtRepaint(display, textInfo->mainWindow);
- }
-
- /* See if we have to scroll down to the bottom */
- if (textInfo->flagWord & NOTATBOTTOM) {
- WarpToBottom(display, textInfo);
- textInfo->flagWord &= (~NOTATBOTTOM);
- }
-
- /* Undraw the current cursor */
- thisLine = textInfo->txtBuffer[textInfo->curLine];
-
- XFillRectangle(display, w, textInfo->bgGC,
- thisLine->lineWidth + CUROFFSET,
- textInfo->curY,
- CURSORWIDTH,
- thisLine->lineHeight);
-
- for ( /* str is ok */ ; (*str != 0) ; str++) {
- /* Check to see if we are waiting on a font */
- if (textInfo->flagWord & FONTNUMWAIT) {
- textInfo->flagWord &= (~FONTNUMWAIT);
- fontIndex = *str - '0';
- if ((fontIndex >= 0) && (fontIndex < MAXFONTS)) {
- /* Handle font -- go get next character */
- if (HandleNewFont(display, fontIndex, textInfo, DODISP))
- continue;
- }
- }
-
- /* Inline code for handling normal character case */
- if ((*str >= LOWCHAR) && (*str <= HIGHCHAR)) {
- register XFontStruct *thisFont;
- register struct txtLine *thisLine;
- register int charWidth;
- int thisColor;
-
- /* Determine size of character */
- thisFont = &(textInfo->theFonts[textInfo->curFont]);
- thisColor = textInfo->theColors[textInfo->curFont];
- if (*str <= thisFont->min_char_or_byte2 ||
- *str >= thisFont->max_char_or_byte2 ||
- thisFont->per_char == 0)
- charWidth = thisFont->max_bounds.width + 1;
- else
- charWidth = thisFont->per_char[*str].width + 1;
-
- /* Check to see if line wrap is required */
- thisLine = textInfo->txtBuffer[textInfo->curLine];
- if (thisLine->lineWidth + charWidth >
- (textInfo->w-BARSIZE-WRAPINDSIZE))
- {
- DrawLineWrap(display, textInfo->mainWindow,
- textInfo->w-BARSIZE-WRAPINDSIZE,
- textInfo->curY, thisLine->lineHeight,
- textInfo->fgPix);
- thisLine->lineFlags |= WRAPFLAG;
- /* Handle the spacing problem the same way as a newline */
- HandleNewLine(display, textInfo, DODISP | NONEWLINE);
- thisLine = textInfo->txtBuffer[textInfo->curLine];
- }
-
- /* Ready to draw character */
- XDrawString(display, textInfo->mainWindow,
- DEFAULT_GC,
- textInfo->curX += charWidth,
- textInfo->curY + thisLine->lineHeight,
- str, 1);
-
- /* Append character onto main buffer */
- if (textInfo->bufSpot >= textInfo->bufAlloc)
- /* Make room for more characters */
- ExpandBuffer(textInfo);
- textInfo->mainBuffer[(textInfo->bufSpot)++] =
- (textInfo->curFont << FONTSHIFT) | (*str);
-
- /* Update the line start array */
- thisLine->lineLength += 1;
- thisLine->lineWidth += charWidth;
- } else if (*str == NEWLINE) {
- HandleNewLine(display, textInfo, DODISP);
- } else if (*str == NEWFONT) {
- /* Go into waiting for font number mode */
- textInfo->flagWord |= FONTNUMWAIT;
- } else if (*str == BACKSPACE) {
- HandleBackspace(display, textInfo, DODISP);
- } else {
- /* Ignore all others */
- }
- }
- /* Draw the cursor in its new position */
- thisLine = textInfo->txtBuffer[textInfo->curLine];
-
- XFillRectangle(display, w, textInfo->CursorGC,
- thisLine->lineWidth + CUROFFSET,
- textInfo->curY /* + thisLine->lineHeight */,
- CURSORWIDTH, thisLine->lineHeight);
-
- return 1;
-}
-
-
-
-int TxtJamStr(display, w, str)
-Display *display;
-Window w; /* Text window */
-register char *str; /* NULL terminated string */
-/*
- * This is the same as TxtWriteStr except the screen is NOT updated.
- * After a call to this routine, TxtRepaint should be called to
- * update the screen. This routine is meant to be used to load
- * a text buffer with information and then allow the user to
- * scroll through it at will.
- */
-{
- register int fontIndex;
- register struct txtWin *textInfo;
-
- if ((textInfo = (struct txtWin *) XLookUpAssoc(display, textWindows, (XID) w)
- ) == 0)
- return 0;
-
- for ( /* str is ok */ ; (*str != 0) ; str++) {
- /* Check to see if we are waiting on a font */
- if (textInfo->flagWord & FONTNUMWAIT) {
- textInfo->flagWord &= (~FONTNUMWAIT);
- fontIndex = *str - '0';
- if ((fontIndex >= 0) && (fontIndex < MAXFONTS)) {
- if (HandleNewFont(display, fontIndex, textInfo, 0)) {
- /* Handled font -- go get next character */
- continue;
- }
- }
- }
- /* Inline code for handling normal character case */
- if ((*str >= LOWCHAR) && (*str <= HIGHCHAR)) {
- register XFontStruct *thisFont;
- register struct txtLine *thisLine;
- register int charWidth;
-
- /* Determine size of character */
- thisFont = &(textInfo->theFonts[textInfo->curFont]);
-
- if (*str <= thisFont->min_char_or_byte2 ||
- *str >= thisFont->max_char_or_byte2 ||
- thisFont->per_char == 0)
- charWidth = thisFont->max_bounds.width + 1;
- else
- charWidth = thisFont->per_char[*str].width + 1;
-
- /* Check to see if line wrap is required */
- thisLine = textInfo->txtBuffer[textInfo->curLine];
- if (thisLine->lineWidth + charWidth >
- (textInfo->w-BARSIZE-WRAPINDSIZE))
- {
- thisLine->lineFlags |= WRAPFLAG;
- /* Handle the spacing problem the same way as a newline */
- HandleNewLine(display, textInfo, NONEWLINE);
- thisLine = textInfo->txtBuffer[textInfo->curLine];
- }
- /* Append character onto main buffer */
- if (textInfo->bufSpot >= textInfo->bufAlloc)
- /* Make room for more characters */
- ExpandBuffer(textInfo);
- textInfo->mainBuffer[(textInfo->bufSpot)++] =
- (textInfo->curFont << FONTSHIFT) | (*str);
-
- /* Update the line start array */
- thisLine->lineLength += 1;
- thisLine->lineWidth += charWidth;
- } else if (*str == NEWLINE) {
- HandleNewLine(display, textInfo, 0);
- } else if (*str == NEWFONT) {
- /* Go into waiting for font number mode */
- textInfo->flagWord |= FONTNUMWAIT;
- } else if (*str == BACKSPACE) {
- HandleBackspace(display, textInfo, 0);
- } else {
- /* Ignore all others */
- }
- }
- textInfo->flagWord |= SCREENWRONG;
- return 1;
-}
-
-
-
-int TxtRepaint(display,w)
-Display *display;
-Window w;
-/*
- * Repaints the given scrollable text window. The routine repaints
- * the entire window. For handling exposure events, the TxtFilter
- * routine should be used.
- */
-{
- struct txtWin *textInfo;
- int index, ypos;
-
- if ((textInfo = (struct txtWin *) XLookUpAssoc(display, textWindows, (XID) w)
- ) == 0)
- return 0;
-
- /* Check to see if the screen is up to date */
- if (textInfo->flagWord & SCREENWRONG) {
- textInfo->endLine = FindEndLine(textInfo, &(textInfo->bottomSpace));
- textInfo->flagWord &= (~SCREENWRONG);
- }
-
- ypos = YPADDING;
- index = textInfo->startLine;
- for (;;) {
- DrawLine(display, textInfo, index, ypos);
- if (index >= textInfo->endLine) break;
- ypos += (textInfo->txtBuffer[index]->lineHeight + INTERLINE);
- index++;
- }
- /* Draw the cursor (if on screen) */
- if (textInfo->endLine == textInfo->curLine) {
- XFillRectangle(display, w, textInfo->CursorGC,
- textInfo->txtBuffer[index]->lineWidth + CUROFFSET,
- ypos /* + textInfo->txtBuffer[index]->lineHeight */,
- CURSORWIDTH, textInfo->txtBuffer[index]->lineHeight);
-
- }
- /* Update the scroll bar */
- UpdateScroll(display, textInfo);
- return 1;
-}
-
-
-
-static int InsertIndex(textInfo, thisIndex, ypos)
-struct txtWin *textInfo; /* Text Window Information */
-int thisIndex; /* Line index of exposed line */
-int ypos; /* Drawing position of line */
-/*
- * This routine inserts the supplied line index into the copy
- * exposure array for 'textInfo'. The array is kept sorted
- * from lowest to highest using insertion sort. The array
- * is dynamically expanded if needed.
- */
-{
- struct expEvent *newItem;
- int newSize, index, downIndex;
-
- /* Check to see if we need to expand it */
- if ((textInfo->exposeSize + 3) >= textInfo->exposeAlloc) {
- newSize = textInfo->exposeAlloc +
- (textInfo->exposeAlloc * EXPANDPERCENT / 100);
- textInfo->exposeAry = (struct expEvent **)
- realloc((char *) textInfo->exposeAry,
- (unsigned) (newSize * sizeof(struct expEvent *)));
- for (index = textInfo->exposeAlloc; index < newSize; index++)
- textInfo->exposeAry[index] = alloc(struct expEvent);
- textInfo->exposeAlloc = newSize;
- }
- /* Find spot for insertion. NOTE: last spot has big number */
- for (index = 0; index <= textInfo->exposeSize; index++) {
- if (textInfo->exposeAry[index]->lineIndex >= thisIndex) {
- if (textInfo->exposeAry[index]->lineIndex > thisIndex) {
- /* Insert before this entry */
- newItem = textInfo->exposeAry[textInfo->exposeSize+1];
- for (downIndex = textInfo->exposeSize;
- downIndex >= index;
- downIndex--)
- {
- textInfo->exposeAry[downIndex+1] =
- textInfo->exposeAry[downIndex];
- }
- /* Put a free structure at this spot */
- textInfo->exposeAry[index] = newItem;
- /* Fill it in */
- textInfo->exposeAry[index]->lineIndex = thisIndex;
- textInfo->exposeAry[index]->ypos = ypos;
- /* Break out of loop */
- textInfo->exposeSize += 1;
- }
- break;
- }
- }
- return 1;
-}
-
-
-
-static int ScrollUp(display, textInfo)
-Display *display;
-struct txtWin *textInfo; /* Text window information */
-/*
- * This routine scrolls the indicated text window up by one
- * line. The line above the current line must exist. The
- * window is scrolled so that the line above the start line
- * is displayed at the top of the screen. This may cause
- * many lines to scroll off the bottom. The scrolling is
- * done using XCopyArea. The exposure events should be caught
- * by ExposeCopy.
- */
-{
- int targetSpace;
-
- /* Make sure all exposures have been handled by now */
- if (textInfo->startLine == 0) return 0;
- targetSpace = textInfo->txtBuffer[textInfo->startLine-1]->lineHeight +
- INTERLINE;
- /* Move the area downward by the target amount */
- XCopyArea(display, textInfo->mainWindow, textInfo->mainWindow,
- DEFAULT_GC,
- 0, YPADDING, textInfo->w - BARSIZE,
- textInfo->h, 0, targetSpace);
-
- textInfo->flagWord |= COPYEXPOSE;
- /* Update the text window parameters */
- textInfo->startLine -= 1;
- textInfo->endLine = FindEndLine(textInfo, &(textInfo->bottomSpace));
-
- /* Clear out bottom space region */
- XClearArea(display, textInfo->mainWindow,
- 0, textInfo->h - textInfo->bottomSpace,
- textInfo->w, textInfo->bottomSpace);
-
- UpdateExposures(display, textInfo);
- UpdateScroll(display, textInfo);
-
- return 1;
-}
-
-
-static int ScrollToSpot(display, textInfo, ySpot)
-Display *display;
-struct txtWin *textInfo; /* Text window information */
-int ySpot; /* Button position in scroll window */
-/*
- * This routine scrolls the specified text window relative to the
- * position of the mouse in the scroll bar. The center of the screen
- * will be positioned to correspond to the mouse position.
- */
-{
- int targetLine, aboveLines;
-
- targetLine = textInfo->numLines * ySpot / textInfo->h;
- textInfo->startLine = targetLine;
- textInfo->endLine = FindEndLine(textInfo, &(textInfo->bottomSpace));
- aboveLines = 0;
- /* Make the target line the *center* of the window */
- while ((textInfo->startLine > 0) &&
- (aboveLines < textInfo->endLine - targetLine))
- {
- textInfo->startLine -= 1;
- textInfo->endLine = FindEndLine(textInfo, &(textInfo->bottomSpace));
- aboveLines++;
- }
- if (textInfo->endLine == textInfo->numLines-1) {
- WarpToBottom(display, textInfo);
- } else {
- XClearWindow(display, textInfo->mainWindow);
- TxtRepaint(display, textInfo->mainWindow);
- }
- return 1;
-}
-
-
-
-static int LineToTop(display, textInfo, pos)
-Display *display;
-struct txtWin *textInfo; /* Text window information */
-int pos; /* Y position of mouse */
-/*
- * This routine scrolls the screen down until the line at the
- * mouse position is at the top of the screen. It stops
- * if it can't scroll the buffer down that far. If the
- * global 'ScrollOption' is NORMSCROLL, a smooth scroll
- * is used. Otherwise, it jumps to the right position
- * and repaints the screen.
- */
-{
- int index, sum;
-
- /* First, we find the current line */
- sum = 0;
- for (index = textInfo->startLine; index <= textInfo->endLine; index++) {
- if (sum + textInfo->txtBuffer[index]->lineHeight + INTERLINE> pos) break;
- sum += textInfo->txtBuffer[index]->lineHeight + INTERLINE;
- }
- /* We always want to scroll down at least one line */
- if (index == textInfo->startLine) index++;
- if (ScrollOption == NORMSCROLL) {
- /* Scroll down until 'index' is the starting line */
- while ((textInfo->startLine < index) && ScrollDown(display, textInfo))
- {
- /* Empty Loop Body */
- }
- } else {
- /* Immediately jump to correct spot */
- textInfo->startLine = index;
- textInfo->endLine = FindEndLine(textInfo, &(textInfo->bottomSpace));
- if (textInfo->endLine == textInfo->numLines-1) {
- WarpToBottom(display, textInfo);
- } else {
- XClearWindow(display, textInfo->mainWindow);
- TxtRepaint(display, textInfo->mainWindow);
- }
- }
- /* Check to see if at end of buffer */
- if (textInfo->endLine >= textInfo->numLines-1) {
- textInfo->flagWord &= (~NOTATBOTTOM);
- }
- return 1;
-}
-
-
-
-static int TopToHere(display, textInfo, pos)
-Display *display;
-struct txtWin *textInfo; /* Text window information */
-int pos; /* Y position of mouse */
-/*
- * This routine scrolls the screen up until the top line of
- * the screen is at the current Y position of the mouse. Again,
- * it will stop if it can't scroll that far. If the global
- * 'ScrollOption' is NORMSCROLL, a smooth scroll is used.
- * If it's not, it will simply redraw the screen at the
- * correct spot.
- */
-{
- int sum, target, linesup, index;
-
- target = pos - textInfo->txtBuffer[textInfo->startLine]->lineHeight;
- /* We always want to scroll up at least one line */
- if (target <= 0) target = 1;
- sum = 0;
- linesup = 0;
- /* Check to see if we are at the top anyway */
- if (textInfo->startLine == 0) return 0;
- if (ScrollOption == NORMSCROLL) {
- /* Scroll up until sum of new top lines greater than target */
- while ((sum < target) && ScrollUp(display, textInfo)) {
- sum += textInfo->txtBuffer[textInfo->startLine]->lineHeight;
- linesup++;
- }
- } else {
- /* Search backward to find index */
- index = textInfo->startLine - 1;
- while ((index > 0) && (sum < target)) {
- sum += textInfo->txtBuffer[index]->lineHeight;
- linesup++;
- index--;
- }
- /* Go directly to the index */
- textInfo->startLine = index;
- textInfo->endLine = FindEndLine(textInfo, &(textInfo->bottomSpace));
- XClearWindow(display, textInfo->mainWindow);
- TxtRepaint(display, textInfo->mainWindow);
- }
- /* If we scrolled, assert we are not at bottom of buffer */
- if (linesup > 0) {
- textInfo->flagWord |= NOTATBOTTOM;
- }
- return 1;
-}
-
-
-
-int TxtFilter(display, evt)
-Display *display;
-XEvent *evt;
-/*
- * This routine handles events associated with scrollable text windows.
- * It will handle all exposure events and any button released events
- * in the scroll bar of a text window. It does NOT handle any other
- * events. If it cannot handle the event, it will return 0.
- */
-{
- XExposeEvent *expose = &evt->xexpose;
- XButtonEvent *btEvt = &evt->xbutton;
- XGraphicsExposeEvent *gexpose = &evt->xgraphicsexpose;
- XNoExposeEvent *noexpose = &evt->xnoexpose;
- struct txtWin *textInfo;
- int index, ypos;
- Window w, sw;
-
- if (textWindows == (XAssocTable *) 0) {
- textWindows = XCreateAssocTable(32);
- if (textWindows == (XAssocTable *) 0) return(0);
- }
- if (evt->type == Expose) {
- w = expose->window;
- sw = 0;
- }
- else if (evt->type == GraphicsExpose) {
- w = gexpose->drawable;
- sw = 0;
- }
- else if (evt->type == NoExpose) {
- w = noexpose->drawable;
- sw = 0;
- }
- else if (evt->type == ButtonRelease) {
- w = btEvt->window;
- sw = btEvt->subwindow;
- }
- else
- return 0;
-
- if ((textInfo = (struct txtWin *)
- XLookUpAssoc(display, textWindows, (XID) w)) == 0)
- return 0;
-
- /* Determine whether it's main window or not */
- if ((w == textInfo->mainWindow) && (sw == 0)) {
- /* Main Window - handle exposures */
- switch (evt->type) {
- case Expose:
- ypos = 0 /*YPADDING*/;
- for (index = textInfo->startLine;
- index <= textInfo->endLine;
- index++)
- {
- int lh = textInfo->txtBuffer[index]->lineHeight;
-
- if (((ypos + lh) >= expose->y) &&
- (ypos <= (expose->y + expose->height)))
- {
- /* Intersection region */
- /* Draw line immediately */
- DrawLine(display, textInfo, index, ypos);
- /* And possibly draw cursor */
- if (textInfo->curLine == index) {
- XFillRectangle(display, w, textInfo->CursorGC,
- textInfo->txtBuffer[index]->lineWidth +
- CUROFFSET,
- ypos,
- CURSORWIDTH,
- lh);
- }
- }
- ypos += lh + INTERLINE;
- }
- break;
- case GraphicsExpose:
- ypos = 0 /*YPADDING*/;
- for (index = textInfo->startLine;
- index <= textInfo->endLine;
- index++)
- {
- int lh = textInfo->txtBuffer[index]->lineHeight;
-
- if (((ypos + lh) >= gexpose->y) &&
- (ypos <= (gexpose->y + gexpose->height)))
- {
- /* Intersection region */
- /* Draw line immediately */
- DrawLine(display, textInfo, index, ypos);
- /* And possibly draw cursor */
- if (textInfo->curLine == index) {
- XFillRectangle(display, w, textInfo->CursorGC,
- textInfo->txtBuffer[index]->lineWidth +
- CUROFFSET,
- ypos,
- CURSORWIDTH,
- lh);
- }
- }
- ypos += lh + INTERLINE;
- }
- break;
- case NoExpose:
- break;
- default:
- /* Not one of our events */
- return 0;
- }
- } else {
- switch (evt->type) {
- case Expose:
- UpdateScroll(display, textInfo);
- break;
- case ButtonRelease:
- /* Find out which button */
- switch (btEvt->button) {
- case Button1:
- /* Scroll up until top line is at mouse position */
- TopToHere(display, textInfo, btEvt->y);
- break;
- case Button2:
- /* Scroll to spot relative to position */
- ScrollToSpot(display, textInfo, btEvt->y);
- if (textInfo->endLine >= textInfo->numLines-1) {
- textInfo->flagWord &= (~NOTATBOTTOM);
- } else {
- textInfo->flagWord |= NOTATBOTTOM;
- }
- break;
- case Button3:
- /* Scroll down until pointed line is at top */
- LineToTop(display, textInfo, btEvt->y);
- break;
- }
- break;
- default:
- /* Not one of our events */
- return 0;
- }
- }
- return 1;
-}
diff --git a/gnu/games/chess/Xchess/std.c b/gnu/games/chess/Xchess/std.c
deleted file mode 100644
index 2bbd113..0000000
--- a/gnu/games/chess/Xchess/std.c
+++ /dev/null
@@ -1,427 +0,0 @@
-
-/* This file contains code for X-CHESS.
- Copyright (C) 1986 Free Software Foundation, Inc.
-
-This file is part of X-CHESS.
-
-X-CHESS is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY. No author or distributor
-accepts responsibility to anyone for the consequences of using it
-or for whether it serves any particular purpose or works at all,
-unless he says so in writing. Refer to the X-CHESS General Public
-License for full details.
-
-Everyone is granted permission to copy, modify and redistribute
-X-CHESS, but only under the conditions described in the
-X-CHESS General Public License. A copy of this license is
-supposed to have been given to you along with X-CHESS so you
-can know your rights and responsibilities. It should be in a
-file named COPYING. Among other things, the copyright notice
-and this notice must be preserved on all copies. */
-
-
-/* RCS Info: $Revision: 1.3 $ on $Date: 1994/11/04 02:11:33 $
- * $Source: /home/ncvs/src/gnu/games/chess/Xchess/std.c,v $
- * Copyright (c) 1985 Wayne A. Christopher, U. C. Berkeley CAD Group
- *
- * Utility routines.
- */
-
-#include "std.h"
-
-#ifndef IBMPC
-#include <sys/types.h>
-#endif not IBMPC
-#ifdef UNIX
-#include <signal.h>
-#include <pwd.h>
-#endif UNIX
-#ifdef BSD
-#include <sys/time.h>
-#include <sys/resource.h>
-#endif BSD
-
-extern char **environ;
-
-bool
-prefix(p, s)
- register char *p, *s;
-{
- while (*p && (*p == *s))
- p++, s++;
- if (!*p)
- return (true);
- else
- return (false);
-}
-
-/* Create a copy of a string. */
-
-char *
-copy(str)
- char *str;
-{
- char *p, *tmalloc();
-
- p = tmalloc(strlen(str) + 1);
- strcpy(p, str);
- return(p);
-}
-
-/* Determine whether sub is a substring of str. */
-
-bool
-substring(sub, str)
- register char *str, *sub;
-{
- register char *s;
-
- while(*str) {
- if(*str == *sub) {
- for(s = sub; *s; s++)
- if(*s != *str++)
- break;
- if(*s == '\0')
- return (true);
- }
- str++;
- }
- return (false);
-}
-
-/* Malloc num bytes and initialize to zero. Fatal error if the space can't
- * be malloc'd.
- */
-
-char *
-tmalloc(num)
- register int num;
-{
- register char *s;
- char *malloc();
-
- s = malloc((unsigned) num);
- if (!s) {
- fatal("malloc: can't allocate %d bytes", num);
- }
- bzero(s, num);
- return(s);
-}
-
-char *
-trealloc(ptr, num)
- char *ptr;
- int num;
-{
- register char *s;
- char *realloc();
-
- s = realloc(ptr, (unsigned) num);
- if (!s) {
- fatal("realloc: can't allocate %d bytes", num);
- }
- /* Well, this won't be zeroed... Too bad... */
- return(s);
-}
-
-/* Append one character to a string. Don't check for overflow. */
-
-void
-appendc(s, c)
- char *s, c;
-{
- while (*s)
- s++;
- *s++ = c;
- *s = '\0';
- return;
-}
-
-int
-scannum(str)
- char *str;
-{
- int i = 0;
-
- while(isdigit(*str))
- i = i * 10 + *(str++) - '0';
- return(i);
-}
-
-/* Case insensitive prefix. */
-
-bool
-ciprefix(p, s)
- register char *p, *s;
-{
- while (*p) {
- if ((isupper(*p) ? tolower(*p) : *p) !=
- (isupper(*s) ? tolower(*s) : *s))
- return(false);
- p++;
- s++;
- }
- return (true);
-}
-
-/* Case insensitive strcmp... */
-
-bool
-cieq(p, s)
- register char *p, *s;
-{
- while (*p) {
- if ((isupper(*p) ? tolower(*p) : *p) !=
- (isupper(*s) ? tolower(*s) : *s))
- return(false);
- p++;
- s++;
- }
- return (!*s);
-}
-
-#ifdef BSD
-
-/* Return the date. Return value is static data. */
-
-char *
-datestring()
-{
- register char *tzn;
- struct tm *tp;
- static char tbuf[40];
- char *ap;
- struct timeval tv;
- struct timezone tz;
- char *timezone(), *asctime();
- int i;
- struct tm *localtime();
-
- (void) gettimeofday(&tv, &tz);
- tp = localtime((time_t *) &tv.tv_sec);
- ap = asctime(tp);
- tzn = timezone(tz.tz_minuteswest, tp->tm_isdst);
- sprintf(tbuf, "%.20s", ap);
- if (tzn)
- strcat(tbuf, tzn);
- strcat(tbuf, ap + 19);
- i = strlen(tbuf);
- tbuf[i - 1] = '\0';
- return (tbuf);
-}
-
-#else BSD
-
-/* Give it a try... */
-
-char *
-datestring()
-{
- long i;
- static char buf[64];
-
- i = time(0);
- strcpy(buf, ctime(&i));
- buf[strlen(buf) - 1] = '\0'; /* Kill the nl. */
- return (buf);
-}
-
-#endif
-
-/* How many seconds have elapsed in running time. */
-
-int
-seconds()
-{
-#ifdef BSD
- struct rusage ruse;
-
- getrusage(RUSAGE_SELF, &ruse);
- return (ruse.ru_utime.tv_sec);
-#else BSD
-#endif BSD
-}
-
-/* A few things that may not exist on non-unix systems. */
-
-#ifndef BSD
-
-#ifndef index
-
-char *
-index(s, c)
- register char *s;
- register char c;
-{
- while ((*s != c) && (*s != '\0'))
- s++;
- if (*s == '\0')
- return ((char *) 0);
- else
- return (s);
-}
-
-#endif not index
-
-#ifndef rindex
-
-char *
-rindex(s, c)
- register char *s;
- register char c;
-{
- register char *t;
-
- for (t = s; *t != '\0'; t++);
- while ((*t != c) && (t != s))
- t--;
- if (t == s)
- return ((char *) 0);
- else
- return (t);
-}
-
-#endif not rindex
-
-#ifndef bcopy
-
-void
-bcopy(from, to, num)
- register char *from, *to;
- register int num;
-{
- while (num-- > 0)
- *to++ = *from++;
- return;
-}
-
-#endif not bcopy
-
-#ifndef bzero
-
-void
-bzero(ptr, num)
- register char *ptr;
- register int num;
-{
- while (num-- > 0)
- *ptr++ = '\0';
- return;
-}
-
-#endif not bzero
-
-/* This might not be around... If not then forget about sorting... */
-
-void qsort() {}
-
-#endif BSD
-
-char *
-gettok(s)
- char **s;
-{
- char buf[BSIZE];
- int i = 0;
-
- while (isspace(**s))
- (*s)++;
- if (!**s)
- return (NULL);
- while (**s && !isspace(**s))
- buf[i++] = *(*s)++;
- buf[i] = '\0';
- while (isspace(**s))
- (*s)++;
- return (copy(buf));
-}
-
-/* Die horribly. */
-
-/* VARARGS1 */
-void
-fatal(s, args)
- char *s;
-{
- fputs("Internal Error: ", stderr);
-#ifndef __FreeBSD__
- _doprnt(s, &args, stderr);
-#endif
- putc('\n', stderr);
-
- kill(getpid(), SIGIOT);
- /* NOTREACHED */
-}
-
-void
-setenv(name, value)
- char *name, *value;
-{
- int i;
- char **xx, *s;
-
- s = tmalloc(strlen(name) + 2);
- sprintf(s, "%s=", name);
-
- /* Copy the old environment... */
- for (i = 0; environ[i]; i++)
- if (prefix(s, environ[i]))
- break;
- if (!environ[i]) {
- xx = (char **) tmalloc((i + 2) * sizeof (char *));
- for (i = 0; environ[i]; i++)
- xx[i] = environ[i];
- xx[i + 1] = NULL;
- environ = xx;
- } else
- xx = environ;
-
- xx[i] = tmalloc(strlen(name) + strlen(value) + 2);
- sprintf(xx[i], "%s=%s", name, value);
- return;
-}
-
-char *
-getusername()
-{
- int i = getuid();
- struct passwd *pw = getpwuid(i);
-
- return (pw ? pw->pw_name : NULL);
-}
-
-char *
-gethome()
-{
- int i = getuid();
- struct passwd *pw = getpwuid(i);
-
- return (pw ? pw->pw_dir : "/strange");
-}
-
-char *
-tildexpand(s)
- char *s;
-{
- struct passwd *pw;
- char *n, buf[64];
- int i;
-
- if (*s != '~')
- return (copy(s));
-
- for (s++, i = 0; *s != '/'; s++, i++)
- buf[i] = *s;
- buf[i] = '\0';
- if (!i)
- pw = getpwuid(getuid());
- else
- pw = getpwnam(buf);
- if (!pw)
- return (s);
- n = tmalloc(strlen(s) + strlen(pw->pw_dir) + 1);
- strcpy(n, pw->pw_dir);
- strcat(n, s);
- return (n);
-}
-
diff --git a/gnu/games/chess/Xchess/std.h b/gnu/games/chess/Xchess/std.h
deleted file mode 100644
index 19cb1da..0000000
--- a/gnu/games/chess/Xchess/std.h
+++ /dev/null
@@ -1,105 +0,0 @@
-
-/* This file contains code for X-CHESS.
- Copyright (C) 1986 Free Software Foundation, Inc.
-
-This file is part of X-CHESS.
-
-X-CHESS is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY. No author or distributor
-accepts responsibility to anyone for the consequences of using it
-or for whether it serves any particular purpose or works at all,
-unless he says so in writing. Refer to the X-CHESS General Public
-License for full details.
-
-Everyone is granted permission to copy, modify and redistribute
-X-CHESS, but only under the conditions described in the
-X-CHESS General Public License. A copy of this license is
-supposed to have been given to you along with X-CHESS so you
-can know your rights and responsibilities. It should be in a
-file named COPYING. Among other things, the copyright notice
-and this notice must be preserved on all copies. */
-
-
-/* RCS Info: $Revision: 1.1.1.1 $ on $Date: 1993/06/12 14:41:06 $
- * $Source: /home/ncvs/src/gnu/games/chess/Xchess/std.h,v $
- * Copyright (c) 1986 Wayne A. Christopher, U. C. Berkeley CAD Group
- *
- * Standard definitions.
- */
-
-#define UNIX
-#define BSD
-
-#ifndef FILE
-#include <stdio.h>
-#endif
-#ifndef isalpha
-#include <ctype.h>
-#endif
-#ifndef HUGE
-#include <math.h>
-#endif
-#include <strings.h>
-
-typedef int bool;
-
-#define false 0
-#define true 1
-
-/* Externs defined in std.c */
-
-extern char *tmalloc();
-extern char *trealloc();
-extern char *copy();
-extern char *datestring();
-extern char *getusername();
-extern char *gethome();
-extern char *gettok();
-extern char *tildexpand();
-extern void fatal();
-extern void setenv();
-extern void appendc();
-extern int scannum();
-extern int seconds();
-extern bool prefix();
-extern bool ciprefix();
-extern bool cieq();
-extern bool substring();
-
-/* Externs from libc */
-
-extern char *getenv();
-extern int errno;
-/* extern char *sys_errlist[]; */
-
-/* Should use BSIZE instead of BUFSIZ... */
-
-#define BSIZE 512
-
-/* Some standard macros. */
-
-#define eq(a,b) (!strcmp((a), (b)))
-#define isalphanum(c) (isalpha(c) || isdigit(c))
-#define alloc(strname) ((struct strname *) tmalloc(sizeof(struct strname)))
-#define tfree(ptr) { if (ptr) free((char *) ptr); ptr = 0; }
-#define hexnum(c) ((((c) >= '0') && ((c) <= '9')) ? ((c) - '0') : ((((c) >= \
- 'a') && ((c) <= 'f')) ? ((c) - 'a' + 10) : ((((c) >= 'A') && \
- ((c) <= 'F')) ? ((c) - 'A' + 10) : 0)))
-
-#ifndef BSD
-#define random rand
-#define srandom srand
-#endif BSD
-
-#ifdef VMS
-
-#define EXIT_NORMAL 1
-#define EXIT_BAD 0
-
-#else VMS
-
-#define EXIT_NORMAL 0
-#define EXIT_BAD 1
-
-#endif VMS
-
diff --git a/gnu/games/chess/Xchess/valid.c b/gnu/games/chess/Xchess/valid.c
deleted file mode 100644
index 06d1f29..0000000
--- a/gnu/games/chess/Xchess/valid.c
+++ /dev/null
@@ -1,264 +0,0 @@
-
-/* This file contains code for X-CHESS.
- Copyright (C) 1986 Free Software Foundation, Inc.
-
-This file is part of X-CHESS.
-
-X-CHESS is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY. No author or distributor
-accepts responsibility to anyone for the consequences of using it
-or for whether it serves any particular purpose or works at all,
-unless he says so in writing. Refer to the X-CHESS General Public
-License for full details.
-
-Everyone is granted permission to copy, modify and redistribute
-X-CHESS, but only under the conditions described in the
-X-CHESS General Public License. A copy of this license is
-supposed to have been given to you along with X-CHESS so you
-can know your rights and responsibilities. It should be in a
-file named COPYING. Among other things, the copyright notice
-and this notice must be preserved on all copies. */
-
-
-/* RCS Info: $Revision: 1.1.1.1 $ on $Date: 1993/06/12 14:41:08 $
- * $Source: /home/ncvs/src/gnu/games/chess/Xchess/valid.c,v $
- * Copyright (c) 1986 Wayne A. Christopher, U. C. Berkeley CAD Group
- * Permission is granted to do anything with this code except sell it
- * or remove this message.
- *
- * Validate a move.
- */
-
-#include "xchess.h"
-
-extern bool ischeck(), couldmove();
-
-bool
-valid_move(m, b)
- move *m;
- board *b;
-{
- board tb;
-
- /* First check that the piece can make the move at all... */
- if (!couldmove(m, b))
- return (false);
-
- /* Now see if the king is in check now. */
- bcopy((char *) b, (char *) &tb, sizeof (board));
- board_move(&tb, m);
- if (ischeck(&tb, m->piece.color))
- return (false);
-
- if (ischeck(&tb, ((m->piece.color == WHITE) ? BLACK : WHITE)))
- m->check = true;
-
- return (true);
-}
-
-static bool
-couldmove(m, b)
- move *m;
- board *b;
-{
- int x, y;
-
- switch (m->type) {
- case KCASTLE:
- if ((m->piece.color == WHITE) && (b->white_cant_castle_k) ||
- (m->piece.color == BLACK) &&
- (b->black_cant_castle_k))
- return (false);
- if ((b->square[m->fromy][5].color != NONE) ||
- (b->square[m->fromy][6].color != NONE))
- return (false);
- if (ischeck(b, m->piece.color))
- return (false);
- break;
-
- case QCASTLE:
- if ((m->piece.color == WHITE) && (b->white_cant_castle_q) ||
- (m->piece.color == BLACK) &&
- (b->black_cant_castle_q))
- return (false);
- if ((b->square[m->fromy][1].color != NONE) ||
- (b->square[m->fromy][2].color != NONE) ||
- (b->square[m->fromy][3].color != NONE))
- return (false);
- if (ischeck(b, m->piece.color))
- return (false);
- break;
-
- case MOVE:
- case CAPTURE:
- /* There is one special case here, that of taking a pawn
- * en passant. In this case we change the move field to
- * CAPTURE if it's ok.
- */
- switch (m->piece.type) {
- case PAWN:
- if ((m->type == MOVE) && (m->fromx == m->tox)) {
- /* A normal move. */
- if ((m->piece.color == WHITE) && (m->fromy ==
- m->toy + 1))
- break;
- if ((m->piece.color == WHITE) && (m->fromy ==
- 6) && (m->toy == 4) &&
- (b->square[5][m->fromx].color
- == NONE))
- break;
- if ((m->piece.color == BLACK) && (m->fromy ==
- m->toy - 1))
- break;
- if ((m->piece.color == BLACK) && (m->fromy ==
- 1) && (m->toy == 3) &&
- (b->square[2][m->fromx].color
- == NONE))
- break;
- return (false);
- } else if (m->type == CAPTURE) {
- if ((((m->piece.color == WHITE) && (m->fromy ==
- m->toy + 1)) || ((m->piece.color ==
- BLACK) && (m->fromy == m->toy -
- 1))) && ((m->fromx == m->tox + 1) ||
- (m->fromx == m->tox - 1)))
- break;
- /* Now maybe it's enpassant... We've already
- * checked for some of these things in the
- * calling routine.
- */
- if (m->enpassant) {
- if (b->square[(m->piece.color == WHITE)
- ? 3 : 4][m->tox].color ==
- ((m->piece.color == WHITE) ?
- BLACK : WHITE))
- break;
- }
- return (false);
- }
- return (false);
-
- case ROOK:
- if (m->fromx == m->tox) {
- for (y = m->fromy + ((m->fromy > m->toy) ? -1 :
- 1); y != m->toy; y += ((m->fromy
- > m->toy) ? -1 : 1))
- if (b->square[y][m->tox].color != NONE)
- return (false);
- break;
- }
- if (m->fromy == m->toy) {
- for (x = m->fromx + ((m->fromx > m->tox) ? -1 :
- 1); x != m->tox; x += ((m->fromx
- > m->tox) ? -1 : 1))
- if (b->square[m->toy][x].color != NONE)
- return (false);
- break;
- }
- return (false);
-
- case KNIGHT:
- x = m->fromx - m->tox;
- y = m->fromy - m->toy;
- if ((((x == 2) || (x == -2)) &&
- ((y == 1) || (y == -1))) ||
- (((x == 1) || (x == -1)) &&
- ((y == 2) || (y == -2))))
- break;
- return (false);
-
- case BISHOP:
- x = m->fromx - m->tox;
- y = m->fromy - m->toy;
- if ((x != y) && (x != - y))
- return (false);
- for (x = m->fromx + ((m->fromx > m->tox) ? -1 : 1), y =
- m->fromy + ((m->fromy > m->toy) ? -1 :
- 1); x != m->tox;
- x += ((m->fromx > m->tox) ? -1 : 1),
- y += ((m->fromy > m->toy) ? -1 : 1))
- if (b->square[y][x].color != NONE)
- return (false);
- break;
-
- case QUEEN:
- if (m->fromx == m->tox) {
- for (y = m->fromy + ((m->fromy > m->toy) ? -1 :
- 1); y != m->toy; y += ((m->fromy
- > m->toy) ? -1 : 1))
- if (b->square[y][m->tox].color != NONE)
- return (false);
- break;
- }
- if (m->fromy == m->toy) {
- for (x = m->fromx + ((m->fromx > m->tox) ? -1 :
- 1); x != m->tox; x += ((m->fromx
- > m->tox) ? -1 : 1))
- if (b->square[m->toy][x].color != NONE)
- return (false);
- break;
- }
- x = m->fromx - m->tox;
- y = m->fromy - m->toy;
- if ((x != y) && (x != - y))
- return (false);
- for (x = m->fromx + ((m->fromx > m->tox) ? -1 : 1), y =
- m->fromy + ((m->fromy > m->toy) ? -1 :
- 1); x != m->tox;
- x += ((m->fromx > m->tox) ? -1 : 1),
- y += ((m->fromy > m->toy) ? -1 : 1))
- if (b->square[y][x].color != NONE)
- return (false);
- break;
-
- case KING:
- x = m->fromx - m->tox;
- y = m->fromy - m->toy;
- if ((x >= -1) && (x <= 1) && (y >= -1) && (y <= 1))
- break;
- return (false);
- }
- break;
- }
- return (true);
-}
-
-/* Say whether either king is in check... If move is non-NULL, say whether he
- * in in check after the move takes place. We do this in a rather stupid way.
- */
-
-static bool
-ischeck(b, col)
- board *b;
- color col;
-{
- int x, y, kx, ky;
- move ch;
-
- for (x = 0; x < SIZE; x++)
- for (y = 0; y < SIZE; y++)
- if ((b->square[y][x].color == col) &&
- (b->square[y][x].type == KING)) {
- kx = x;
- ky = y;
- }
-
- for (x = 0; x < SIZE; x++)
- for (y = 0; y < SIZE; y++)
- if (b->square[y][x].color == ((col == WHITE) ?
- BLACK : WHITE)) {
- ch.type = CAPTURE;
- ch.piece.color = b->square[y][x].color;
- ch.piece.type = b->square[y][x].type;
- ch.fromx = x;
- ch.fromy = y;
- ch.tox = kx;
- ch.toy = ky;
- ch.enpassant = false;
- if (couldmove(&ch, b))
- return (true);
- }
-
- return (false);
-}
-
diff --git a/gnu/games/chess/Xchess/window.c b/gnu/games/chess/Xchess/window.c
deleted file mode 100644
index c33ef81..0000000
--- a/gnu/games/chess/Xchess/window.c
+++ /dev/null
@@ -1,952 +0,0 @@
-/* This file contains code for X-CHESS.
- Copyright (C) 1986 Free Software Foundation, Inc.
-
-This file is part of X-CHESS.
-
-X-CHESS is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY. No author or distributor
-accepts responsibility to anyone for the consequences of using it
-or for whether it serves any particular purpose or works at all,
-unless he says so in writing. Refer to the X-CHESS General Public
-License for full details.
-
-Everyone is granted permission to copy, modify and redistribute
-X-CHESS, but only under the conditions described in the
-X-CHESS General Public License. A copy of this license is
-supposed to have been given to you along with X-CHESS so you
-can know your rights and responsibilities. It should be in a
-file named COPYING. Among other things, the copyright notice
-and this notice must be preserved on all copies. */
-
-
-/* RCS Info: $Revision: 1.1.1.1 $ on $Date: 1993/06/12 14:41:08 $
- * $Source: /home/ncvs/src/gnu/games/chess/Xchess/window.c,v $
- * Copyright (c) 1986 Wayne A. Christopher, U. C. Berkeley CAD Group
- * Permission is granted to do anything with this code except sell it
- * or remove this message.
- *
- * Deal with the two (or one) windows.
- */
-
-#include "xchess.h"
-#include <X11/Xutil.h>
-#include <sys/time.h>
-
-#include "pawn.bitmap"
-#include "rook.bitmap"
-#include "knight.bitmap"
-#include "bishop.bitmap"
-#include "queen.bitmap"
-#include "king.bitmap"
-
-#include "pawn_outline.bitmap"
-#include "rook_outline.bitmap"
-#include "knight_outline.bitmap"
-#include "bishop_outline.bitmap"
-#include "queen_outline.bitmap"
-#include "king_outline.bitmap"
-
-#include "pawn_mask.bitmap"
-#include "rook_mask.bitmap"
-#include "knight_mask.bitmap"
-#include "bishop_mask.bitmap"
-#include "queen_mask.bitmap"
-#include "king_mask.bitmap"
-
-#include "shade.bitmap"
-
-#include "xchess.cur"
-#include "xchess_mask.cur"
-
-#include "xchess.icon"
-
-windata *win1, *win2;
-bool win_flashmove = false;
-
-extern bool setup();
-extern void service(), drawgrid(), icon_refresh();
-
-bool
-win_setup(disp1, disp2)
- char *disp1, *disp2;
-{
- win1 = alloc(windata);
- if (!oneboard)
- win2 = alloc(windata);
-
- if (!setup(disp1, win1) || (!oneboard && !setup(disp2, win2)))
- return (false);
-
- if (blackflag) {
- win1->color = BLACK;
- win1->flipped = true;
- } else
- win1->color = WHITE;
- win_drawboard(win1);
-
- if (!oneboard) {
- win2->color = BLACK;
- win2->flipped = true;
- win_drawboard(win2);
- }
-
- return(true);
-}
-
-/* Draw the chess board... */
-
-void
-win_drawboard(win)
- windata *win;
-{
- int i, j;
-
- drawgrid(win);
-
- /* Now toss on the squares... */
- for (i = 0; i < SIZE; i++)
- for (j = 0; j < SIZE; j++)
- win_erasepiece(j, i, win->color);
-
- return;
-}
-
-/* Draw one piece. */
-
-void
-win_drawpiece(p, y, x, wnum)
- piece *p;
- int y, x;
- color wnum;
-{
- char *bits, *maskbits, *outline;
- windata *win;
- char buf[BSIZE];
- XImage *tmpImage;
- Pixmap tmpPM, maskPM;
- XGCValues gc;
-
- if (oneboard || (wnum == win1->color))
- win = win1;
- else
- win = win2;
-
- if (win->flipped) {
- y = SIZE - y - 1;
- x = SIZE - x - 1;
- }
-
- /*
- if (debug)
- fprintf(stderr, "draw a %s at (%d, %d) on board %d\n",
- piecenames[(int) p->type], y, x, wnum);
- */
-
- if ((x < 0) || (x > 7) || (y < 0) || (y > 7)) exit(1);
-
- switch (p->type) {
- case PAWN:
- bits = pawn_bits;
- maskbits = pawn_mask_bits;
- outline = pawn_outline_bits;
- break;
-
- case ROOK:
- bits = rook_bits;
- maskbits = rook_mask_bits;
- outline = rook_outline_bits;
- break;
-
- case KNIGHT:
- bits = knight_bits;
- maskbits = knight_mask_bits;
- outline = knight_outline_bits;
- break;
-
- case BISHOP:
- bits = bishop_bits;
- maskbits = bishop_mask_bits;
- outline = bishop_outline_bits;
- break;
-
- case QUEEN:
- bits = queen_bits;
- maskbits = queen_mask_bits;
- outline = queen_outline_bits;
- break;
-
- case KING:
- bits = king_bits;
- maskbits = king_mask_bits;
- outline = king_outline_bits;
- break;
-
- default:
- fprintf(stderr,
- "Internal Error: win_drawpiece: bad piece type %d\n",
- p->type);
- }
-
- /* There are two things we can do... If this is a black and white
- * display, we have to shade the square and use an outline if the piece
- * is white. We also have to use a mask... Since we don't want
- * to use up too many bitmaps, create the mask bitmap, put the bits,
- * and then destroy it.
- */
- if (win->bnw && (p->color == WHITE))
- bits = outline;
- if (win->bnw && !iswhite(win, x, y)) {
- XSetState(win->display, DefaultGC(win->display, 0),
- BlackPixel(win->display, 0),
- WhitePixel(win->display, 0), GXcopy, AllPlanes);
-
- tmpPM = XCreateBitmapFromData(win->display, win->boardwin,
- shade_bits, SQUARE_WIDTH, SQUARE_HEIGHT);
-
- XCopyPlane(win->display, tmpPM, win->boardwin, DefaultGC(win->display, 0),
- 0, 0, SQUARE_WIDTH, SQUARE_HEIGHT,
- x * (SQUARE_WIDTH + BORDER_WIDTH),
- y * (SQUARE_HEIGHT + BORDER_WIDTH), 1);
-
- XFreePixmap(win->display, tmpPM);
-
- XSetFunction(win->display, DefaultGC(win->display, 0),
- GXandInverted);
- maskPM = XCreateBitmapFromData(win->display, win->boardwin,
- maskbits, SQUARE_WIDTH, SQUARE_HEIGHT);
- XCopyPlane(win->display, maskPM, win->boardwin, DefaultGC(win->display, 0),
- 0, 0, SQUARE_WIDTH, SQUARE_HEIGHT,
- x * (SQUARE_WIDTH + BORDER_WIDTH),
- y * (SQUARE_HEIGHT + BORDER_WIDTH), 1);
- XFreePixmap(win->display, maskPM);
-
- XSetFunction(win->display, DefaultGC(win->display, 0),
- GXor);
- tmpPM = XCreateBitmapFromData(win->display, win->boardwin,
- bits, SQUARE_WIDTH, SQUARE_HEIGHT);
- XCopyPlane(win->display, tmpPM, win->boardwin, DefaultGC(win->display, 0),
- 0, 0, SQUARE_WIDTH, SQUARE_HEIGHT,
- x * (SQUARE_WIDTH + BORDER_WIDTH),
- y * (SQUARE_HEIGHT + BORDER_WIDTH), 1);
- XFreePixmap(win->display, tmpPM);
-
- XSetFunction(win->display, DefaultGC(win->display, 0), GXcopy);
-
- } else if (win->bnw){
- XSetState(win->display, DefaultGC(win->display, 0),
- BlackPixel(win->display, 0),
- WhitePixel(win->display, 0), GXcopy, AllPlanes);
-
- tmpPM = XCreateBitmapFromData(win->display, win->boardwin,
- bits, SQUARE_WIDTH, SQUARE_HEIGHT);
- XCopyPlane(win->display, tmpPM, win->boardwin, DefaultGC(win->display, 0),
- 0, 0, SQUARE_WIDTH, SQUARE_HEIGHT,
- x * (SQUARE_WIDTH + BORDER_WIDTH),
- y * (SQUARE_HEIGHT + BORDER_WIDTH), 1);
- XFreePixmap(win->display, tmpPM);
- } else {
- XSetState(win->display, DefaultGC(win->display, 0),
- ((p->color == WHITE) ? win->whitepiece.pixel :
- win->blackpiece.pixel),
- (iswhite(win, x, y) ? win->whitesquare.pixel :
- win->blacksquare.pixel),
- GXcopy, AllPlanes);
- tmpPM = XCreateBitmapFromData(win->display, win->boardwin,
- bits, SQUARE_WIDTH, SQUARE_HEIGHT);
- XCopyPlane(win->display, tmpPM, win->boardwin, DefaultGC(win->display, 0),
- 0, 0, SQUARE_WIDTH, SQUARE_HEIGHT,
- x * (SQUARE_WIDTH + BORDER_WIDTH),
- y * (SQUARE_HEIGHT + BORDER_WIDTH), 1);
- XFreePixmap(win->display, tmpPM);
- }
-
- if (!record_english) {
- gc.foreground = win->textcolor.pixel;
- if (iswhite(win, x, y) || win->bnw)
- gc.background = win->whitesquare.pixel;
- else
- gc.background = win->blacksquare.pixel;
-
- gc.font = win->small->fid;
-
- XChangeGC(win->display, DefaultGC(win->display, 0),
- GCForeground | GCBackground | GCFont, &gc);
-
- if (!x) {
- sprintf(buf, " %d", SIZE - y);
- XDrawImageString(win->display, win->boardwin,
- DefaultGC(win->display, 0),
- 1, (y + 1) * (SQUARE_HEIGHT +
- BORDER_WIDTH) - BORDER_WIDTH +
- win->small->max_bounds.ascent - 1, buf, 2);
- }
- if (y == SIZE - 1) {
- sprintf(buf, "%c", 'A' + x);
- XDrawImageString(win->display, win->boardwin,
- DefaultGC(win->display, 0),
- x * (SQUARE_WIDTH + BORDER_WIDTH) + 1,
- SIZE * (SQUARE_HEIGHT + BORDER_WIDTH) - BORDER_WIDTH +
- win->small->max_bounds.ascent - 1, buf, 1);
- }
- }
- return;
-}
-
-void
-win_erasepiece(y, x, wnum)
- int y, x;
- color wnum;
-{
- windata *win;
- char buf[BSIZE];
- XGCValues gc;
- Pixmap tmpPM;
-
- if (oneboard || (wnum == win1->color))
- win = win1;
- else
- win = win2;
-
- if (win->flipped) {
- y = SIZE - y - 1;
- x = SIZE - x - 1;
- }
-
- /*
- if (debug)
- fprintf(stderr, "erase square (%d, %d) on board %d\n", y, x,
- wnum);
- */
-
- if ((x < 0) || (x > 7) || (y < 0) || (y > 7)) exit(1);
-
- if (win->bnw && !iswhite(win, x, y)) {
- XSetState(win->display, DefaultGC(win->display, 0),
- BlackPixel(win->display, 0),
- WhitePixel(win->display, 0), GXcopy, AllPlanes);
- tmpPM = XCreateBitmapFromData(win->display, win->boardwin,
- shade_bits, SQUARE_WIDTH, SQUARE_HEIGHT);
-
- XCopyPlane(win->display, tmpPM, win->boardwin, DefaultGC(win->display, 0),
- 0, 0, SQUARE_WIDTH, SQUARE_HEIGHT,
- x * (SQUARE_WIDTH + BORDER_WIDTH),
- y * (SQUARE_HEIGHT + BORDER_WIDTH), 1);
-
- XFreePixmap(win->display, tmpPM);
- } else {
- XSetFillStyle(win->display, DefaultGC(win->display, 0),
- FillSolid);
- XSetForeground(win->display, DefaultGC(win->display, 0),
- iswhite(win, x, y) ? win->whitesquare.pixel :
- win->blacksquare.pixel);
- XFillRectangle(win->display, win->boardwin,
- DefaultGC(win->display, 0),
- x * (SQUARE_WIDTH + BORDER_WIDTH),
- y * (SQUARE_HEIGHT + BORDER_WIDTH),
- SQUARE_WIDTH, SQUARE_HEIGHT);
- }
-
- if (!record_english) {
- gc.foreground = win->textcolor.pixel;
- if (iswhite(win, x, y) || win->bnw)
- gc.background = win->whitesquare.pixel;
- else
- gc.background = win->blacksquare.pixel;
-
- gc.font = win->small->fid;
-
- XChangeGC(win->display, DefaultGC(win->display, 0),
- GCForeground | GCBackground | GCFont, &gc);
-
- if (!x) {
- sprintf(buf, " %d", SIZE - y);
- XDrawImageString(win->display, win->boardwin,
- DefaultGC(win->display, 0),
- 1, (y + 1) * (SQUARE_HEIGHT +
- BORDER_WIDTH) - BORDER_WIDTH +
- win->small->max_bounds.ascent - 1, buf, 2);
- }
- if (y == SIZE - 1) {
- sprintf(buf, "%c", 'A' + x);
- XDrawImageString(win->display, win->boardwin,
- DefaultGC(win->display, 0),
- x * (SQUARE_WIDTH + BORDER_WIDTH) + 1,
- SIZE * (SQUARE_HEIGHT + BORDER_WIDTH) - BORDER_WIDTH +
- win->small->max_bounds.ascent - 1, buf, 1);
- }
- }
-
-
- return;
-}
-
-void
-win_flash(m, wnum)
- move *m;
- color wnum;
-{
- windata *win;
- int sx, sy, ex, ey, i;
-
- if (oneboard || (wnum == win1->color))
- win = win1;
- else
- win = win2;
-
- if (win->flipped) {
- sx = SIZE - m->fromx - 1;
- sy = SIZE - m->fromy - 1;
- ex = SIZE - m->tox - 1;
- ey = SIZE - m->toy - 1;
- } else {
- sx = m->fromx;
- sy = m->fromy;
- ex = m->tox;
- ey = m->toy;
- }
- sx = sx * (SQUARE_WIDTH + BORDER_WIDTH) + SQUARE_WIDTH / 2;
- sy = sy * (SQUARE_HEIGHT + BORDER_WIDTH) + SQUARE_HEIGHT / 2;
- ex = ex * (SQUARE_WIDTH + BORDER_WIDTH) + SQUARE_WIDTH / 2;
- ey = ey * (SQUARE_HEIGHT + BORDER_WIDTH) + SQUARE_HEIGHT / 2;
-
- XSetFunction(win->display, DefaultGC(win->display, 0), GXinvert);
- XSetLineAttributes(win->display, DefaultGC(win->display, 0),
- 0, LineSolid, 0, 0);
- for (i = 0; i < num_flashes * 2; i++) {
- XDrawLine(win->display,win->boardwin,
- DefaultGC(win->display, 0),
- sx, sy, ex, ey);
- }
-
- XSetFunction(win->display, DefaultGC(win->display, 0), GXcopy);
- return;
-}
-
-/* Handle input from the players. */
-
-void
-win_process(quick)
- bool quick;
-{
- int i, rfd = 0, wfd = 0, xfd = 0;
- struct timeval timeout;
-
- timeout.tv_sec = 0;
- timeout.tv_usec = (quick ? 0 : 500000);
-
- if (XPending(win1->display))
- service(win1);
- if (!oneboard) {
- if (XPending(win1->display))
- service(win2);
- }
-
- if (oneboard)
- rfd = 1 << win1->display->fd;
- else
- rfd = (1 << win1->display->fd) | (1 << win2->display->fd);
- if (!(i = select(32, &rfd, &wfd, &xfd, &timeout)))
- return;
- if (i == -1) {
- perror("select");
- exit(1);
- }
- if (rfd & (1 << win1->display->fd))
- service(win1);
- if (!oneboard && (rfd & (1 << win2->display->fd)))
- service(win2);
-
- return;
-}
-
-static void
-service(win)
- windata *win;
-{
- XEvent ev;
-
- while(XPending(win->display)) {
- XNextEvent(win->display, &ev);
- if (TxtFilter(win->display, &ev))
- continue;
-
- if (ev.xany.window == win->boardwin) {
- switch (ev.type) {
- case ButtonPress:
- button_pressed(&ev, win);
- break;
-
- case ButtonRelease:
- button_released(&ev, win);
- break;
-
- case Expose:
- /* Redraw... */
- win_redraw(win, &ev);
- break;
-
- case 0:
- case NoExpose:
- break;
- default:
- fprintf(stderr, "Bad event type %d\n", ev.type);
- exit(1);
- }
- } else if (ev.xany.window == win->wclockwin) {
- switch (ev.type) {
- case Expose:
- clock_draw(win, WHITE);
- break;
-
- case 0:
- case NoExpose:
- break;
- default:
- fprintf(stderr, "Bad event type %d\n", ev.type);
- exit(1);
- }
- } else if (ev.xany.window == win->bclockwin) {
- switch (ev.type) {
- case Expose:
- clock_draw(win, BLACK);
- break;
-
- case 0:
- case NoExpose:
- break;
- default:
- fprintf(stderr, "Bad event type %d\n", ev.type);
- exit(1);
- }
- } else if (ev.xany.window == win->jailwin) {
- switch (ev.type) {
- case Expose:
- jail_draw(win);
- break;
-
- case 0:
- case NoExpose:
- break;
- default:
- fprintf(stderr, "Bad event type %d\n", ev.type);
- exit(1);
- }
- } else if (ev.xany.window == win->buttonwin) {
- switch (ev.type) {
- case ButtonPress:
- button_service(win, &ev);
- break;
-
- case Expose:
- button_draw(win);
- break;
-
- case 0:
- case NoExpose:
- break;
- default:
- fprintf(stderr, "Bad event type %d\n", ev.type);
- exit(1);
- }
- } else if (ev.xany.window == win->icon) {
- icon_refresh(win);
- } else if (ev.xany.window == win->basewin) {
- message_send(win, &ev);
- } else {
- fprintf(stderr, "Internal Error: service: bad win\n");
- fprintf(stderr, "window = %d, event = %d\n", ev.xany.window,
- ev.type);
- }
- }
- return;
-}
-
-void
-win_redraw(win, event)
- windata *win;
- XEvent *event;
-{
- XExposeEvent *ev = &event->xexpose;
- int x1, y1, x2, y2, i, j;
-
- drawgrid(win);
- if (ev) {
- x1 = ev->x / (SQUARE_WIDTH + BORDER_WIDTH);
- y1 = ev->y / (SQUARE_HEIGHT + BORDER_WIDTH);
- x2 = (ev->x + ev->width) / (SQUARE_WIDTH + BORDER_WIDTH);
- y2 = (ev->y + ev->height) / (SQUARE_HEIGHT + BORDER_WIDTH);
- } else {
- x1 = 0;
- y1 = 0;
- x2 = SIZE - 1;
- y2 = SIZE - 1;
- }
-
- if (x1 < 0) x1 = 0;
- if (y1 < 0) y1 = 0;
- if (x2 < 0) x2 = 0;
- if (y2 < 0) y2 = 0;
- if (x1 > SIZE - 1) x1 = SIZE - 1;
- if (y1 > SIZE - 1) y1 = SIZE - 1;
- if (x2 > SIZE - 1) x2 = SIZE - 1;
- if (y2 > SIZE - 1) y2 = SIZE - 1;
-
- if (win->flipped) {
- y1 = SIZE - y2 - 1;
- y2 = SIZE - y1 - 1;
- x1 = SIZE - x2 - 1;
- x2 = SIZE - x1 - 1;
- }
-
- for (i = x1; i <= x2; i++)
- for (j = y1; j <= y2; j++) {
- if (chessboard->square[j][i].color == NONE)
- win_erasepiece(j, i, WHITE);
- else
- win_drawpiece(&chessboard->square[j][i], j, i,
- WHITE);
- if (!oneboard) {
- if (chessboard->square[j][i].color == NONE)
- win_erasepiece(j, i, BLACK);
- else
- win_drawpiece(&chessboard->square[j][i],
- j, i, BLACK);
- }
- }
-
- return;
-}
-
-static bool
-setup(dispname, win)
- char *dispname;
- windata *win;
-{
- char buf[BSIZE], *s;
- Pixmap bm, bmask;
- Cursor cur;
- extern char *program, *recfile;
- XSizeHints xsizes;
-
-
- if (!(win->display = XOpenDisplay(dispname)))
- return (false);
-
-
- /* Now get boolean defaults... */
- if ((s = XGetDefault(win->display, program, "noisy")) && eq(s, "on"))
- noisyflag = true;
- if ((s = XGetDefault(win->display, program, "savemoves")) && eq(s, "on"))
- saveflag = true;
- if ((s = XGetDefault(win->display, program, "algebraic")) && eq(s, "on"))
- record_english = false;
- if ((s = XGetDefault(win->display, program, "blackandwhite")) && eq(s, "on"))
- bnwflag = true;
- if ((s = XGetDefault(win->display, program, "quickrestore")) && eq(s, "on"))
- quickflag = true;
- if ((s = XGetDefault(win->display, program, "flash")) && eq(s, "on"))
- win_flashmove = true;
-
- /* ... numeric variables ... */
- if (s = XGetDefault(win->display, program, "numflashes"))
- num_flashes = atoi(s);
- if (s = XGetDefault(win->display, program, "flashsize"))
- flash_size = atoi(s);
-
- /* ... and strings. */
- if (s = XGetDefault(win->display, program, "progname"))
- progname = s;
- if (s = XGetDefault(win->display, program, "proghost"))
- proghost = s;
- if (s = XGetDefault(win->display, program, "recordfile"))
- recfile = s;
- if (s = XGetDefault(win->display, program, "blackpiece"))
- black_piece_color = s;
- if (s = XGetDefault(win->display, program, "whitepiece"))
- white_piece_color = s;
- if (s = XGetDefault(win->display, program, "blacksquare"))
- black_square_color = s;
- if (s = XGetDefault(win->display, program, "whitesquare"))
- white_square_color = s;
- if (s = XGetDefault(win->display, program, "bordercolor"))
- border_color = s;
- if (s = XGetDefault(win->display, program, "textcolor"))
- text_color = s;
- if (s = XGetDefault(win->display, program, "textback"))
- text_back = s;
- if (s = XGetDefault(win->display, program, "errortext"))
- error_text = s;
- if (s = XGetDefault(win->display, program, "playertext"))
- player_text = s;
- if (s = XGetDefault(win->display, program, "cursorcolor"))
- cursor_color = s;
-
- if ((DisplayPlanes(win->display, 0) == 1) || bnwflag)
- win->bnw = true;
-
- /* Allocate colors... */
- if (win->bnw) {
- win->blackpiece.pixel = BlackPixel (win->display, 0);
- win->whitepiece.pixel = WhitePixel (win->display, 0);
- win->blacksquare.pixel = BlackPixel (win->display, 0);
- win->whitesquare.pixel = WhitePixel (win->display, 0);
- win->border.pixel = BlackPixel (win->display, 0);
- win->textcolor.pixel = BlackPixel (win->display, 0);
- win->textback.pixel = WhitePixel (win->display, 0);
- win->playertext.pixel = BlackPixel (win->display, 0);
- win->errortext.pixel = BlackPixel (win->display, 0);
- win->cursorcolor.pixel = BlackPixel (win->display, 0) ;
- } else {
- if (!XParseColor(win->display,
- DefaultColormap(win->display, 0),
- black_piece_color, &win->blackpiece) ||
- !XParseColor(win->display,
- DefaultColormap(win->display, 0),
- white_piece_color, &win->whitepiece) ||
- !XParseColor(win->display,
- DefaultColormap(win->display, 0),
- black_square_color, &win->blacksquare) ||
- !XParseColor(win->display,
- DefaultColormap(win->display, 0),
- white_square_color, &win->whitesquare) ||
- !XParseColor(win->display,
- DefaultColormap(win->display, 0),
- border_color, &win->border) ||
- !XParseColor(win->display,
- DefaultColormap(win->display, 0),
- text_color, &win->textcolor) ||
- !XParseColor(win->display,
- DefaultColormap(win->display, 0),
- text_back, &win->textback) ||
- !XParseColor(win->display,
- DefaultColormap(win->display, 0),
- error_text, &win->errortext) ||
- !XParseColor(win->display,
- DefaultColormap(win->display, 0),
- player_text, &win->playertext) ||
- !XParseColor(win->display,
- DefaultColormap(win->display, 0),
- cursor_color, &win->cursorcolor) ||
- !XAllocColor(win->display,
- DefaultColormap(win->display, 0),
- &win->blackpiece) ||
- !XAllocColor(win->display,
- DefaultColormap(win->display, 0),
- &win->whitepiece) ||
- !XAllocColor(win->display,
- DefaultColormap(win->display, 0),
- &win->blacksquare) ||
- !XAllocColor(win->display,
- DefaultColormap(win->display, 0),
- &win->whitesquare) ||
- !XAllocColor(win->display,
- DefaultColormap(win->display, 0),
- &win->border) ||
- !XAllocColor(win->display,
- DefaultColormap(win->display, 0),
- &win->textcolor) ||
- !XAllocColor(win->display,
- DefaultColormap(win->display, 0),
- &win->textback) ||
- !XAllocColor(win->display,
- DefaultColormap(win->display, 0),
- &win->errortext) ||
- !XAllocColor(win->display,
- DefaultColormap(win->display, 0),
- &win->playertext) ||
- !XAllocColor(win->display,
- DefaultColormap(win->display, 0),
- &win->cursorcolor))
- fprintf(stderr, "Can't get colors...\n");
- }
-
- /* Get fonts... */
- if ((win->small = XLoadQueryFont(win->display,SMALL_FONT)) ==
- NULL)
- fprintf(stderr, "Can't get small font...\n");
-
- if ((win->medium = XLoadQueryFont(win->display,MEDIUM_FONT))
- == NULL)
- fprintf(stderr, "Can't get medium font...\n");
-
- if ((win->large = XLoadQueryFont(win->display,LARGE_FONT)) ==
- NULL)
- fprintf(stderr, "Can't get large font...\n");
-
-
- /* Create the windows... */
-
- win->basewin =
- XCreateSimpleWindow(win->display,DefaultRootWindow(win->display),
- BASE_XPOS, BASE_YPOS,
- BASE_WIDTH, BASE_HEIGHT, 0,
- BlackPixel(win->display, 0),
- WhitePixel(win->display, 0));
- win->boardwin = XCreateSimpleWindow(win->display,win->basewin,
- BOARD_XPOS, BOARD_YPOS,
- BOARD_WIDTH, BOARD_HEIGHT,
- BORDER_WIDTH,
- win->border.pixel,
- WhitePixel(win->display, 0));
- win->recwin = XCreateSimpleWindow(win->display,win->basewin,
- RECORD_XPOS, RECORD_YPOS,
- RECORD_WIDTH, RECORD_HEIGHT,
- BORDER_WIDTH, win->border.pixel,
- win->textback.pixel);
- win->jailwin = XCreateSimpleWindow(win->display,win->basewin,
- JAIL_XPOS, JAIL_YPOS,
- JAIL_WIDTH, JAIL_HEIGHT,
- BORDER_WIDTH,
- win->border.pixel,
- win->textback.pixel);
- win->wclockwin = XCreateSimpleWindow(win->display,win->basewin,
- WCLOCK_XPOS, WCLOCK_YPOS,
- CLOCK_WIDTH, CLOCK_HEIGHT,
- BORDER_WIDTH, win->border.pixel,
- win->textback.pixel);
- win->bclockwin = XCreateSimpleWindow(win->display,win->basewin,
- BCLOCK_XPOS, BCLOCK_YPOS,
- CLOCK_WIDTH, CLOCK_HEIGHT,
- BORDER_WIDTH, win->border.pixel,
- win->textback.pixel);
- win->messagewin = XCreateSimpleWindow(win->display,win->basewin,
- MESS_XPOS, MESS_YPOS,
- MESS_WIDTH, MESS_HEIGHT,
- BORDER_WIDTH, win->border.pixel,
- win->textback.pixel);
- win->buttonwin = XCreateSimpleWindow(win->display,win->basewin,
- BUTTON_XPOS, BUTTON_YPOS,
- BUTTON_WIDTH, BUTTON_HEIGHT,
- BORDER_WIDTH, win->border.pixel,
- win->textback.pixel);
-
- /* Let's define an icon... */
- win->iconpixmap = XCreatePixmapFromBitmapData(win->display,
- win->basewin, icon_bits,
- icon_width, icon_height,
- win->blacksquare.pixel,
- win->whitesquare.pixel,
- 1);
- xsizes.flags = PSize | PMinSize | PPosition;
- xsizes.min_width = BASE_WIDTH;
- xsizes.min_height = BASE_HEIGHT;
- xsizes.x = BASE_XPOS;
- xsizes.y = BASE_YPOS;
- XSetStandardProperties(win->display, win->basewin,
- program, program, win->iconpixmap,
- 0, NULL, &xsizes);
-
- bm = XCreateBitmapFromData(win->display,
- win->basewin, xchess_bits,
- xchess_width, xchess_height);
- bmask = XCreateBitmapFromData(win->display,
- win->basewin, xchess_mask_bits,
- xchess_width, xchess_height);
- cur = XCreatePixmapCursor(win->display, bm, bmask,
- &win->cursorcolor,
- &WhitePixel(win->display, 0),
- xchess_x_hot, xchess_y_hot);
- XFreePixmap(win->display, bm);
- XFreePixmap(win->display, bmask);
-
- XDefineCursor(win->display,win->basewin, cur);
-
- XMapSubwindows(win->display,win->basewin);
- XMapRaised(win->display,win->basewin);
-
- XSelectInput(win->display,win->basewin, KeyPressMask);
- XSelectInput(win->display,win->boardwin,
- ButtonPressMask | ButtonReleaseMask | ExposureMask);
- XSelectInput(win->display,win->recwin,
- ButtonReleaseMask | ExposureMask);
- XSelectInput(win->display,win->jailwin, ExposureMask);
- XSelectInput(win->display,win->wclockwin, ExposureMask);
- XSelectInput(win->display,win->bclockwin, ExposureMask);
- XSelectInput(win->display,win->messagewin,
- ButtonReleaseMask | ExposureMask);
- XSelectInput(win->display,win->buttonwin,
- ButtonPressMask | ExposureMask);
-
- message_init(win);
- record_init(win);
- button_draw(win);
- jail_init(win);
- clock_init(win, WHITE);
- clock_init(win, BLACK);
- if (timeunit) {
- if (timeunit > 1800)
- sprintf(buf, "%d moves every %.2lg hours.\n",
- movesperunit, ((double) timeunit) / 3600);
- else if (timeunit > 30)
- sprintf(buf, "%d moves every %.2lg minutes.\n",
- movesperunit, ((double) timeunit) / 60);
- else
- sprintf(buf, "%d moves every %d seconds.\n",
- movesperunit, timeunit);
- message_add(win, buf, false);
- }
- return (true);
-}
-
-static void
-drawgrid(win)
- windata *win;
-{
- int i;
- XGCValues gc;
-
- gc.function = GXcopy;
- gc.plane_mask = AllPlanes;
- gc.foreground = win->border.pixel;
- gc.line_width = 0;
- gc.line_style = LineSolid;
-
- XChangeGC(win->display,
- DefaultGC(win->display, 0),
- GCFunction | GCPlaneMask | GCForeground |
- GCLineWidth | GCLineStyle, &gc);
-
- /* Draw the lines... horizontal, */
- for (i = 1; i < SIZE; i++)
- XDrawLine(win->display, win->boardwin,
- DefaultGC(win->display, 0), 0,
- i * (SQUARE_WIDTH + BORDER_WIDTH) -
- BORDER_WIDTH / 2,
- SIZE * (SQUARE_WIDTH + BORDER_WIDTH),
- i * (SQUARE_WIDTH + BORDER_WIDTH) -
- BORDER_WIDTH / 2);
-
- /* and vertical... */
- for (i = 1; i < SIZE; i++)
- XDrawLine(win->display, win->boardwin,
- DefaultGC(win->display, 0),
- i * (SQUARE_WIDTH + BORDER_WIDTH) -
- BORDER_WIDTH / 2, 0,
- i * (SQUARE_WIDTH + BORDER_WIDTH) -
- BORDER_WIDTH / 2,
- SIZE * (SQUARE_WIDTH + BORDER_WIDTH));
- return;
-}
-
-void
-win_restart()
-{
- win1->flipped = false;
- win_redraw(win1, (XEvent *) NULL);
- if (!oneboard) {
- win2->flipped = true;
- win_redraw(win2, (XEvent *) NULL);
- }
- return;
-}
-
-static void
-icon_refresh(win)
- windata *win;
-{
- XCopyArea(win->display, win->iconpixmap, win->icon,
- DefaultGC(win->display, 0),
- 0, 0, icon_width, icon_height, 0, 0);
- return;
-}
-
diff --git a/gnu/games/chess/Xchess/xchess.c b/gnu/games/chess/Xchess/xchess.c
deleted file mode 100644
index 74d010f..0000000
--- a/gnu/games/chess/Xchess/xchess.c
+++ /dev/null
@@ -1,205 +0,0 @@
-
-/* This file contains code for X-CHESS.
- Copyright (C) 1986 Free Software Foundation, Inc.
-
-This file is part of X-CHESS.
-
-X-CHESS is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY. No author or distributor
-accepts responsibility to anyone for the consequences of using it
-or for whether it serves any particular purpose or works at all,
-unless he says so in writing. Refer to the X-CHESS General Public
-License for full details.
-
-Everyone is granted permission to copy, modify and redistribute
-X-CHESS, but only under the conditions described in the
-X-CHESS General Public License. A copy of this license is
-supposed to have been given to you along with X-CHESS so you
-can know your rights and responsibilities. It should be in a
-file named COPYING. Among other things, the copyright notice
-and this notice must be preserved on all copies. */
-
-
-/* RCS Info: $Revision: 1.1.1.1 $ on $Date: 1993/06/12 14:41:09 $
- * $Source: /home/ncvs/src/gnu/games/chess/Xchess/xchess.c,v $
- * Copyright (c) 1986 Wayne A. Christopher, U. C. Berkeley CAD Group
- * Permission is granted to do anything with this code except sell it
- * or remove this message.
- */
-
-#define USAGE "xchess [ -d ] [ -f recordfile ] [ -r savedfile ] [ -i ]\n\
-\t[ -t moves/timeunit ] [ -c ] [ -p program ] [ -b ] [ -bnw ] [ -s ]\n\
-\t[ -n ] [ -h host ] [ -v ] [ -R ] [ whitedisplay ] [ blackdisplay ]"
-
-#include <signal.h>
-#include "xchess.h"
-
-bool debug = false;
-bool oneboard = false;
-bool bnwflag = false;
-bool progflag = false;
-bool blackflag = false;
-bool quickflag = false;
-
-char *progname = DEF_PROGRAM;
-char *proghost = NULL;
-char *piecenames[] = { "pawn", "rook", "knight", "bishop", "queen", "king" } ;
-char *colornames[] = { "white", "black", "none" } ;
-char *movetypenames[] = { "move", "qcastle", "kcastle", "capture" } ;
-char *dispname1 = NULL, *dispname2 = NULL;
-
-char *black_piece_color = BLACK_PIECE_COLOR;
-char *white_piece_color = WHITE_PIECE_COLOR;
-char *black_square_color = BLACK_SQUARE_COLOR;
-char *white_square_color = WHITE_SQUARE_COLOR;
-char *border_color = BORDER_COLOR;
-char *text_color = TEXT_COLOR;
-char *text_back = TEXT_BACK;
-char *error_text = ERROR_TEXT;
-char *player_text = PLAYER_TEXT;
-char *cursor_color = CURSOR_COLOR;
-
-int num_flashes = NUM_FLASHES;
-int flash_size = FLASH_SIZE;
-char *program;
-char *recfile = NULL;
-
-#ifdef notdef
-/*
- * Serves no purpose.
- */
-die () {
-fprintf(stderr, "child proc changed status?!\n");
-}
-#endif
-
-void
-main(ac, av)
- char **av;
-{
- bool randflag = false;
- move *m;
- char *s;
-
- program = av[0];
-
-#ifdef notdef
- signal(SIGCHLD, die);
-#endif
-
- /* Process args. */
- av++; ac--;
- while (ac > 0 && **av == '-') {
- if (eq(*av, "-d")) {
- debug = true;
- } else if (eq(*av, "-f")) {
- av++; ac--;
- if (*av)
- record_file = *av;
- else
- goto usage;
- } else if (eq(*av, "-r")) {
- av++; ac--;
- if (*av)
- recfile = *av;
- else
- goto usage;
- } else if (eq(*av, "-i")) {
- record_english = false;
- } else if (eq(*av, "-R")) {
- randflag = true;
- } else if (eq(*av, "-v")) {
- win_flashmove = true;
- } else if (eq(*av, "-q")) {
- quickflag = true;
- } else if (eq(*av, "-t")) {
- av++; ac--;
- if (*av) {
- movesperunit = atoi(*av);
- if (s = index(*av, '/'))
- timeunit = atoi(s + 1) * 60;
- else
- timeunit = 60;
- } else
- goto usage;
- } else if (eq(*av, "-p")) {
- av++; ac--;
- if (*av)
- progname = *av;
- else
- goto usage;
- } else if (eq(*av, "-h")) {
- av++; ac--;
- if (*av)
- proghost = *av;
- else
- goto usage;
- } else if (eq(*av, "-b")) {
- blackflag = true;
- } else if (eq(*av, "-c")) {
- progflag = true;
- } else if (eq(*av, "-bnw")) {
- bnwflag = true;
- } else if (eq(*av, "-s")) {
- saveflag = true;
- } else if (eq(*av, "-n")) {
- noisyflag = true;
- } else
- goto usage;
- av++; ac--;
- }
- if (ac > 0)
- dispname1 = av[0];
- if (ac > 1)
- dispname2 = av[1];
- if (ac > 2)
- goto usage;
-
- if (!dispname2)
- oneboard = true;
-
- srandom(getpid());
-
- if (!oneboard && randflag && (random() % 2)) {
- s = dispname1;
- dispname1 = dispname2;
- dispname2 = s;
- }
-
- if (!dispname1)
- dispname1 = getenv("DISPLAY");
-
- /* Set up the board. */
- board_setup();
-
- /* Create the windows. */
- win_setup(dispname1, dispname2);
-
- board_drawall();
-
- /* Start the program if necessary. */
- if (progflag)
- if (!program_init(progname))
- exit(1);
-
- if (recfile)
- load_game(recfile);
-
- /* Go into a loop of prompting players alternately for moves, checking
- * them, and updating things.
- */
- for (;;) {
- win_process(false);
- clock_update();
- if (progflag && ((!blackflag && (nexttomove == BLACK)) ||
- (blackflag && (nexttomove == WHITE)))) {
- m = program_get();
- if (m)
- prog_move(m);
- }
- }
-
-usage: fprintf(stderr, "Usage: %s\n", USAGE);
- exit(1);
-}
-
diff --git a/gnu/games/chess/chess.6 b/gnu/games/chess/chess.6
deleted file mode 100644
index bbf0aa4..0000000
--- a/gnu/games/chess/chess.6
+++ /dev/null
@@ -1,161 +0,0 @@
-.TH Chess GNU
-.SH NAME
-Chess \- GNU Chess
-.SH SYNOPSIS
-.B Chess
-[
-.B arg1 arg2
-]
-.SH DESCRIPTION
-.I Chess
-plays a game of chess against the user or it plays against itself.
-.PP
-.I Chess
-has a simple alpha-numeric board display or it can be compiled for
-use with the CHESSTOOL program on a SUN workstation.
-The program gets its opening moves from the file gnuchess.book which
-should be located in the same directory as gnuchess.
-To invoke the prgram, type 'gnuchess' or type 'chesstool gnuchess'
-on a SUN workstation where 'CHESSTOOL' is installed.
-The 'gnuchess' command can be followed by up to 2 command line arguments.
-If one argument is given it determines the programs search time in
-seconds. If two arguments are given, they will be used to set tournament
-time controls with the first argument being the number of moves and the second
-being the total clock time in minutes. Thus, entering 'chess 60 5' will set
-the clocks for 5 minutes (300 seconds) for the first 60 moves.
-If no argument is given the program will prompt the user for level of
-play.
-For use with CHESSTOOL, see the documentation on that program.
-.PP
-Once
-.I Chess
-is invoked, the program will display the board and prompt the user
-for a move. To enter a move, use the notation 'e2e4' where the first
-letter-number pair indicates the origination square
-and the second letter-number pair indicates the destination square.
-An alternative is to use the notation 'nf3' where
-the first letter indicates the piece type (p,n,b,r,q,k).
-To castle, type the origin and destination squares
-of the king just as you would do for a regular move, or type
-"o-o" for kingside castling and "o-o-o" for queenside.
-.SH COMMANDS
-.PP
-In addition to legal moves, the following commands are available as responses.
-.PP
-.I beep
--- causes the program to beep after each move.
-.PP
-.I bd
--- updates the current board position on the display.
-.PP
-.I book
--- turns off use of the opening library.
-.PP
-.I both
--- causes the computer to play both sides of a chess game.
-.PP
-.I black
--- causes the computer to take the black pieces with the move
-and begin searching.
-.PP
-.I level
--- allows the user to set time controls such as
-60 moves in 5 minutes etc. In tournament mode, the program will
-vary the time it takes for each
-move depending on the situation. If easy mode is disabled (using
-the 'easy' command), the program
-will often respond with its move immediately, saving time on
-its clock for use later on.
-.PP
-.I depth
--- allows the user to change the
-search depth of the program. The maximum depth is 29 ply.
-Normally the depth is set to 29 and the computer terminates
-its search based on elapsed time rather than depth.
-Using the depth command allows setting depth to say
-4 ply and setting response time to a large number such as
-9999 seconds. The program will then search until all moves
-have been examined to a depth of 4 ply (with extensions up
-to 11 additional ply for sequences of checks and captures).
-.PP
-.I easy
--- toggles easy mode (thinking on opponents time)
-on and off. The default is easy mode ON. If easy mode is disabled,
-the user must enter a 'break' or '^C' to get the programs
-attention before entering each move.
-.PP
-.I edit
--- allows the user to set up a board position.
-In this mode, the '#' command will clear the board, the 'c'
-command will toggle piece color, and the '.' command will exit
-setup mode. Pieces are entered by typing a letter (p,n,b,r,q,k) for
-the piece followed by the coordinate. For example "pb3" would
-place a pawn on square b3.
-.PP
-.I force
--- allows the user to enter moves for both
-sides. To get the program to play after a sequence of moves
-has been entered use the 'white' or 'black' commands.
-.PP
-.I get
--- retrieves a game from disk. The program will
-prompt the user for a file name.
-.PP
-.I help
--- displays a short description of the commands.
-.PP
-.I hint
--- causes the program to supply the user with
-its predicted move.
-.PP
-.I list
--- writes the game moves and some statistics
-on search depth, nodes, and time to the file 'chess.lst'.
-.PP
-.I new
--- starts a new game.
-.PP
-.I post
--- causes the program to display the principle
-variation and the score during the search. A score of
-100 is equivalent to a 1 pawn advantage for the computer.
-.PP
-.I random
--- causes the program to randomize its move
-selection slightly.
-.PP
-.I reverse
--- causes the board display to be reversed. That
-is, the white pieces will now appear at the top of the board.
-.PP
-.I quit
--- exits the game.
-.PP
-.I save
--- saves a game to disk. The program will prompt
-the user for a file name.
-.PP
-.I switch
--- causes the program to switch places with
-the opponent and begin searching.
-.PP
-.I undo
--- undoes the last move whether it was the computer's
-or the human's. You may also type "remove". This is equivalent
-to two "undo's" (e.g. retract one move for each side).
-.PP
-.I white
--- causes the computer to take the white pieces
-with the move and begin searching.
-.SH BUGS
-.PP
-Pawn promotion to pieces other than a queen is not allowed.
-En-Passant does not work properly with CHESSTOOOL.
-The transposition table may not work properly in some
-positions so the default is to turn this off.
-.fi
-.SH SEE ALSO
-.nf
-chesstool(6)
-.fi
-
diff --git a/gnu/games/chess/gnuchess.c b/gnu/games/chess/gnuchess.c
deleted file mode 100644
index 20b32c4..0000000
--- a/gnu/games/chess/gnuchess.c
+++ /dev/null
@@ -1,2307 +0,0 @@
-/*
- C source for CHESS
-
- Revision: 4-25-88
-
- Copyright (C) 1986, 1987, 1988 Free Software Foundation, Inc.
- Copyright (c) 1988 John Stanback
-
- This file is part of CHESS.
-
- CHESS is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY. No author or distributor
- accepts responsibility to anyone for the consequences of using it
- or for whether it serves any particular purpose or works at all,
- unless he says so in writing. Refer to the CHESS General Public
- License for full details.
-
- Everyone is granted permission to copy, modify and redistribute
- CHESS, but only under the conditions described in the
- CHESS General Public License. A copy of this license is
- supposed to have been given to you along with CHESS so you
- can know your rights and responsibilities. It should be in a
- file named COPYING. Among other things, the copyright notice
- and this notice must be preserved on all copies.
-*/
-
-
-#include <stdio.h>
-#include <ctype.h>
-
-#ifdef MSDOS
-#include <stdlib.h>
-#include <time.h>
-#include <alloc.h>
-#define ttblsz 4096
-#else
-#include <sys/param.h>
-#include <sys/times.h>
-#define ttblsz 16384
-#define huge
-#endif MSDOS
-
-#include "move.h"
-
-#define neutral 2
-#define white 0
-#define black 1
-#define no_piece 0
-#define pawn 1
-#define knight 2
-#define bishop 3
-#define rook 4
-#define queen 5
-#define king 6
-#define valueP 100
-#define valueN 350
-#define valueB 355
-#define valueR 550
-#define valueQ 1100
-#define valueK 1200
-#define ctlP 0x4000
-#define ctlN 0x2800
-#define ctlB 0x1800
-#define ctlR 0x0400
-#define ctlQ 0x0200
-#define ctlK 0x0100
-#define ctlBQ 0x1200
-#define ctlRQ 0x0600
-#define ctlNN 0x2000
-#define pxx " PNBRQK"
-#define qxx " pnbrqk"
-#define rxx "12345678"
-#define cxx "abcdefgh"
-#define check 0x0001
-#define capture 0x0002
-#define draw 0x0004
-#define promote 0x0008
-#define cstlmask 0x0010
-#define epmask 0x0020
-#define exact 0x0040
-#define pwnthrt 0x0080
-#define truescore 0x0001
-#define lowerbound 0x0002
-#define upperbound 0x0004
-#define maxdepth 30
-#define true 1
-#define false 0
-#define absv(x) ((x) < 0 ? -(x) : (x))
-#if (NEWMOVE < 1)
-#define taxicab(a,b) (abs(column[a]-column[b]) + abs(row[a]-row[b]))
-#endif
-struct leaf
- {
- short f,t,score,reply;
- unsigned short flags;
- };
-struct GameRec
- {
- unsigned short gmove;
- short score,depth,time,piece,color;
- long nodes;
- };
-struct TimeControlRec
- {
- short moves[2];
- long clock[2];
- };
-struct BookEntry
- {
- struct BookEntry *next;
- unsigned short *mv;
- };
-struct hashval
- {
- unsigned long bd;
- unsigned short key;
- };
-struct hashentry
- {
- unsigned long hashbd;
- unsigned short mv,flags;
- short score,depth;
- };
-
-char mvstr1[5],mvstr2[5];
-struct leaf Tree[2000],*root;
-short TrPnt[maxdepth],board[64],color[64];
-short row[64],column[64],locn[8][8],Pindex[64],svalue[64];
-short PieceList[2][16],PieceCnt[2],atak[2][64],PawnCnt[2][8];
-short castld[2],kingmoved[2],mtl[2],pmtl[2],emtl[2],hung[2];
-short c1,c2,*atk1,*atk2,*PC1,*PC2,EnemyKing;
-short mate,post,opponent,computer,Sdepth,Awindow,Bwindow,dither;
-long ResponseTime,ExtraTime,Level,et,et0,time0,cputimer,ft;
-long NodeCnt,evrate,ETnodes,EvalNodes,HashCnt;
-short quit,reverse,bothsides,hashflag,InChk,player,force,easy,beep;
-short wking,bking,FROMsquare,TOsquare,timeout,Zscore,zwndw,xwndw,slk;
-short INCscore;
-short HasPawn[2],HasKnight[2],HasBishop[2],HasRook[2],HasQueen[2];
-short ChkFlag[maxdepth],CptrFlag[maxdepth],PawnThreat[maxdepth];
-short Pscore[maxdepth],Tscore[maxdepth],Threat[maxdepth];
-struct GameRec GameList[240];
-short GameCnt,Game50,epsquare,lpost,rcptr,contempt;
-short MaxSearchDepth;
-struct BookEntry *Book;
-struct TimeControlRec TimeControl;
-short TCflag,TCmoves,TCminutes,OperatorTime;
-short otherside[3]={1,0,2};
-short rank7[3]={6,1,0};
-short map[64]=
- {0,1,2,3,4,5,6,7,
- 0x10,0x11,0x12,0x13,0x14,0x15,0x16,0x17,
- 0x20,0x21,0x22,0x23,0x24,0x25,0x26,0x27,
- 0x30,0x31,0x32,0x33,0x34,0x35,0x36,0x37,
- 0x40,0x41,0x42,0x43,0x44,0x45,0x46,0x47,
- 0x50,0x51,0x52,0x53,0x54,0x55,0x56,0x57,
- 0x60,0x61,0x62,0x63,0x64,0x65,0x66,0x67,
- 0x70,0x71,0x72,0x73,0x74,0x75,0x76,0x77};
-short unmap[120]=
- {0,1,2,3,4,5,6,7,-1,-1,-1,-1,-1,-1,-1,-1,
- 8,9,10,11,12,13,14,15,-1,-1,-1,-1,-1,-1,-1,-1,
- 16,17,18,19,20,21,22,23,-1,-1,-1,-1,-1,-1,-1,-1,
- 24,25,26,27,28,29,30,31,-1,-1,-1,-1,-1,-1,-1,-1,
- 32,33,34,35,36,37,38,39,-1,-1,-1,-1,-1,-1,-1,-1,
- 40,41,42,43,44,45,46,47,-1,-1,-1,-1,-1,-1,-1,-1,
- 48,49,50,51,52,53,54,55,-1,-1,-1,-1,-1,-1,-1,-1,
- 56,57,58,59,60,61,62,63};
-short Dcode[120]=
- {0,1,1,1,1,1,1,1,0,0,0,0,0,0,0x0E,0x0F,
- 0x10,0x11,0x12,0,0,0,0,0,0,0,0,0,0,0,0x0F,0x1F,
- 0x10,0x21,0x11,0,0,0,0,0,0,0,0,0,0,0x0F,0,0,
- 0x10,0,0,0x11,0,0,0,0,0,0,0,0,0x0F,0,0,0,
- 0x10,0,0,0,0x11,0,0,0,0,0,0,0x0F,0,0,0,0,
- 0x10,0,0,0,0,0x11,0,0,0,0,0x0F,0,0,0,0,0,
- 0x10,0,0,0,0,0,0x11,0,0,0x0F,0,0,0,0,0,0,
- 0x10,0,0,0,0,0,0,0x11};
-short Stboard[64]=
- {rook,knight,bishop,queen,king,bishop,knight,rook,
- pawn,pawn,pawn,pawn,pawn,pawn,pawn,pawn,
- 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
- pawn,pawn,pawn,pawn,pawn,pawn,pawn,pawn,
- rook,knight,bishop,queen,king,bishop,knight,rook};
-short Stcolor[64]=
- {white,white,white,white,white,white,white,white,
- white,white,white,white,white,white,white,white,
- 2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,
- black,black,black,black,black,black,black,black,
- black,black,black,black,black,black,black,black};
-short sweep[7]= {false,false,false,true,true,true,false};
-short Dpwn[3]={4,6,0};
-short Dstart[7]={6,4,8,4,0,0,0};
-short Dstop[7]={7,5,15,7,3,7,7};
-short Dir[16]={1,0x10,-1,-0x10,0x0F,0x11,-0x0F,-0x11,
- 0x0E,-0x0E,0x12,-0x12,0x1F,-0x1F,0x21,-0x21};
-short Pdir[34]={0,0x38,0,0,0,0,0,0,0,0,0,0,0,0,0x02,0x35,
- 0x38,0x35,0x02,0,0,0,0,0,0,0,0,0,0,0,0,0x02,
- 0,0x02};
-short pbit[7]={0,0x01,0x02,0x04,0x08,0x10,0x20};
-unsigned short killr0[maxdepth],killr1[maxdepth],killr2[maxdepth];
-unsigned short killr3[maxdepth],PrVar[maxdepth];
-unsigned short PV,hint,Swag0,Swag1,Swag2,Swag3,Swag4;
-unsigned short hashkey;
-unsigned long hashbd;
-struct hashval hashcode[2][7][64];
-struct hashentry huge *ttable,*ptbl;
-unsigned char history[8192];
-
-short Mwpawn[64],Mbpawn[64],Mknight[2][64],Mbishop[2][64];
-short Mking[2][64],Kfield[2][64];
-short value[7]={0,valueP,valueN,valueB,valueR,valueQ,valueK};
-short control[7]={0,ctlP,ctlN,ctlB,ctlR,ctlQ,ctlK};
-short PassedPawn0[8]={0,60,80,120,200,360,600,800};
-short PassedPawn1[8]={0,30,40,60,100,180,300,800};
-short PassedPawn2[8]={0,15,25,35,50,90,140,800};
-short PassedPawn3[8]={0,5,10,15,20,30,140,800};
-short ISOLANI[8] = {-12,-16,-20,-24,-24,-20,-16,-12};
-short BACKWARD[8] = {-6,-10,-15,-21,-28,-28,-28,-28};
-short BMBLTY[14] = {-2,0,2,4,6,8,10,12,13,14,15,16,16,16};
-short RMBLTY[14] = {0,2,4,6,8,10,11,12,13,14,14,14,14,14};
-short Kthreat[16] = {0,-8,-20,-36,-52,-68,-80,-80,-80,-80,-80,-80,
- -80,-80,-80,-80};
-short KNIGHTPOST,KNIGHTSTRONG,BISHOPSTRONG,KATAK,KBNKsq;
-short PEDRNK2B,PWEAKH,PADVNCM,PADVNCI,PAWNSHIELD,PDOUBLED,PBLOK;
-short RHOPN,RHOPNX,KHOPN,KHOPNX,KSFTY;
-short ATAKD,HUNGP,HUNGX,KCASTLD,KMOVD,XRAY,PINVAL;
-short stage,stage2,Zwmtl,Zbmtl,Developed[2],PawnStorm;
-short PawnBonus,BishopBonus,RookBonus;
-short KingOpening[64]=
- { 0, 0, -4,-10,-10, -4, 0, 0,
- -4, -4, -8,-12,-12, -8, -4, -4,
- -12,-16,-20,-20,-20,-20,-16,-12,
- -16,-20,-24,-24,-24,-24,-20,-16,
- -16,-20,-24,-24,-24,-24,-20,-16,
- -12,-16,-20,-20,-20,-20,-16,-12,
- -4, -4, -8,-12,-12, -8, -4, -4,
- 0, 0, -4,-10,-10, -4, 0, 0};
-short KingEnding[64]=
- { 0, 6,12,18,18,12, 6, 0,
- 6,12,18,24,24,18,12, 6,
- 12,18,24,30,30,24,18,12,
- 18,24,30,36,36,30,24,18,
- 18,24,30,36,36,30,24,18,
- 12,18,24,30,30,24,18,12,
- 6,12,18,24,24,18,12, 6,
- 0, 6,12,18,18,12, 6, 0};
-short DyingKing[64]=
- { 0, 8,16,24,24,16, 8, 0,
- 8,32,40,48,48,40,32, 8,
- 16,40,56,64,64,56,40,16,
- 24,48,64,72,72,64,48,24,
- 24,48,64,72,72,64,48,24,
- 16,40,56,64,64,56,40,16,
- 8,32,40,48,48,40,32, 8,
- 0, 8,16,24,24,16, 8, 0};
-short KBNK[64]=
- {99,90,80,70,60,50,40,40,
- 90,80,60,50,40,30,20,40,
- 80,60,40,30,20,10,30,50,
- 70,50,30,10, 0,20,40,60,
- 60,40,20, 0,10,30,50,70,
- 50,30,10,20,30,40,60,80,
- 40,20,30,40,50,60,80,90,
- 40,40,50,60,70,80,90,99};
-short pknight[64]=
- { 0, 4, 8,10,10, 8, 4, 0,
- 4, 8,16,20,20,16, 8, 4,
- 8,16,24,28,28,24,16, 8,
- 10,20,28,32,32,28,20,10,
- 10,20,28,32,32,28,20,10,
- 8,16,24,28,28,24,16, 8,
- 4, 8,16,20,20,16, 8, 4,
- 0, 4, 8,10,10, 8, 4, 0};
-short pbishop[64]=
- {14,14,14,14,14,14,14,14,
- 14,22,18,18,18,18,22,14,
- 14,18,22,22,22,22,18,14,
- 14,18,22,22,22,22,18,14,
- 14,18,22,22,22,22,18,14,
- 14,18,22,22,22,22,18,14,
- 14,22,18,18,18,18,22,14,
- 14,14,14,14,14,14,14,14};
-short PawnAdvance[64]=
- { 0, 0, 0, 0, 0, 0, 0, 0,
- 4, 4, 4, 0, 0, 4, 4, 4,
- 6, 8, 2,10,10, 2, 8, 6,
- 6, 8,12,16,16,12, 8, 6,
- 8,12,16,24,24,16,12, 8,
- 12,16,24,32,32,24,16,12,
- 12,16,24,32,32,24,16,12,
- 0, 0, 0, 0, 0, 0, 0, 0};
-
-
-main(argc,argv)
-int argc; char *argv[];
-{
-#ifdef MSDOS
- ttable = (struct hashentry huge *)farmalloc(ttblsz *
- (unsigned long)sizeof(struct hashentry));
-#else
- ttable = (struct hashentry *)malloc(ttblsz *
- (unsigned long)sizeof(struct hashentry));
-#endif
- Level = 0; TCflag = false; OperatorTime = 0;
- if (argc == 2) Level = atoi(argv[1]);
- if (argc == 3)
- {
- TCmoves = atoi(argv[1]); TCminutes = atoi(argv[2]); TCflag = true;
- }
- Initialize();
- NewGame();
-#if (NEWMOVE > 0)
- Initialize_dist();
-#if (NEWMOVE > 1)
- Initialize_moves();
-#endif
-#endif
- while (!(quit))
- {
- if (bothsides && !mate) SelectMove(opponent,1); else InputCommand();
- if (!(quit || mate || force)) SelectMove(computer,1);
- }
- ExitChess();
-}
-
-
-
-/* ............ INTERFACE ROUTINES ........................... */
-
-int VerifyMove(s,iop,mv)
-char s[];
-short iop;
-unsigned short *mv;
-
-/*
- Compare the string 's' to the list of legal moves available for the
- opponent. If a match is found, make the move on the board.
-*/
-
-{
-static short pnt,tempb,tempc,tempsf,tempst,cnt;
-static struct leaf xnode;
-struct leaf *node;
-
- *mv = 0;
- if (iop == 2)
- {
- UnmakeMove(opponent,&xnode,&tempb,&tempc,&tempsf,&tempst);
- return(false);
- }
- cnt = 0;
- MoveList(opponent,2);
- pnt = TrPnt[2];
- while (pnt < TrPnt[3])
- {
- node = &Tree[pnt++];
- algbr(node->f,node->t,(short) node->flags & cstlmask);
- if (strcmp(s,mvstr1) == 0 || strcmp(s,mvstr2) == 0)
- {
- cnt++; xnode = *node;
- }
- }
- if (cnt == 1)
- {
- MakeMove(opponent,&xnode,&tempb,&tempc,&tempsf,&tempst);
- if (SqAtakd(PieceList[opponent][0],computer))
- {
- UnmakeMove(opponent,&xnode,&tempb,&tempc,&tempsf,&tempst);
- ShowMessage("Illegal Move!!");
- return(false);
- }
- else
- {
- if (iop == 1) return(true);
- if (xnode.flags & epmask) UpdateDisplay(0,0,1,0);
- else UpdateDisplay(xnode.f,xnode.t,0,xnode.flags & cstlmask);
- if (xnode.flags & cstlmask) Game50 = GameCnt;
- else if (board[xnode.t] == pawn || (xnode.flags & capture))
- Game50 = GameCnt;
- GameList[GameCnt].depth = GameList[GameCnt].score = 0;
- GameList[GameCnt].nodes = 0;
- ElapsedTime(1);
- GameList[GameCnt].time = (short)et;
- TimeControl.clock[opponent] -= et;
- --TimeControl.moves[opponent];
- *mv = (xnode.f << 8) + xnode.t;
- algbr(xnode.f,xnode.t,false);
- return(true);
- }
- }
- if (cnt > 1) ShowMessage("Ambiguous Move!");
- return(false);
-}
-
-
-NewGame()
-
-/*
- Reset the board and other variables to start a new game.
-*/
-
-{
-short l,r,c,p;
-
- mate = quit = reverse = bothsides = post = false;
- hashflag = force = PawnStorm = false;
- beep = rcptr = easy = true;
- lpost = NodeCnt = epsquare = et0 = 0;
- dither = 0;
- Awindow = 90;
- Bwindow = 90;
- xwndw = 90;
- MaxSearchDepth = 29;
- contempt = 0;
- GameCnt = -1; Game50 = 0;
- Zwmtl = Zbmtl = 0;
- Developed[white] = Developed[black] = false;
- castld[white] = castld[black] = false;
- kingmoved[white] = kingmoved[black] = 0;
- PawnThreat[0] = CptrFlag[0] = Threat[0] = false;
- Pscore[0] = 12000; Tscore[0] = 12000;
- opponent = white; computer = black;
- for (r = 0; r < 8; r++)
- for (c = 0; c < 8; c++)
- {
- l = 8*r+c; locn[r][c] = l;
- row[l] = r; column[l] = c;
- board[l] = Stboard[l]; color[l] = Stcolor[l];
- }
- for (c = white; c <= black; c++)
- for (p = pawn; p <= king; p++)
- for (l = 0; l < 64; l++)
- {
- hashcode[c][p][l].key = (unsigned short)rand();
- hashcode[c][p][l].bd = ((unsigned long)rand() << 16) +
- (unsigned long)rand();
- }
- ClrScreen();
- if (TCflag) SetTimeControl();
- else if (Level == 0) SelectLevel();
- UpdateDisplay(0,0,1,0);
- InitializeStats();
- time0 = time((long *)0);
- ElapsedTime(1);
- GetOpenings();
-}
-
-
-algbr(f,t,iscastle)
-short f,t,iscastle;
-{
- mvstr1[0] = cxx[column[f]]; mvstr1[1] = rxx[row[f]];
- mvstr1[2] = cxx[column[t]]; mvstr1[3] = rxx[row[t]];
- mvstr2[0] = qxx[board[f]];
- mvstr2[1] = mvstr1[2]; mvstr2[2] = mvstr1[3];
- mvstr1[4] = '\0'; mvstr2[3] = '\0';
- if (iscastle)
- if (t > f) strcpy(mvstr2,"o-o");
- else strcpy(mvstr2,"o-o-o");
-}
-
-
-/* ............ MOVE GENERATION & SEARCH ROUTINES .............. */
-
-SelectMove(side,iop)
-short side,iop;
-
-/*
- Select a move by calling function search() at progressively deeper
- ply until time is up or a mate or draw is reached. An alpha-beta
- window of -90 to +90 points is set around the score returned from the
- previous iteration. If Sdepth != 0 then the program has correctly
- predicted the opponents move and the search will start at a depth of
- Sdepth+1 rather than a depth of 1.
-*/
-
-{
-static short i,alpha,beta,score,tempb,tempc,tempsf,tempst,xside,rpt;
-
- timeout = false;
- xside = otherside[side];
- if (iop != 2) player = side;
- if (TCflag)
- {
- if (((TimeControl.moves[side] + 3) - OperatorTime) != 0)
- ResponseTime = (TimeControl.clock[side]) /
- (TimeControl.moves[side] + 3) -
- OperatorTime;
- else ResponseTime = 0;
- ResponseTime += (ResponseTime*TimeControl.moves[side])/(2*TCmoves+1);
- }
- else ResponseTime = Level;
- if (iop == 2) ResponseTime = 999;
- if (Sdepth > 0 && root->score > Zscore-zwndw) ResponseTime -= ft;
- else if (ResponseTime < 1) ResponseTime = 1;
- ExtraTime = 0;
- ExaminePosition();
- ScorePosition(side,&score);
- ShowSidetomove();
-
- if (Sdepth == 0)
- {
- ZeroTTable();
- SearchStartStuff(side);
- for (i = 0; i < 8192; i++) history[i] = 0;
- FROMsquare = TOsquare = -1;
- PV = 0;
- if (iop != 2) hint = 0;
- for (i = 0; i < maxdepth; i++)
- PrVar[i] = killr0[i] = killr1[i] = killr2[i] = killr3[i] = 0;
- alpha = score-90; beta = score+90;
- rpt = 0;
- TrPnt[1] = 0; root = &Tree[0];
- MoveList(side,1);
- for (i = TrPnt[1]; i < TrPnt[2]; i++) pick(i,TrPnt[2]-1);
- if (Book != NULL) OpeningBook();
- if (Book != NULL) timeout = true;
- NodeCnt = ETnodes = EvalNodes = HashCnt = 0;
- Zscore = 0; zwndw = 20;
- }
-
- while (!timeout && Sdepth < MaxSearchDepth)
- {
- Sdepth++;
- ShowDepth(' ');
- score = search(side,1,Sdepth,alpha,beta,PrVar,&rpt);
- for (i = 1; i <= Sdepth; i++) killr0[i] = PrVar[i];
- if (score < alpha)
- {
- ShowDepth('-');
- ExtraTime = 10*ResponseTime;
- ZeroTTable();
- score = search(side,1,Sdepth,-9000,beta,PrVar,&rpt);
- }
- if (score > beta && !(root->flags & exact))
- {
- ShowDepth('+');
- ExtraTime = 0;
- ZeroTTable();
- score = search(side,1,Sdepth,alpha,9000,PrVar,&rpt);
- }
- score = root->score;
- if (!timeout)
- for (i = TrPnt[1]+1; i < TrPnt[2]; i++) pick(i,TrPnt[2]-1);
- ShowResults(score,PrVar,'.');
- for (i = 1; i <= Sdepth; i++) killr0[i] = PrVar[i];
- if (score > Zscore-zwndw && score > Tree[1].score+250) ExtraTime = 0;
- else if (score > Zscore-3*zwndw) ExtraTime = ResponseTime;
- else ExtraTime = 3*ResponseTime;
- if (root->flags & exact) timeout = true;
- if (Tree[1].score < -9000) timeout = true;
- if (4*et > 2*ResponseTime + ExtraTime) timeout = true;
- if (!timeout)
- {
- Tscore[0] = score;
- if (Zscore == 0) Zscore = score;
- else Zscore = (Zscore+score)/2;
- }
- zwndw = 20+abs(Zscore/12);
- beta = score + Bwindow;
- if (Zscore < score) alpha = Zscore - Awindow - zwndw;
- else alpha = score - Awindow - zwndw;
- }
-
- score = root->score;
- if (rpt >= 2 || score < -12000) root->flags |= draw;
- if (iop == 2) return(0);
- if (Book == NULL) hint = PrVar[2];
- ElapsedTime(1);
-
- if (score > -9999 && rpt <= 2)
- {
- MakeMove(side,root,&tempb,&tempc,&tempsf,&tempst);
- algbr(root->f,root->t,(short) root->flags & cstlmask);
- }
- else mvstr1[0] = '\0';
- OutputMove();
- if (score == -9999 || score == 9998) mate = true;
- if (mate) hint = 0;
- if (root->flags & cstlmask) Game50 = GameCnt;
- else if (board[root->t] == pawn || (root->flags & capture))
- Game50 = GameCnt;
- GameList[GameCnt].score = score;
- GameList[GameCnt].nodes = NodeCnt;
- GameList[GameCnt].time = (short)et;
- GameList[GameCnt].depth = Sdepth;
- if (TCflag)
- {
- TimeControl.clock[side] -= (et + OperatorTime);
- if (--TimeControl.moves[side] == 0) SetTimeControl();
- }
- if ((root->flags & draw) && bothsides) quit = true;
- if (GameCnt > 238) quit = true;
- player = xside;
- Sdepth = 0;
- fflush(stdin);
- return(0);
-}
-
-
-OpeningBook()
-
-/*
- Go thru each of the opening lines of play and check for a match with
- the current game listing. If a match occurs, generate a random number.
- If this number is the largest generated so far then the next move in
- this line becomes the current "candidate". After all lines are
- checked, the candidate move is put at the top of the Tree[] array and
- will be played by the program. Note that the program does not handle
- book transpositions.
-*/
-
-{
-short j,pnt;
-unsigned short m,*mp;
-unsigned r,r0;
-struct BookEntry *p;
-
- srand((unsigned)time0);
- r0 = m = 0;
- p = Book;
- while (p != NULL)
- {
- mp = p->mv;
- for (j = 0; j <= GameCnt; j++)
- if (GameList[j].gmove != *(mp++)) break;
- if (j > GameCnt)
- if ((r=rand()) > r0)
- {
- r0 = r; m = *mp;
- hint = *(++mp);
- }
- p = p->next;
- }
-
- for (pnt = TrPnt[1]; pnt < TrPnt[2]; pnt++)
- if ((Tree[pnt].f<<8) + Tree[pnt].t == m) Tree[pnt].score = 0;
- pick(TrPnt[1],TrPnt[2]-1);
- if (Tree[TrPnt[1]].score < 0) Book = NULL;
-}
-
-
-#define UpdateSearchStatus \
-{\
- if (post) ShowCurrentMove(pnt,node->f,node->t);\
- if (pnt > TrPnt[1])\
- {\
- d = best-Zscore; e = best-node->score;\
- if (best < alpha) ExtraTime = 10*ResponseTime;\
- else if (d > -zwndw && e > 4*zwndw) ExtraTime = -ResponseTime/3;\
- else if (d > -zwndw) ExtraTime = 0;\
- else if (d > -3*zwndw) ExtraTime = ResponseTime;\
- else if (d > -9*zwndw) ExtraTime = 3*ResponseTime;\
- else ExtraTime = 5*ResponseTime;\
- }\
-}
-
-int search(side,ply,depth,alpha,beta,bstline,rpt)
-short side,ply,depth,alpha,beta,*rpt;
-unsigned short bstline[];
-
-/*
- Perform an alpha-beta search to determine the score for the current
- board position. If depth <= 0 only capturing moves, pawn promotions
- and responses to check are generated and searched, otherwise all
- moves are processed. The search depth is modified for check evasions,
- certain re-captures and threats. Extensions may continue for up to 11
- ply beyond the nominal search depth.
-*/
-
-#define prune (cf && score+node->score < alpha)
-#define ReCapture (rcptr && score > alpha && score < beta &&\
- ply > 2 && CptrFlag[ply-1] && CptrFlag[ply-2])
-#define MateThreat (ply < Sdepth+4 && ply > 4 &&\
- ChkFlag[ply-2] && ChkFlag[ply-4] &&\
- ChkFlag[ply-2] != ChkFlag[ply-4])
-
-{
-register short j,pnt;
-short best,tempb,tempc,tempsf,tempst;
-short xside,pbst,d,e,cf,score,rcnt;
-unsigned short mv,nxtline[maxdepth];
-struct leaf *node,tmp;
-
- NodeCnt++;
- xside = otherside[side];
- if (depth < 0) depth = 0;
-
- if (ply <= Sdepth+3) repetition(rpt); else *rpt = 0;
- if (*rpt >= 2) return(0);
-
- score = evaluate(side,xside,ply,alpha,beta);
- if (score > 9000)
- {
- bstline[ply] = 0;
- return(score);
- }
-
- if (depth > 0)
- {
- if (InChk || PawnThreat[ply-1] || ReCapture) ++depth;
- }
- else
- {
- if (score >= alpha &&
- (InChk || PawnThreat[ply-1] || Threat[ply-1])) ++depth;
- else if (score <= beta && MateThreat) ++depth;
- }
-
- if (depth > 0 && hashflag && ply > 1)
- {
- ProbeTTable(side,depth,&alpha,&beta,&score);
- bstline[ply] = PV;
- bstline[ply+1] = 0;
- if (beta == -20000) return(score);
- if (alpha > beta) return(alpha);
- }
-
- if (Sdepth == 1) d = 7; else d = 11;
- if (ply > Sdepth+d || (depth < 1 && score > beta)) return(score);
-
- if (ply > 1)
- if (depth > 0) MoveList(side,ply);
- else CaptureList(side,xside,ply);
-
- if (TrPnt[ply] == TrPnt[ply+1]) return(score);
-
- cf = (depth < 1 && ply > Sdepth+1 && !ChkFlag[ply-2] && !slk);
-
- if (depth > 0) best = -12000; else best = score;
- if (best > alpha) alpha = best;
-
- for (pnt = pbst = TrPnt[ply];
- pnt < TrPnt[ply+1] && best <= beta;
- pnt++)
- {
- if (ply > 1) pick(pnt,TrPnt[ply+1]-1);
- node = &Tree[pnt];
- mv = (node->f << 8) + node->t;
- nxtline[ply+1] = 0;
-
- if (prune) break;
- if (ply == 1) UpdateSearchStatus;
-
- if (!(node->flags & exact))
- {
- MakeMove(side,node,&tempb,&tempc,&tempsf,&tempst);
- CptrFlag[ply] = (node->flags & capture);
- PawnThreat[ply] = (node->flags & pwnthrt);
- Tscore[ply] = node->score;
- PV = node->reply;
- node->score = -search(xside,ply+1,depth-1,-beta,-alpha,
- nxtline,&rcnt);
- if (abs(node->score) > 9000) node->flags |= exact;
- else if (rcnt == 1) node->score /= 2;
- if (rcnt >= 2 || GameCnt-Game50 > 99 ||
- (node->score == 9999-ply && !ChkFlag[ply]))
- {
- node->flags |= draw; node->flags |= exact;
- if (side == computer) node->score = contempt;
- else node->score = -contempt;
- }
- node->reply = nxtline[ply+1];
- UnmakeMove(side,node,&tempb,&tempc,&tempsf,&tempst);
- }
- if (node->score > best && !timeout)
- {
- if (depth > 0)
- if (node->score > alpha && !(node->flags & exact))
- node->score += depth;
- best = node->score; pbst = pnt;
- if (best > alpha) alpha = best;
- for (j = ply+1; nxtline[j] > 0; j++) bstline[j] = nxtline[j];
- bstline[j] = 0;
- bstline[ply] = mv;
- if (ply == 1)
- {
- if (best == alpha)
- {
- tmp = Tree[pnt];
- for (j = pnt-1; j >= 0; j--) Tree[j+1] = Tree[j];
- Tree[0] = tmp;
- pbst = 0;
- }
- if (Sdepth > 2)
- if (best > beta) ShowResults(best,bstline,'+');
- else if (best < alpha) ShowResults(best,bstline,'-');
- else ShowResults(best,bstline,'&');
- }
- }
- if (NodeCnt > ETnodes) ElapsedTime(0);
- if (timeout) return(-Tscore[ply-1]);
- }
-
- node = &Tree[pbst];
- mv = (node->f<<8) + node->t;
- if (hashflag && ply <= Sdepth && *rpt == 0 && best == alpha)
- PutInTTable(side,best,depth,alpha,beta,mv);
- if (depth > 0)
- {
- j = (node->f<<6) + node->t; if (side == black) j |= 0x1000;
- if (history[j] < 150) history[j] += 2*depth;
- if (node->t != (GameList[GameCnt].gmove & 0xFF))
- if (best <= beta) killr3[ply] = mv;
- else if (mv != killr1[ply])
- {
- killr2[ply] = killr1[ply];
- killr1[ply] = mv;
- }
- if (best > 9000) killr0[ply] = mv; else killr0[ply] = 0;
- }
- return(best);
-}
-
-
-evaluate(side,xside,ply,alpha,beta)
-short side,xside,ply,alpha,beta;
-
-/*
- Compute an estimate of the score by adding the positional score from
- the previous ply to the material difference. If this score falls
- inside a window which is 180 points wider than the alpha-beta window
- (or within a 50 point window during quiescence search) call
- ScorePosition() to determine a score, otherwise return the estimated
- score. If one side has only a king and the other either has no pawns
- or no pieces then the function ScoreLoneKing() is called.
-*/
-
-{
-short s,evflag;
-
- hung[white] = hung[black] = 0;
- slk = ((mtl[white] == valueK && (pmtl[black] == 0 || emtl[black] == 0)) ||
- (mtl[black] == valueK && (pmtl[white] == 0 || emtl[white] == 0)));
- s = -Pscore[ply-1] + mtl[side] - mtl[xside];
- s -= INCscore;
-
- if (slk) evflag = false;
- else evflag =
- (ply == 1 || ply < Sdepth ||
- ((ply == Sdepth+1 || ply == Sdepth+2) &&
- (s > alpha-xwndw && s < beta+xwndw)) ||
- (ply > Sdepth+2 && s >= alpha-25 && s <= beta+25));
-
- if (evflag)
- {
- EvalNodes++;
- ataks(side,atak[side]);
- if (atak[side][PieceList[xside][0]] > 0) return(10001-ply);
- ataks(xside,atak[xside]);
- InChk = (atak[xside][PieceList[side][0]] > 0);
- ScorePosition(side,&s);
- }
- else
- {
- if (SqAtakd(PieceList[xside][0],side)) return(10001-ply);
- InChk = SqAtakd(PieceList[side][0],xside);
- if (slk) ScoreLoneKing(side,&s);
- }
-
- Pscore[ply] = s - mtl[side] + mtl[xside];
- if (InChk) ChkFlag[ply-1] = Pindex[TOsquare];
- else ChkFlag[ply-1] = 0;
- Threat[ply-1] = (hung[side] > 1 && ply == Sdepth+1);
- return(s);
-}
-
-
-ProbeTTable(side,depth,alpha,beta,score)
-short side,depth,*alpha,*beta,*score;
-
-/*
- Look for the current board position in the transposition table.
-*/
-
-{
-short hindx;
- if (side == white) hashkey |= 1; else hashkey &= 0xFFFE;
- hindx = (hashkey & (ttblsz-1));
- ptbl = (ttable + hindx);
- if (ptbl->depth >= depth && ptbl->hashbd == hashbd)
- {
- HashCnt++;
- PV = ptbl->mv;
- if (ptbl->flags & truescore)
- {
- *score = ptbl->score;
- *beta = -20000;
- return(true);
- }
-/*
- else if (ptbl->flags & upperbound)
- {
- if (ptbl->score < *beta) *beta = ptbl->score+1;
- }
-*/
- else if (ptbl->flags & lowerbound)
- {
- if (ptbl->score > *alpha) *alpha = ptbl->score-1;
- }
- }
- return(false);
-}
-
-
-PutInTTable(side,score,depth,alpha,beta,mv)
-short side,score,depth,alpha,beta;
-unsigned short mv;
-
-/*
- Store the current board position in the transposition table.
-*/
-
-{
-short hindx;
- if (side == white) hashkey |= 1; else hashkey &= 0xFFFE;
- hindx = (hashkey & (ttblsz-1));
- ptbl = (ttable + hindx);
- ptbl->hashbd = hashbd;
- ptbl->depth = depth;
- ptbl->score = score;
- ptbl->mv = mv;
- ptbl->flags = 0;
- if (score < alpha) ptbl->flags |= upperbound;
- else if (score > beta) ptbl->flags |= lowerbound;
- else ptbl->flags |= truescore;
-}
-
-
-ZeroTTable()
-{
-int i;
- if (hashflag)
- for (i = 0; i < ttblsz; i++)
- {
- ptbl = (ttable + i);
- ptbl->depth = 0;
- }
-}
-
-
-MoveList(side,ply)
-short side,ply;
-
-/*
- Fill the array Tree[] with all available moves for side to play. Array
- TrPnt[ply] contains the index into Tree[] of the first move at a ply.
-*/
-
-{
-register short i;
-short xside,f;
-
- xside = otherside[side];
- if (PV == 0) Swag0 = killr0[ply]; else Swag0 = PV;
- Swag1 = killr1[ply]; Swag2 = killr2[ply];
- Swag3 = killr3[ply]; Swag4 = 0;
- if (ply > 2) Swag4 = killr1[ply-2];
- TrPnt[ply+1] = TrPnt[ply];
- Dstart[pawn] = Dpwn[side]; Dstop[pawn] = Dstart[pawn] + 1;
- for (i = PieceCnt[side]; i >= 0; i--)
- GenMoves(ply,PieceList[side][i],side,xside);
- if (kingmoved[side] == 0 && !castld[side])
- {
- f = PieceList[side][0];
- if (castle(side,f,f+2,0))
- {
- LinkMove(ply,f,f+2,xside);
- Tree[TrPnt[ply+1]-1].flags |= cstlmask;
- }
- if (castle(side,f,f-2,0))
- {
- LinkMove(ply,f,f-2,xside);
- Tree[TrPnt[ply+1]-1].flags |= cstlmask;
- }
- }
-}
-
-#if (NEWMOVE < 11)
-GenMoves(ply,sq,side,xside)
-short ply,sq,side,xside;
-
-/*
- Generate moves for a piece. The from square is mapped onto a special
- board and offsets (taken from array Dir[]) are added to the mapped
- location. The newly generated square is tested to see if it falls off
- the board by ANDing the square with 88 HEX. Legal moves are linked
- into the tree.
-*/
-
-{
-register short m,u,d;
-short i,m0,piece;
-
- piece = board[sq]; m0 = map[sq];
- if (sweep[piece])
- for (i = Dstart[piece]; i <= Dstop[piece]; i++)
- {
- d = Dir[i]; m = m0+d;
- while (!(m & 0x88))
- {
- u = unmap[m];
- if (color[u] == neutral)
- {
- LinkMove(ply,sq,u,xside);
- m += d;
- }
- else if (color[u] == xside)
- {
- LinkMove(ply,sq,u,xside);
- break;
- }
- else break;
- }
- }
- else if (piece == pawn)
- {
- if (side == white && color[sq+8] == neutral)
- {
- LinkMove(ply,sq,sq+8,xside);
- if (row[sq] == 1)
- if (color[sq+16] == neutral)
- LinkMove(ply,sq,sq+16,xside);
- }
- else if (side == black && color[sq-8] == neutral)
- {
- LinkMove(ply,sq,sq-8,xside);
- if (row[sq] == 6)
- if (color[sq-16] == neutral)
- LinkMove(ply,sq,sq-16,xside);
- }
- for (i = Dstart[piece]; i <= Dstop[piece]; i++)
- if (!((m = m0+Dir[i]) & 0x88))
- {
- u = unmap[m];
- if (color[u] == xside || u == epsquare)
- LinkMove(ply,sq,u,xside);
- }
- }
- else
- {
- for (i = Dstart[piece]; i <= Dstop[piece]; i++)
- if (!((m = m0+Dir[i]) & 0x88))
- {
- u = unmap[m];
- if (color[u] != side) LinkMove(ply,sq,u,xside);
- }
- }
-}
-#endif
-
-LinkMove(ply,f,t,xside)
-short ply,f,t,xside;
-
-/*
- Add a move to the tree. Assign a bonus to order the moves
- as follows:
- 1. Principle variation
- 2. Capture of last moved piece
- 3. Other captures (major pieces first)
- 4. Killer moves
- 5. "history" killers
-*/
-
-{
-register short s,z;
-unsigned short mv;
-struct leaf *node;
-
- node = &Tree[TrPnt[ply+1]];
- ++TrPnt[ply+1];
- node->flags = node->reply = 0;
- node->f = f; node->t = t;
- mv = (f<<8) + t;
- s = 0;
- if (mv == Swag0) s = 2000;
- else if (mv == Swag1) s = 60;
- else if (mv == Swag2) s = 50;
- else if (mv == Swag3) s = 40;
- else if (mv == Swag4) s = 30;
- if (color[t] != neutral)
- {
- node->flags |= capture;
- if (t == TOsquare) s += 500;
- s += value[board[t]] - board[f];
- }
- if (board[f] == pawn)
- if (row[t] == 0 || row[t] == 7)
- {
- node->flags |= promote;
- s += 800;
- }
- else if (row[t] == 1 || row[t] == 6)
- {
- node->flags |= pwnthrt;
- s += 600;
- }
- else if (t == epsquare) node->flags |= epmask;
- z = (f<<6) + t; if (xside == white) z |= 0x1000;
- s += history[z];
- node->score = s - 20000;
-}
-
-#if (NEWMOVE < 10)
-CaptureList(side,xside,ply)
-short side,xside,ply;
-
-/*
- Generate captures and Pawn promotions only.
-*/
-
-#define LinkCapture\
-{\
- node->f = sq; node->t = u;\
- node->reply = 0;\
- node->flags = capture;\
- node->score = value[board[u]] + svalue[board[u]] - piece;\
- if (piece == pawn && (u < 8 || u > 55))\
- {\
- node->flags |= promote;\
- node->score = valueQ;\
- }\
- ++node;\
- ++TrPnt[ply+1];\
-}
-
-{
-register short m,u;
-short d,sq,i,j,j1,j2,m0,r7,d0,piece,*PL;
-struct leaf *node;
-
- TrPnt[ply+1] = TrPnt[ply];
- node = &Tree[TrPnt[ply]];
- Dstart[pawn] = Dpwn[side]; Dstop[pawn] = Dstart[pawn] + 1;
- if (side == white)
- {
- r7 = 6; d0 = 8;
- }
- else
- {
- r7 = 1; d0 = -8;
- }
- PL = PieceList[side];
- for (i = 0; i <= PieceCnt[side]; i++)
- {
- sq = PL[i];
- m0 = map[sq]; piece = board[sq];
- j1 = Dstart[piece]; j2 = Dstop[piece];
- if (sweep[piece])
- for (j = j1; j <= j2; j++)
- {
- d = Dir[j]; m = m0+d;
- while (!(m & 0x88))
- {
- u = unmap[m];
- if (color[u] == neutral) m += d;
- else
- {
- if (color[u] == xside) LinkCapture;
- break;
- }
- }
- }
- else
- {
- for (j = j1; j <= j2; j++)
- if (!((m = m0+Dir[j]) & 0x88))
- {
- u = unmap[m];
- if (color[u] == xside) LinkCapture;
- }
- if (piece == pawn && row[sq] == r7)
- {
- u = sq+d0;
- if (color[u] == neutral) LinkCapture;
- }
- }
- }
-}
-#endif
-
-int castle(side,kf,kt,iop)
-short side,kf,kt,iop;
-
-/*
- Make or Unmake a castling move.
-*/
-
-{
-short rf,rt,d,t0,xside;
-
- xside = otherside[side];
- if (kt > kf)
- {
- rf = kf+3; rt = kt-1; d = 1;
- }
- else
- {
- rf = kf-4; rt = kt+1; d = -1;
- }
- if (iop == 0)
- {
- if (board[kf] != king || board[rf] != rook || color[rf] != side)
- return(false);
- if (color[kt] != neutral || color[rt] != neutral) return(false);
- if (d == -1 && color[kt+d] != neutral) return(false);
- if (SqAtakd(kf,xside)) return(false);
- if (SqAtakd(kt,xside)) return(false);
- if (SqAtakd(kf+d,xside)) return(false);
- }
- else
- {
- if (iop == 1) castld[side] = true; else castld[side] = false;
- if (iop == 2)
- {
- t0 = kt; kt = kf; kf = t0;
- t0 = rt; rt = rf; rf = t0;
- }
- board[kt] = king; color[kt] = side; Pindex[kt] = 0;
- board[kf] = no_piece; color[kf] = neutral;
- board[rt] = rook; color[rt] = side; Pindex[rt] = Pindex[rf];
- board[rf] = no_piece; color[rf] = neutral;
- PieceList[side][Pindex[kt]] = kt;
- PieceList[side][Pindex[rt]] = rt;
- if (hashflag)
- {
- UpdateHashbd(side,king,kf,kt);
- UpdateHashbd(side,rook,rf,rt);
- }
- }
- return(true);
-}
-
-
-EnPassant(xside,f,t,iop)
-short xside,f,t,iop;
-
-/*
- Make or unmake an en passant move.
-*/
-
-{
-short l;
- if (t > f) l = t-8; else l = t+8;
- if (iop == 1)
- {
- board[l] = no_piece; color[l] = neutral;
- }
- else
- {
- board[l] = pawn; color[l] = xside;
- }
- InitializeStats();
-}
-
-
-MakeMove(side,node,tempb,tempc,tempsf,tempst)
-short side,*tempc,*tempb,*tempsf,*tempst;
-struct leaf *node;
-
-/*
- Update Arrays board[], color[], and Pindex[] to reflect the new board
- position obtained after making the move pointed to by node. Also
- update miscellaneous stuff that changes when a move is made.
-*/
-
-{
-register short f,t;
-short xside,ct,cf;
-
- xside = otherside[side];
- f = node->f; t = node->t; epsquare = -1;
- FROMsquare = f; TOsquare = t;
- INCscore = 0;
- GameList[++GameCnt].gmove = (f<<8) + t;
- if (node->flags & cstlmask)
- {
- GameList[GameCnt].piece = no_piece;
- GameList[GameCnt].color = side;
- castle(side,f,t,1);
- }
- else
- {
- *tempc = color[t]; *tempb = board[t];
- *tempsf = svalue[f]; *tempst = svalue[t];
- GameList[GameCnt].piece = *tempb;
- GameList[GameCnt].color = *tempc;
- if (*tempc != neutral)
- {
- UpdatePieceList(*tempc,t,1);
- if (*tempb == pawn) --PawnCnt[*tempc][column[t]];
- if (board[f] == pawn)
- {
- --PawnCnt[side][column[f]];
- ++PawnCnt[side][column[t]];
- cf = column[f]; ct = column[t];
- if (PawnCnt[side][ct] > 1+PawnCnt[side][cf])
- INCscore -= 15;
- else if (PawnCnt[side][ct] < 1+PawnCnt[side][cf])
- INCscore += 15;
- else if (ct == 0 || ct == 7 || PawnCnt[side][ct+ct-cf] == 0)
- INCscore -= 15;
- }
- mtl[xside] -= value[*tempb];
- if (*tempb == pawn) pmtl[xside] -= valueP;
- if (hashflag) UpdateHashbd(xside,*tempb,-1,t);
- INCscore += *tempst;
- }
- color[t] = color[f]; board[t] = board[f]; svalue[t] = svalue[f];
- Pindex[t] = Pindex[f]; PieceList[side][Pindex[t]] = t;
- color[f] = neutral; board[f] = no_piece;
- if (board[t] == pawn)
- if (t-f == 16) epsquare = f+8;
- else if (f-t == 16) epsquare = f-8;
- if (node->flags & promote)
- {
- board[t] = queen;
- --PawnCnt[side][column[t]];
- mtl[side] += valueQ - valueP;
- pmtl[side] -= valueP;
- HasQueen[side] = true;
- if (hashflag)
- {
- UpdateHashbd(side,pawn,f,-1);
- UpdateHashbd(side,queen,f,-1);
- }
- INCscore -= *tempsf;
- }
- if (board[t] == king) ++kingmoved[side];
- if (node->flags & epmask) EnPassant(xside,f,t,1);
- else if (hashflag) UpdateHashbd(side,board[t],f,t);
- }
-}
-
-
-UnmakeMove(side,node,tempb,tempc,tempsf,tempst)
-short side,*tempc,*tempb,*tempsf,*tempst;
-struct leaf *node;
-
-/*
- Take back a move.
-*/
-
-{
-register short f,t;
-short xside;
-
- xside = otherside[side];
- f = node->f; t = node->t; epsquare = -1;
- GameCnt--;
- if (node->flags & cstlmask) castle(side,f,t,2);
- else
- {
- color[f] = color[t]; board[f] = board[t]; svalue[f] = *tempsf;
- Pindex[f] = Pindex[t]; PieceList[side][Pindex[f]] = f;
- color[t] = *tempc; board[t] = *tempb; svalue[t] = *tempst;
- if (node->flags & promote)
- {
- board[f] = pawn;
- ++PawnCnt[side][column[t]];
- mtl[side] += valueP - valueQ;
- pmtl[side] += valueP;
- if (hashflag)
- {
- UpdateHashbd(side,queen,-1,t);
- UpdateHashbd(side,pawn,-1,t);
- }
- }
- if (*tempc != neutral)
- {
- UpdatePieceList(*tempc,t,2);
- if (*tempb == pawn) ++PawnCnt[*tempc][column[t]];
- if (board[f] == pawn)
- {
- --PawnCnt[side][column[t]];
- ++PawnCnt[side][column[f]];
- }
- mtl[xside] += value[*tempb];
- if (*tempb == pawn) pmtl[xside] += valueP;
- if (hashflag) UpdateHashbd(xside,*tempb,-1,t);
- }
- if (board[f] == king) --kingmoved[side];
- if (node->flags & epmask) EnPassant(xside,f,t,2);
- else if (hashflag) UpdateHashbd(side,board[f],f,t);
- }
-}
-
-
-UpdateHashbd(side,piece,f,t)
-short side,piece,f,t;
-
-/*
- hashbd contains a 32 bit "signature" of the board position. hashkey
- contains a 16 bit code used to address the hash table. When a move is
- made, XOR'ing the hashcode of moved piece on the from and to squares
- with the hashbd and hashkey values keeps things current.
-*/
-
-{
- if (f >= 0)
- {
- hashbd ^= hashcode[side][piece][f].bd;
- hashkey ^= hashcode[side][piece][f].key;
- }
- if (t >= 0)
- {
- hashbd ^= hashcode[side][piece][t].bd;
- hashkey ^= hashcode[side][piece][t].key;
- }
-}
-
-
-UpdatePieceList(side,sq,iop)
-short side,sq,iop;
-
-/*
- Update the PieceList and Pindex arrays when a piece is captured or
- when a capture is unmade.
-*/
-
-{
-register short i;
- if (iop == 1)
- {
- PieceCnt[side]--;
- for (i = Pindex[sq]; i <= PieceCnt[side]; i++)
- {
- PieceList[side][i] = PieceList[side][i+1];
- Pindex[PieceList[side][i]] = i;
- }
- }
- else
- {
- PieceCnt[side]++;
- PieceList[side][PieceCnt[side]] = sq;
- Pindex[sq] = PieceCnt[side];
- }
-}
-
-
-InitializeStats()
-
-/*
- Scan thru the board seeing what's on each square. If a piece is found,
- update the variables PieceCnt, PawnCnt, Pindex and PieceList. Also
- determine the material for each side and set the hashkey and hashbd
- variables to represent the current board position. Array
- PieceList[side][indx] contains the location of all the pieces of
- either side. Array Pindex[sq] contains the indx into PieceList for a
- given square.
-*/
-
-{
-register short i,sq;
- epsquare = -1;
- for (i = 0; i < 8; i++)
- PawnCnt[white][i] = PawnCnt[black][i] = 0;
- mtl[white] = mtl[black] = pmtl[white] = pmtl[black] = 0;
- PieceCnt[white] = PieceCnt[black] = 0;
- hashbd = hashkey = 0;
- for (sq = 0; sq < 64; sq++)
- if (color[sq] != neutral)
- {
- mtl[color[sq]] += value[board[sq]];
- if (board[sq] == pawn)
- {
- pmtl[color[sq]] += valueP;
- ++PawnCnt[color[sq]][column[sq]];
- }
- if (board[sq] == king) Pindex[sq] = 0;
- else Pindex[sq] = ++PieceCnt[color[sq]];
- PieceList[color[sq]][Pindex[sq]] = sq;
- hashbd ^= hashcode[color[sq]][board[sq]][sq].bd;
- hashkey ^= hashcode[color[sq]][board[sq]][sq].key;
- }
-}
-
-
-pick(p1,p2)
-short p1,p2;
-
-/*
- Find the best move in the tree between indexes p1 and p2. Swap the
- best move into the p1 element.
-*/
-
-{
-register short p,s;
-short p0,s0;
-struct leaf temp;
-
- s0 = Tree[p1].score; p0 = p1;
- for (p = p1+1; p <= p2; p++)
- if ((s = Tree[p].score) > s0)
- {
- s0 = s; p0 = p;
- }
- if (p0 != p1)
- {
- temp = Tree[p1]; Tree[p1] = Tree[p0]; Tree[p0] = temp;
- }
-}
-
-
-repetition(cnt)
-short *cnt;
-
-/*
- Check for draw by threefold repetition.
-*/
-
-{
-register short i,c;
-short f,t,b[64];
-unsigned short m;
- *cnt = c = 0;
- if (GameCnt > Game50+3)
- {
-/*
- memset((char *)b,0,64*sizeof(short));
-*/
- for (i = 0; i < 64; b[i++] = 0);
- for (i = GameCnt; i > Game50; i--)
- {
- m = GameList[i].gmove; f = m>>8; t = m & 0xFF;
- if (++b[f] == 0) c--; else c++;
- if (--b[t] == 0) c--; else c++;
- if (c == 0) (*cnt)++;
- }
- }
-}
-
-#if (NEWMOVE < 3)
-int SqAtakd(sq,side)
-short sq,side;
-
-/*
- See if any piece with color 'side' ataks sq. First check for pawns
- or king, then try other pieces. Array Dcode is used to check for
- knight attacks or R,B,Q co-linearity.
-*/
-
-{
-register short m,d;
-short i,m0,m1,loc,piece,*PL;
-
- m1 = map[sq];
- if (side == white) m = m1-0x0F; else m = m1+0x0F;
- if (!(m & 0x88))
- if (board[unmap[m]] == pawn && color[unmap[m]] == side) return(true);
- if (side == white) m = m1-0x11; else m = m1+0x11;
- if (!(m & 0x88))
- if (board[unmap[m]] == pawn && color[unmap[m]] == side) return(true);
- if (distance(sq,PieceList[side][0]) == 1) return(true);
-
- PL = PieceList[side];
- for (i = 1; i <= PieceCnt[side]; i++)
- {
- loc = PL[i]; piece = board[loc];
- if (piece == pawn) continue;
- m0 = map[loc]; d = Dcode[abs(m1-m0)];
- if (d == 0 || (Pdir[d] & pbit[piece]) == 0) continue;
- if (piece == knight) return(true);
- else
- {
- if (m1 < m0) d = -d;
- for (m = m0+d; m != m1; m += d)
- if (color[unmap[m]] != neutral) break;
- if (m == m1) return(true);
- }
- }
- return(false);
-}
-#endif
-
-#if (NEWMOVE < 2)
-ataks(side,a)
-short side,*a;
-
-/*
- Fill array atak[][] with info about ataks to a square. Bits 8-15
- are set if the piece (king..pawn) ataks the square. Bits 0-7
- contain a count of total ataks to the square.
-*/
-
-{
-register short u,m;
-short d,c,j,j1,j2,piece,i,m0,sq,*PL;
-
-/*
- memset((char *)a,0,64*sizeof(short));
-*/
- for (u = 0; u < 64; a[u++] = 0);
- Dstart[pawn] = Dpwn[side]; Dstop[pawn] = Dstart[pawn] + 1;
- PL = PieceList[side];
- for (i = 0; i <= PieceCnt[side]; i++)
- {
- sq = PL[i];
- m0 = map[sq];
- piece = board[sq];
- c = control[piece]; j1 = Dstart[piece]; j2 = Dstop[piece];
- if (sweep[piece])
- for (j = j1; j <= j2; j++)
- {
- d = Dir[j]; m = m0+d;
- while (!(m & 0x88))
- {
- u = unmap[m];
- a[u] = ++a[u] | c;
- if (color[u] == neutral) m += d;
- else break;
- }
- }
- else
- for (j = j1; j <= j2; j++)
- if (!((m = m0+Dir[j]) & 0x88))
- {
- u = unmap[m];
- a[u] = ++a[u] | c;
- }
- }
-}
-#endif
-
-/* ............ POSITIONAL EVALUATION ROUTINES ............ */
-
-ScorePosition(side,score)
-short side,*score;
-
-/*
- Perform normal static evaluation of board position. A score is
- generated for each piece and these are summed to get a score for each
- side.
-*/
-
-{
-register short sq,s;
-short i,xside,pscore[3];
-
- wking = PieceList[white][0]; bking = PieceList[black][0];
- UpdateWeights();
- xside = otherside[side];
- pscore[white] = pscore[black] = 0;
-
- for (c1 = white; c1 <= black; c1++)
- {
- c2 = otherside[c1];
- if (c1 == white) EnemyKing = bking; else EnemyKing = wking;
- atk1 = atak[c1]; atk2 = atak[c2];
- PC1 = PawnCnt[c1]; PC2 = PawnCnt[c2];
- for (i = 0; i <= PieceCnt[c1]; i++)
- {
- sq = PieceList[c1][i];
- s = SqValue(sq,side);
- pscore[c1] += s;
- svalue[sq] = s;
- }
- }
- if (hung[side] > 1) pscore[side] += HUNGX;
- if (hung[xside] > 1) pscore[xside] += HUNGX;
-
- *score = mtl[side] - mtl[xside] + pscore[side] - pscore[xside] + 10;
- if (dither) *score += rand() % dither;
-
- if (*score > 0 && pmtl[side] == 0)
- if (emtl[side] < valueR) *score = 0;
- else if (*score < valueR) *score /= 2;
- if (*score < 0 && pmtl[xside] == 0)
- if (emtl[xside] < valueR) *score = 0;
- else if (-*score < valueR) *score /= 2;
-
- if (mtl[xside] == valueK && emtl[side] > valueB) *score += 200;
- if (mtl[side] == valueK && emtl[xside] > valueB) *score -= 200;
-}
-
-
-ScoreLoneKing(side,score)
-short side,*score;
-
-/*
- Static evaluation when loser has only a king and winner has no pawns
- or no pieces.
-*/
-
-{
-short winner,loser,king1,king2,s,i;
-
- UpdateWeights();
- if (mtl[white] > mtl[black]) winner = white; else winner = black;
- loser = otherside[winner];
- king1 = PieceList[winner][0]; king2 = PieceList[loser][0];
-
- s = 0;
-
- if (pmtl[winner] > 0)
- for (i = 1; i <= PieceCnt[winner]; i++)
- s += ScoreKPK(side,winner,loser,king1,king2,PieceList[winner][i]);
-
- else if (emtl[winner] == valueB+valueN)
- s = ScoreKBNK(winner,king1,king2);
-
- else if (emtl[winner] > valueB)
- s = 500 + emtl[winner] - DyingKing[king2] - 2*distance(king1,king2);
-
- if (side == winner) *score = s; else *score = -s;
-}
-
-
-int ScoreKPK(side,winner,loser,king1,king2,sq)
-short side,winner,loser,king1,king2,sq;
-
-/*
- Score King and Pawns versus King endings.
-*/
-
-{
-short s,r;
-
- if (PieceCnt[winner] == 1) s = 50; else s = 120;
- if (winner == white)
- {
- if (side == loser) r = row[sq]-1; else r = row[sq];
- if (row[king2] >= r && distance(sq,king2) < 8-r) s += 10*row[sq];
- else s = 500+50*row[sq];
- if (row[sq] < 6) sq += 16; else sq += 8;
- }
- else
- {
- if (side == loser) r = row[sq]+1; else r = row[sq];
- if (row[king2] <= r && distance(sq,king2) < r+1) s += 10*(7-row[sq]);
- else s = 500+50*(7-row[sq]);
- if (row[sq] > 1) sq -= 16; else sq -= 8;
- }
- s += 8*(taxicab(king2,sq) - taxicab(king1,sq));
- return(s);
-}
-
-
-int ScoreKBNK(winner,king1,king2)
-short winner,king1,king2;
-
-/*
- Score King+Bishop+Knight versus King endings.
- This doesn't work all that well but it's better than nothing.
-*/
-
-{
-short s;
- s = emtl[winner] - 300;
- if (KBNKsq == 0) s += KBNK[king2];
- else s += KBNK[locn[row[king2]][7-column[king2]]];
- s -= taxicab(king1,king2);
- s -= distance(PieceList[winner][1],king2);
- s -= distance(PieceList[winner][2],king2);
- return(s);
-}
-
-
-SqValue(sq,side)
-short sq,side;
-
-/*
- Calculate the positional value for the piece on 'sq'.
-*/
-
-{
-register short j,fyle,rank;
-short s,piece,a1,a2,in_square,r,mob,e,c;
-
- piece = board[sq];
- a1 = (atk1[sq] & 0x4FFF); a2 = (atk2[sq] & 0x4FFF);
- rank = row[sq]; fyle = column[sq];
- s = 0;
- if (piece == pawn && c1 == white)
- {
- s = Mwpawn[sq];
- if (sq == 11 || sq == 12)
- if (color[sq+8] != neutral) s += PEDRNK2B;
- if ((fyle == 0 || PC1[fyle-1] == 0) &&
- (fyle == 7 || PC1[fyle+1] == 0))
- s += ISOLANI[fyle];
- else if (PC1[fyle] > 1) s += PDOUBLED;
- if (a1 < ctlP && atk1[sq+8] < ctlP)
- {
- s += BACKWARD[a2 & 0xFF];
- if (PC2[fyle] == 0) s += PWEAKH;
- if (color[sq+8] != neutral) s += PBLOK;
- }
- if (PC2[fyle] == 0)
- {
- if (side == black) r = rank-1; else r = rank;
- in_square = (row[bking] >= r && distance(sq,bking) < 8-r);
- if (a2 == 0 || side == white) e = 0; else e = 1;
- for (j = sq+8; j < 64; j += 8)
- if (atk2[j] >= ctlP) { e = 2; break; }
- else if (atk2[j] > 0 || color[j] != neutral) e = 1;
- if (e == 2) s += (stage*PassedPawn3[rank]) / 10;
- else if (in_square || e == 1) s += (stage*PassedPawn2[rank]) / 10;
- else if (emtl[black] > 0) s += (stage*PassedPawn1[rank]) / 10;
- else s += PassedPawn0[rank];
- }
- }
- else if (piece == pawn && c1 == black)
- {
- s = Mbpawn[sq];
- if (sq == 51 || sq == 52)
- if (color[sq-8] != neutral) s += PEDRNK2B;
- if ((fyle == 0 || PC1[fyle-1] == 0) &&
- (fyle == 7 || PC1[fyle+1] == 0))
- s += ISOLANI[fyle];
- else if (PC1[fyle] > 1) s += PDOUBLED;
- if (a1 < ctlP && atk1[sq-8] < ctlP)
- {
- s += BACKWARD[a2 & 0xFF];
- if (PC2[fyle] == 0) s += PWEAKH;
- if (color[sq-8] != neutral) s += PBLOK;
- }
- if (PC2[fyle] == 0)
- {
- if (side == white) r = rank+1; else r = rank;
- in_square = (row[wking] <= r && distance(sq,wking) < r+1);
- if (a2 == 0 || side == black) e = 0; else e = 1;
- for (j = sq-8; j >= 0; j -= 8)
- if (atk2[j] >= ctlP) { e = 2; break; }
- else if (atk2[j] > 0 || color[j] != neutral) e = 1;
- if (e == 2) s += (stage*PassedPawn3[7-rank]) / 10;
- else if (in_square || e == 1) s += (stage*PassedPawn2[7-rank]) / 10;
- else if (emtl[white] > 0) s += (stage*PassedPawn1[7-rank]) / 10;
- else s += PassedPawn0[7-rank];
- }
- }
- else if (piece == knight)
- {
- s = Mknight[c1][sq];
- }
- else if (piece == bishop)
- {
- s = Mbishop[c1][sq];
- BRscan(sq,&s,&mob);
- s += BMBLTY[mob];
- }
- else if (piece == rook)
- {
- s += RookBonus;
- BRscan(sq,&s,&mob);
- s += RMBLTY[mob];
- if (PC1[fyle] == 0) s += RHOPN;
- if (PC2[fyle] == 0) s += RHOPNX;
- if (rank == rank7[c1] && pmtl[c2] > 100) s += 10;
- if (stage > 2) s += 14 - taxicab(sq,EnemyKing);
- }
- else if (piece == queen)
- {
- if (stage > 2) s += 14 - taxicab(sq,EnemyKing);
- if (distance(sq,EnemyKing) < 3) s += 12;
- }
- else if (piece == king)
- {
- s = Mking[c1][sq];
- if (KSFTY > 0)
- if (Developed[c2] || stage > 0) KingScan(sq,&s);
- if (castld[c1]) s += KCASTLD;
- else if (kingmoved[c1]) s += KMOVD;
-
- if (PC1[fyle] == 0) s += KHOPN;
- if (PC2[fyle] == 0) s += KHOPNX;
- if (fyle == 1 || fyle == 2 || fyle == 3 || fyle == 7)
- {
- if (PC1[fyle-1] == 0) s += KHOPN;
- if (PC2[fyle-1] == 0) s += KHOPNX;
- }
- if (fyle == 4 || fyle == 5 || fyle == 6 || fyle == 0)
- {
- if (PC1[fyle+1] == 0) s += KHOPN;
- if (PC2[fyle+1] == 0) s += KHOPNX;
- }
- if (fyle == 2)
- {
- if (PC1[0] == 0) s += KHOPN;
- if (PC2[0] == 0) s += KHOPNX;
- }
- if (fyle == 5)
- {
- if (PC1[7] == 0) s += KHOPN;
- if (PC2[7] == 0) s += KHOPNX;
- }
- }
-
- if (a2 > 0)
- {
- c = (control[piece] & 0x4FFF);
- if (a1 == 0 || a2 > c+1)
- {
- s += HUNGP;
- ++hung[c1];
- if (piece != king && trapped(sq,piece)) ++hung[c1];
- }
- else if (piece != pawn || a2 > a1)
- if (a2 >= c || a1 < ctlP) s += ATAKD;
- }
- return(s);
-}
-
-#if (NEWMOVE > 6)
-KingScan(sq,s)
-short sq,*s;
-
-/*
- Assign penalties if king can be threatened by checks, if squares
- near the king are controlled by the enemy (especially the queen),
- or if there are no pawns near the king.
-*/
-
-#define ScoreThreat\
- if (color[u] != c2)\
- if (atk1[u] == 0 || (atk2[u] & 0xFF) > 1) ++cnt;\
- else *s -= 3
-
-{
-register short m,u;
-short d,i,m0,cnt,ok;
-
- cnt = 0;
- m0 = map[sq];
- if (HasBishop[c2] || HasQueen[c2])
- for (i = Dstart[bishop]; i <= Dstop[bishop]; i++)
- {
- d = Dir[i]; m = m0+d;
- while (!(m & 0x88))
- {
- u = unmap[m];
- if (atk2[u] & ctlBQ) ScoreThreat;
- if (color[u] != neutral) break;
- m += d;
- }
- }
- if (HasRook[c2] || HasQueen[c2])
- for (i = Dstart[rook]; i <= Dstop[rook]; i++)
- {
- d = Dir[i]; m = m0+d;
- while (!(m & 0x88))
- {
- u = unmap[m];
- if (atk2[u] & ctlRQ) ScoreThreat;
- if (color[u] != neutral) break;
- m += d;
- }
- }
- if (HasKnight[c2])
- for (i = Dstart[knight]; i <= Dstop[knight]; i++)
- if (!((m = m0+Dir[i]) & 0x88))
- {
- u = unmap[m];
- if (atk2[u] & ctlNN) ScoreThreat;
- }
- *s += (KSFTY*Kthreat[cnt]) / 16;
-
- cnt = 0; ok = false;
- m0 = map[sq];
- for (i = Dstart[king]; i <= Dstop[king]; i++)
- if (!((m = m0+Dir[i]) & 0x88))
- {
- u = unmap[m];
- if (board[u] == pawn) ok = true;
- if (atk2[u] > atk1[u])
- {
- ++cnt;
- if (atk2[u] & ctlQ)
- if (atk2[u] > ctlQ+1 && atk1[u] < ctlQ) *s -= 4*KSFTY;
- }
- }
- if (!ok) *s -= KSFTY;
- if (cnt > 1) *s -= KSFTY;
-}
-#endif
-
-#if (NEWMOVE < 4)
-BRscan(sq,s,mob)
-short sq,*s,*mob;
-
-/*
- Find Bishop and Rook mobility, XRAY attacks, and pins. Increment the
- hung[] array if a pin is found.
-*/
-
-{
-register short m,u;
-short d,j,m0,piece,pin,*Kf;
-
- Kf = Kfield[c1];
- *mob = 0;
- m0 = map[sq]; piece = board[sq];
- for (j = Dstart[piece]; j <= Dstop[piece]; j++)
- {
- pin = -1;
- d = Dir[j]; m = m0+d;
- while (!(m & 0x88))
- {
- u = unmap[m]; *s += Kf[u];
- if (color[u] == neutral)
- {
- (*mob)++;
- m += d;
- }
- else if (pin < 0)
- {
- if (board[u] == pawn || board[u] == king) break;
- pin = u;
- m += d;
- }
- else if (color[u] == c2 && (board[u] > piece || atk2[u] == 0))
- {
- if (color[pin] == c2)
- {
- *s += PINVAL;
- if (atk2[pin] == 0 ||
- atk1[pin] > control[board[pin]]+1)
- ++hung[c2];
- }
- else *s += XRAY;
- break;
- }
- else break;
- }
- }
-}
-#endif
-
-#if (NEWMOVE > 5)
-int trapped(sq,piece)
-short sq,piece;
-
-/*
- See if the attacked piece has unattacked squares to move to.
-*/
-
-{
-register short u,m,d;
-short i,m0;
-
- m0 = map[sq];
- if (sweep[piece])
- for (i = Dstart[piece]; i <= Dstop[piece]; i++)
- {
- d = Dir[i]; m = m0+d;
- while (!(m & 0x88))
- {
- u = unmap[m];
- if (color[u] == c1) break;
- if (atk2[u] == 0 || board[u] >= piece) return(false);
- if (color[u] == c2) break;
- m += d;
- }
- }
- else if (piece == pawn)
- {
- if (c1 == white) u = sq+8; else u = sq-8;
- if (color[u] == neutral && atk1[u] >= atk2[u])
- return(false);
- if (!((m = m0+Dir[Dpwn[c1]]) & 0x88))
- if (color[unmap[m]] == c2) return(false);
- if (!((m = m0+Dir[Dpwn[c1]+1]) & 0x88))
- if (color[unmap[m]] == c2) return(false);
- }
- else
- {
- for (i = Dstart[piece]; i <= Dstop[piece]; i++)
- if (!((m = m0+Dir[i]) & 0x88))
- {
- u = unmap[m];
- if (color[u] != c1)
- if (atk2[u] == 0 || board[u] >= piece) return(false);
- }
- }
- return(true);
-}
-#endif
-
-ExaminePosition()
-
-/*
- This is done one time before the search is started. Set up arrays
- Mwpawn, Mbpawn, Mknight, Mbishop, Mking which are used in the
- SqValue() function to determine the positional value of each piece.
-*/
-
-{
-register short i,sq;
-short wpadv,bpadv,wstrong,bstrong,z,side,pp,j,val,Pd,fyle,rank;
-
- wking = PieceList[white][0]; bking = PieceList[black][0];
- ataks(white,atak[white]); ataks(black,atak[black]);
- Zwmtl = Zbmtl = 0;
- UpdateWeights();
- HasPawn[white] = HasPawn[black] = 0;
- HasKnight[white] = HasKnight[black] = 0;
- HasBishop[white] = HasBishop[black] = 0;
- HasRook[white] = HasRook[black] = 0;
- HasQueen[white] = HasQueen[black] = 0;
- for (side = white; side <= black; side++)
- for (i = 0; i <= PieceCnt[side]; i++)
- switch (board[PieceList[side][i]])
- {
- case pawn : ++HasPawn[side]; break;
- case knight : ++HasKnight[side]; break;
- case bishop : ++HasBishop[side]; break;
- case rook : ++HasRook[side]; break;
- case queen : ++HasQueen[side]; break;
- }
- if (!Developed[white])
- Developed[white] = (board[1] != knight && board[2] != bishop &&
- board[5] != bishop && board[6] != knight);
- if (!Developed[black])
- Developed[black] = (board[57] != knight && board[58] != bishop &&
- board[61] != bishop && board[62] != knight);
- if (!PawnStorm && stage < 5)
- PawnStorm = ((column[wking] < 3 && column[bking] > 4) ||
- (column[wking] > 4 && column[bking] < 3));
-
- CopyBoard(pknight,Mknight[white]);
- CopyBoard(pknight,Mknight[black]);
- CopyBoard(pbishop,Mbishop[white]);
- CopyBoard(pbishop,Mbishop[black]);
- BlendBoard(KingOpening,KingEnding,Mking[white]);
- BlendBoard(KingOpening,KingEnding,Mking[black]);
-
- for (sq = 0; sq < 64; sq++)
- {
- fyle = column[sq]; rank = row[sq];
- wstrong = bstrong = true;
- for (i = sq; i < 64; i += 8)
- if (atak[black][i] >= ctlP) wstrong = false;
- for (i = sq; i >= 0; i -= 8)
- if (atak[white][i] >= ctlP) bstrong = false;
- wpadv = bpadv = PADVNCM;
- if ((fyle == 0 || PawnCnt[white][fyle-1] == 0) &&
- (fyle == 7 || PawnCnt[white][fyle+1] == 0)) wpadv = PADVNCI;
- if ((fyle == 0 || PawnCnt[black][fyle-1] == 0) &&
- (fyle == 7 || PawnCnt[black][fyle+1] == 0)) bpadv = PADVNCI;
- Mwpawn[sq] = (wpadv*PawnAdvance[sq]) / 10;
- Mbpawn[sq] = (bpadv*PawnAdvance[63-sq]) / 10;
- Mwpawn[sq] += PawnBonus; Mbpawn[sq] += PawnBonus;
- if (castld[white] || kingmoved[white])
- {
- if ((fyle < 3 || fyle > 4) && distance(sq,wking) < 3)
- Mwpawn[sq] += PAWNSHIELD;
- }
- else if (rank < 3 && (fyle < 2 || fyle > 5))
- Mwpawn[sq] += PAWNSHIELD / 2;
- if (castld[black] || kingmoved[black])
- {
- if ((fyle < 3 || fyle > 4) && distance(sq,bking) < 3)
- Mbpawn[sq] += PAWNSHIELD;
- }
- else if (rank > 4 && (fyle < 2 || fyle > 5))
- Mbpawn[sq] += PAWNSHIELD / 2;
- if (PawnStorm)
- {
- if ((column[wking] < 4 && fyle > 4) ||
- (column[wking] > 3 && fyle < 3)) Mwpawn[sq] += 3*rank - 21;
- if ((column[bking] < 4 && fyle > 4) ||
- (column[bking] > 3 && fyle < 3)) Mbpawn[sq] -= 3*rank;
- }
-
- Mknight[white][sq] += 5 - distance(sq,bking);
- Mknight[white][sq] += 5 - distance(sq,wking);
- Mknight[black][sq] += 5 - distance(sq,wking);
- Mknight[black][sq] += 5 - distance(sq,bking);
- Mbishop[white][sq] += BishopBonus;
- Mbishop[black][sq] += BishopBonus;
- for (i = 0; i <= PieceCnt[black]; i++)
- if (distance(sq,PieceList[black][i]) < 3)
- Mknight[white][sq] += KNIGHTPOST;
- for (i = 0; i <= PieceCnt[white]; i++)
- if (distance(sq,PieceList[white][i]) < 3)
- Mknight[black][sq] += KNIGHTPOST;
- if (wstrong) Mknight[white][sq] += KNIGHTSTRONG;
- if (bstrong) Mknight[black][sq] += KNIGHTSTRONG;
- if (wstrong) Mbishop[white][sq] += BISHOPSTRONG;
- if (bstrong) Mbishop[black][sq] += BISHOPSTRONG;
-
- if (HasBishop[white] == 2) Mbishop[white][sq] += 8;
- if (HasBishop[black] == 2) Mbishop[black][sq] += 8;
- if (HasKnight[white] == 2) Mknight[white][sq] += 5;
- if (HasKnight[black] == 2) Mknight[black][sq] += 5;
-
- if (board[sq] == bishop)
- if (rank % 2 == fyle % 2) KBNKsq = 0; else KBNKsq = 7;
-
- Kfield[white][sq] = Kfield[black][sq] = 0;
- if (distance(sq,wking) == 1) Kfield[black][sq] = KATAK;
- if (distance(sq,bking) == 1) Kfield[white][sq] = KATAK;
-
- Pd = 0;
- for (i = 0; i < 64; i++)
- if (board[i] == pawn)
- {
- if (color[i] == white)
- {
- pp = true;
- if (row[i] == 6) z = i+8; else z = i+16;
- for (j = i+8; j < 64; j += 8)
- if (atak[black][j] > ctlP || board[j] == pawn) pp = false;
- }
- else
- {
- pp = true;
- if (row[i] == 1) z = i-8; else z = i-16;
- for (j = i-8; j >= 0; j -= 8)
- if (atak[white][j] > ctlP || board[j] == pawn) pp = false;
- }
- if (pp) Pd += 5*taxicab(sq,z); else Pd += taxicab(sq,z);
- }
- if (Pd != 0)
- {
- val = (Pd*stage2) / 10;
- Mking[white][sq] -= val;
- Mking[black][sq] -= val;
- }
- }
-}
-
-
-UpdateWeights()
-
-/*
- If material balance has changed, determine the values for the
- positional evaluation terms.
-*/
-
-{
-short tmtl;
-
- if (mtl[white] != Zwmtl || mtl[black] != Zbmtl)
- {
- Zwmtl = mtl[white]; Zbmtl = mtl[black];
- emtl[white] = Zwmtl - pmtl[white] - valueK;
- emtl[black] = Zbmtl - pmtl[black] - valueK;
- tmtl = emtl[white] + emtl[black];
- if (tmtl > 6600) stage = 0;
- else if (tmtl < 1400) stage = 10;
- else stage = (6600-tmtl) / 520;
- if (tmtl > 3600) stage2 = 0;
- else if (tmtl < 1400) stage2 = 10;
- else stage2 = (3600-tmtl) / 220;
-
- PEDRNK2B = -15; /* centre pawn on 2nd rank & blocked */
- PBLOK = -4; /* blocked backward pawn */
- PDOUBLED = -14; /* doubled pawn */
- PWEAKH = -4; /* weak pawn on half open file */
- PAWNSHIELD = 10-stage; /* pawn near friendly king */
- PADVNCM = 10; /* advanced pawn multiplier */
- PADVNCI = 7; /* muliplier for isolated pawn */
- PawnBonus = stage;
-
- KNIGHTPOST = (stage+2)/3; /* knight near enemy pieces */
- KNIGHTSTRONG = (stage+6)/2; /* occupies pawn hole */
-
- BISHOPSTRONG = (stage+6)/2; /* occupies pawn hole */
- BishopBonus = 2*stage;
-
- RHOPN = 10; /* rook on half open file */
- RHOPNX = 4;
- RookBonus = 6*stage;
-
- XRAY = 8; /* Xray attack on piece */
- PINVAL = 10; /* Pin */
-
- KHOPN = (3*stage-30) / 2; /* king on half open file */
- KHOPNX = KHOPN / 2;
- KCASTLD = 10 - stage;
- KMOVD = -40 / (stage+1); /* king moved before castling */
- KATAK = (10-stage) / 2; /* B,R attacks near enemy king */
- if (stage < 8) KSFTY = 16-2*stage; else KSFTY = 0;
-
- ATAKD = -6; /* defender > attacker */
- HUNGP = -8; /* each hung piece */
- HUNGX = -12; /* extra for >1 hung piece */
- }
-}
-
-#if (NEWMOVE < 1)
-int distance(a,b)
-short a,b;
-{
-register short d1,d2;
-
- d1 = abs(column[a]-column[b]);
- d2 = abs(row[a]-row[b]);
- return(d1 > d2 ? d1 : d2);
-}
-#endif
-
-BlendBoard(a,b,c)
-short a[64],b[64],c[64];
-{
-register int sq;
- for (sq = 0; sq < 64; sq++)
- c[sq] = (a[sq]*(10-stage) + b[sq]*stage) / 10;
-}
-
-
-CopyBoard(a,b)
-short a[64],b[64];
-{
-register int sq;
- for (sq = 0; sq < 64; sq++)
- b[sq] = a[sq];
-}
diff --git a/gnu/games/chess/gnuchess.h b/gnu/games/chess/gnuchess.h
deleted file mode 100644
index ee6442e..0000000
--- a/gnu/games/chess/gnuchess.h
+++ /dev/null
@@ -1,97 +0,0 @@
-/*
- This file contains code for CHESS.
- Copyright (C) 1986, 1987, 1988 Free Software Foundation, Inc.
-
- This file is part of CHESS.
-
- CHESS is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY. No author or distributor
- accepts responsibility to anyone for the consequences of using it
- or for whether it serves any particular purpose or works at all,
- unless he says so in writing. Refer to the CHESS General Public
- License for full details.
-
- Everyone is granted permission to copy, modify and redistribute
- CHESS, but only under the conditions described in the
- CHESS General Public License. A copy of this license is
- supposed to have been given to you along with CHESS so you
- can know your rights and responsibilities. It should be in a
- file named COPYING. Among other things, the copyright notice
- and this notice must be preserved on all copies.
-*/
-
-
-/* Header file for GNU CHESS */
-
-#define neutral 2
-#define white 0
-#define black 1
-#define no_piece 0
-#define pawn 1
-#define knight 2
-#define bishop 3
-#define rook 4
-#define queen 5
-#define king 6
-#define pxx " PNBRQK"
-#define qxx " pnbrqk"
-#define rxx "12345678"
-#define cxx "abcdefgh"
-#define check 0x0001
-#define capture 0x0002
-#define draw 0x0004
-#define promote 0x0008
-#define cstlmask 0x0010
-#define epmask 0x0020
-#define exact 0x0040
-#define pwnthrt 0x0080
-#define maxdepth 30
-#define true 1
-#define false 0
-
-struct leaf
- {
- short f,t,score,reply;
- unsigned short flags;
- };
-struct GameRec
- {
- unsigned short gmove;
- short score,depth,time,piece,color;
- long nodes;
- };
-struct TimeControlRec
- {
- short moves[2];
- long clock[2];
- };
-struct BookEntry
- {
- struct BookEntry *next;
- unsigned short *mv;
- };
-
-extern char mvstr1[5],mvstr2[5];
-extern struct leaf Tree[2000],*root;
-extern short TrPnt[maxdepth],board[64],color[64];
-extern short row[64],column[64],locn[8][8];
-extern short atak[2][64],PawnCnt[2][8];
-extern short castld[2],kingmoved[2];
-extern short c1,c2,*atk1,*atk2,*PC1,*PC2;
-extern short mate,post,opponent,computer,Sdepth,Awindow,Bwindow,dither;
-extern long ResponseTime,ExtraTime,Level,et,et0,time0,cputimer,ft;
-extern long NodeCnt,evrate,ETnodes,EvalNodes,HashCnt;
-extern short quit,reverse,bothsides,hashflag,InChk,player,force,easy,beep,meter;
-extern short timeout,xwndw;
-extern struct GameRec GameList[240];
-extern short GameCnt,Game50,epsquare,lpost,rcptr,contempt;
-extern short MaxSearchDepth;
-extern struct BookEntry *Book;
-extern struct TimeControlRec TimeControl;
-extern short TCflag,TCmoves,TCminutes,OperatorTime;
-extern short otherside[3];
-extern short Stboard[64];
-extern short Stcolor[64];
-extern unsigned short hint,PrVar[maxdepth];
-
-#define HZ 60
diff --git a/gnu/games/chess/move.c b/gnu/games/chess/move.c
deleted file mode 100644
index b4b0d42..0000000
--- a/gnu/games/chess/move.c
+++ /dev/null
@@ -1,357 +0,0 @@
-/* move generator hes@log-sv.se 890318
- Modified: 890606 NEWMOVE Levels 1-6 for easier debugging */
-#include "move.h"
-#include "gnuchess.h"
-
-short distdata[64][64];
-short taxidata[64][64];
-
-void Initialize_dist() {
-register short a,b,d,di;
-
- /* init taxi and dist data */
- for(a=0;a<64;a++)
- for(b=0;b<64;b++) {
- d = abs(column[a]-column[b]);
- di = abs(row[a]-row[b]);
- taxidata[a][b] = d + di;
- distdata[a][b] = (d > di ? d : di);
- };
-}
-
-#if (NEWMOVE > 1)
-struct sqdata posdata[3][8][64][64];
-
-static short direc[8][8] = {
- 0, 0, 0, 0, 0, 0, 0, 0, /* no_piece = 0 */
- -10,-11, -9, 0, 0, 0, 0, 0, /* wpawn = 1 */
- -21,-19,-12, -8, 21, 19, 12, 8, /* knight = 2 */
- -11, -9, 11, 9, 0, 0, 0, 0, /* bishop = 3 */
- -10, -1, 10, 1, 0, 0, 0, 0, /* rook = 4 */
- -11, -9,-10, -1, 11, 9, 10, 1, /* queen = 5 */
- -11, -9,-10, -1, 11, 9, 10, 1, /* king = 6 */
- 0, 0, 0, 0, 0, 0, 0, 0};/* no_piece = 7 */
-
-static short dc[3] = {-1,1,0};
-
-static short max_steps [8] = {0,2,1,7,7,7,1,0};
-
-static short unmap[120] = {
- -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
- -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
- -1, 0, 1, 2, 3, 4, 5, 6, 7,-1,
- -1, 8, 9,10,11,12,13,14,15,-1,
- -1,16,17,18,19,20,21,22,23,-1,
- -1,24,25,26,27,28,29,30,31,-1,
- -1,32,33,34,35,36,37,38,39,-1,
- -1,40,41,42,43,44,45,46,47,-1,
- -1,48,49,50,51,52,53,54,55,-1,
- -1,56,57,58,59,60,61,62,63,-1,
- -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
- -1,-1,-1,-1,-1,-1,-1,-1,-1,-1};
-
-void Initialize_moves() {
- short c,ptyp,po,p0,d,di,s;
- struct sqdata *p;
- short dest[8][8];
- short steps[8];
- short sorted[8];
-
- /* init posdata */
- for(c=0;c<3;c++)
- for(ptyp=0;ptyp<8;ptyp++)
- for(po=0;po<64;po++)
- for(p0=0;p0<64;p0++) {
- posdata[c][ptyp][po][p0].nextpos = po;
- posdata[c][ptyp][po][p0].nextdir = po;
- };
- /* dest is a function of dir and step */
- for(c=0;c<2;c++)
- for(ptyp=1;ptyp<7;ptyp++)
- for(po=21;po<99;po++)
- if (unmap[po] >= 0) {
- p = posdata[c][ptyp][unmap[po]];
- for(d=0;d<8;d++) {
- dest[d][0] = unmap[po];
- if (dc[c]*direc[ptyp][d] != 0) {
- p0=po;
- for(s=0;s<max_steps[ptyp];s++) {
- p0 = p0 + dc[c]*direc[ptyp][d];
- /* break if (off board) or
- (pawns move two steps from home square) */
- if (unmap[p0] < 0 ||
- (ptyp == pawn && s>0 && (d>0 || Stboard[unmap[po]] != ptyp)))
- break;
- else
- dest[d][s] = unmap[p0];
- }
- }
- else s=0;
- /* sort dest in number of steps order */
- steps[d] = s;
- for(di=d;di>0;di--)
- if (steps[sorted[di-1]] < s)
- sorted[di] = sorted[di-1];
- else
- break;
- sorted[di] = d;
- }
- /* update posdata, pawns have two threads (capture and no capture) */
- p0=unmap[po];
- if (ptyp == pawn) {
- for(s=0;s<steps[0];s++) {
- p[p0].nextpos = dest[0][s];
- p0 = dest[0][s];
- }
- p0=unmap[po];
- for(d=1;d<3;d++) {
- p[p0].nextdir = dest[d][0];
- p0 = dest[d][0];
- }
- }
- else {
- p[p0].nextdir = dest[sorted[0]][0];
- for(d=0;d<8;d++)
- for(s=0;s<steps[sorted[d]];s++) {
- p[p0].nextpos = dest[sorted[d]][s];
- p0 = dest[sorted[d]][s];
- if (d < 7)
- p[p0].nextdir = dest[sorted[d+1]][0];
- /* else is already initialised */
- }
- }
-#ifdef DEBUG
- printf("Ptyp:%d Position:%d\n{",ptyp,unmap[po]);
- for(p0=0;p0<63;p0++) printf("%d,",p[p0].nextpos);
- printf("%d};\n",p[63].nextpos);
- for(p0=0;p0<63;p0++) printf("%d,",p[p0].nextdir);
- printf("%d};\n",p[63].nextdir);
-#endif DEBUG
- }
-}
-#endif
-
-
-#if (NEWMOVE > 2)
-int SqAtakd(sq,side)
-short sq,side;
-
-/*
- See if any piece with color 'side' ataks sq. First check pawns
- Then Queen, Bishop, Rook and King and last Knight.
-*/
-
-{
- register short u;
- register struct sqdata *p;
-
- p = posdata[1-side][pawn][sq];
- u = p[sq].nextdir; /* follow captures thread */
- while (u != sq) {
- if (board[u] == pawn && color[u] == side) return(true);
- u = p[u].nextdir;
- }
- /* king capture */
- if (distance(sq,PieceList[side][0]) == 1) return(true);
- /* try a queen bishop capture */
- p = posdata[side][bishop][sq];
- u = p[sq].nextpos;
- while (u != sq) {
- if (color[u] == neutral) {
- u = p[u].nextpos;
- }
- else {
- if (color[u] == side &&
- (board[u] == queen || board[u] == bishop))
- return(true);
- u = p[u].nextdir;
- }
- }
- /* try a queen rook capture */
- p = posdata[side][rook][sq];
- u = p[sq].nextpos;
- while (u != sq) {
- if (color[u] == neutral) {
- u = p[u].nextpos;
- }
- else {
- if (color[u] == side &&
- (board[u] == queen || board[u] == rook))
- return(true);
- u = p[u].nextdir;
- }
- }
- /* try a knight capture */
- p = posdata[side][knight][sq];
- u = p[sq].nextpos;
- while (u != sq) {
- if (color[u] == neutral) {
- u = p[u].nextpos;
- }
- else {
- if (color[u] == side && board[u] == knight) return(true);
- u = p[u].nextdir;
- }
- }
- return(false);
-}
-#endif
-
-#if (NEWMOVE > 3)
-BRscan(sq,s,mob)
-short sq,*s,*mob;
-/*
- Find Bishop and Rook mobility, XRAY attacks, and pins. Increment the
- hung[] array if a pin is found.
-*/
-{
- register short u,piece,pin;
- register struct sqdata *p;
- short *Kf;
-
- Kf = Kfield[c1];
- *mob = 0;
- piece = board[sq];
- p = posdata[color[sq]][piece][sq];
- u = p[sq].nextpos;
- pin = -1; /* start new direction */
- while (u != sq) {
- *s += Kf[u];
- if (color[u] == neutral) {
- (*mob)++;
- if (p[u].nextpos == p[u].nextdir) pin = -1; /* oops new direction */
- u = p[u].nextpos;
- }
- else if (pin < 0) {
- if (board[u] == pawn || board[u] == king)
- u = p[u].nextdir;
- else {
- if (p[u].nextpos != p[u].nextdir)
- pin = u; /* not on the edge and on to find a pin */
- u = p[u].nextpos;
- }
- }
- else if (color[u] == c2 && (board[u] > piece || atk2[u] == 0))
- {
- if (color[pin] == c2)
- {
- *s += PINVAL;
- if (atk2[pin] == 0 ||
- atk1[pin] > control[board[pin]]+1)
- ++hung[c2];
- }
- else *s += XRAY;
- pin = -1; /* new direction */
- u = p[u].nextdir;
- }
- else {
- pin = -1; /* new direction */
- u = p[u].nextdir;
- }
- }
-}
-#endif
-
-#if (NEWMOVE >= 5)
-CaptureList(side,xside,ply)
-short side,xside,ply;
-{
- register short u,sq;
- register struct sqdata *p;
- short i,piece,*PL;
- struct leaf *node;
-
- TrPnt[ply+1] = TrPnt[ply];
- node = &Tree[TrPnt[ply]];
- PL = PieceList[side];
- for (i = 0; i <= PieceCnt[side]; i++)
- {
- sq = PL[i];
- piece = board[sq];
- p = posdata[side][piece][sq];
- if (piece == pawn) {
- u = p[sq].nextdir; /* follow captures thread */
- while (u != sq) {
- if (color[u] == xside) {
- node->f = sq; node->t = u;
- node->flags = capture;
- if (u < 8 || u > 55)
- {
- node->flags |= promote;
- node->score = valueQ;
- }
- else
- node->score = value[board[u]] + svalue[board[u]] - piece;
- ++node;
- ++TrPnt[ply+1];
- }
- u = p[u].nextdir;
- }
- }
- else {
- u = p[sq].nextpos;
- while (u != sq) {
- if (color[u] == neutral)
- u = p[u].nextpos;
- else {
- if (color[u] == xside) {
- node->f = sq; node->t = u;
- node->flags = capture;
- node->score = value[board[u]] + svalue[board[u]] - piece;
- ++node;
- ++TrPnt[ply+1];
- }
- u = p[u].nextdir;
- }
- }
- }
- }
-}
-#endif
-
-#if (NEWMOVE > 5)
-GenMoves(ply,sq,side,xside)
- short ply,sq,side,xside;
-
-/*
- Generate moves for a piece. The moves are taken from the
- precalulated array posdata. If the board is free, next move
- is choosen from nextpos else from nextdir.
-*/
-
-{
- register short u,piece;
- register struct sqdata *p;
-
- piece = board[sq];
- p = posdata[side][piece][sq];
- if (piece == pawn) {
- u = p[sq].nextdir; /* follow captures thread */
- while (u != sq) {
- if (color[u] == xside) LinkMove(ply,sq,u,xside);
- u = p[u].nextdir;
- }
- u = p[sq].nextpos; /* and follow no captures thread */
- while (u != sq) {
- if (color[u] == neutral && (u != sq+16 || color[u-8] == neutral)
- && (u != sq-16 || color[u+8] == neutral)) {
- LinkMove(ply,sq,u,xside);
- }
- u = p[u].nextpos;
- }
- }
- else {
- u = p[sq].nextpos;
- while (u != sq) {
- if (color[u] == neutral) {
- LinkMove(ply,sq,u,xside);
- u = p[u].nextpos;
- }
- else {
- if (color[u] == xside) LinkMove(ply,sq,u,xside);
- u = p[u].nextdir;
- }
- }
- }
-}
-#endif
diff --git a/gnu/games/chess/move.h b/gnu/games/chess/move.h
deleted file mode 100644
index 3294e4a..0000000
--- a/gnu/games/chess/move.h
+++ /dev/null
@@ -1,81 +0,0 @@
-/* header file for move generator hes 890318
- Modified: 890510 minor bug fixed in Newataks
- 890606 NEWMOVE levels 1-6 */
-
-#if (NEWMOVE >= 1)
-extern short distdata[64][64];
-extern short taxidata[64][64];
-
-#define taxicab(a,b) taxidata[a][b]
-#define distance(a,b) distdata[a][b]
-
-extern void Initialize_dist();
-#endif
-
-#if (NEWMOVE >= 2)
-struct sqdata {
- short nextpos;
- short nextdir;
-};
-extern struct sqdata posdata[3][8][64][64];
-
-extern void Initialize_moves();
-
-#define ataks(side,a)\
-{\
- register short u,c,sq;\
- register struct sqdata *p;\
- short i,piece,*PL;\
- \
- for (u = 64; u; a[--u] = 0); \
- PL = PieceList[side];\
- for (i = 0; i <= PieceCnt[side]; i++)\
- {\
- sq = PL[i];\
- piece = board[sq];\
- c = control[piece];\
- p = posdata[side][piece][sq];\
- if (piece == pawn) {\
- u = p[sq].nextdir; /* follow captures thread */\
- while (u != sq) {\
- a[u] = ++a[u] | c;\
- u = p[u].nextdir;\
- }\
- }\
- else {\
- u = p[sq].nextpos;\
- while (u != sq) {\
- a[u] = ++a[u] | c;\
- if (color[u] == neutral)\
- u = p[u].nextpos;\
- else\
- u = p[u].nextdir;\
- }\
- }\
- }\
-}
-#endif
-
-#if (NEWMOVE >= 3)
-extern short PieceList[2][16];
-
-extern int Sqatakd();
-#endif
-
-#if (NEWMOVE > 3)
-extern short Kfield[2][64],PINVAL,control[7],hung[2],XRAY;
-
-extern BRscan();
-#endif
-
-#if (NEWMOVE > 4)
-#define valueQ 1100
-
-extern short PieceCnt[2],value[7],svalue[64];
-
-extern CaptureList();
-#endif
-
-#if (NEWMOVE > 5)
-extern GenMoves();
-#endif
diff --git a/gnu/games/chess/nondsp.c b/gnu/games/chess/nondsp.c
deleted file mode 100644
index bec36d3..0000000
--- a/gnu/games/chess/nondsp.c
+++ /dev/null
@@ -1,791 +0,0 @@
-/*
- UNIX & MSDOS NON-DISPLAY, AND CHESSTOOL interface for Chess
-
- Revision: 4-25-88
-
- Copyright (C) 1986, 1987, 1988 Free Software Foundation, Inc.
- Copyright (c) 1988 John Stanback
-
- This file is part of CHESS.
-
- CHESS is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY. No author or distributor
- accepts responsibility to anyone for the consequences of using it
- or for whether it serves any particular purpose or works at all,
- unless he says so in writing. Refer to the CHESS General Public
- License for full details.
-
- Everyone is granted permission to copy, modify and redistribute
- CHESS, but only under the conditions described in the
- CHESS General Public License. A copy of this license is
- supposed to have been given to you along with CHESS so you
- can know your rights and responsibilities. It should be in a
- file named COPYING. Among other things, the copyright notice
- and this notice must be preserved on all copies.
-*/
-
-
-#include <stdio.h>
-#include <ctype.h>
-#ifdef MSDOS
-#include <dos.h>
-#include <stdlib.h>
-#include <time.h>
-#else
-#include <sys/param.h>
-#include <sys/times.h>
-#include <sys/file.h>
-struct tms tmbuf1,tmbuf2;
-int TerminateSearch(),Die();
-#endif MSDOS
-
-#include "gnuchess.h"
-#ifdef NEWMOVE
-#include "move.h"
-#endif
-
-#define printz printf
-#define scanz scanf
-int mycnt1,mycnt2;
-
-
-Initialize()
-{
- mycnt1 = mycnt2 = 0;
-#ifndef MSDOS
-#endif
-#ifdef CHESSTOOL
- setlinebuf(stdout);
-/*
- setvbuf(stdout,NULL,_IOLBF,BUFSIZ);
-*/
- printf("Chess\n");
- if (Level == 0 && !TCflag) Level = 15;
-#endif CHESSTOOL
-}
-
-ExitChess()
-{
- ListGame();
- exit(0);
-}
-
-#ifndef MSDOS
-Die()
-{
-char s[80];
- printz("Abort? ");
- scanz("%s",s);
- if (strcmp(s,"yes") == 0) ExitChess();
-}
-
-TerminateSearch()
-{
- timeout = true;
- bothsides = false;
-}
-#endif MSDOS
-
-
-InputCommand()
-
-/*
- Process the users command. If easy mode is OFF (the computer is
- thinking on opponents time) and the program is out of book, then make
- the 'hint' move on the board and call SelectMove() to find a response.
- The user terminates the search by entering ^C (quit siqnal) before
- entering a command. If the opponent does not make the hint move, then
- set Sdepth to zero.
-*/
-
-{
-int i;
-short ok,tmp;
-long cnt,rate,t1,t2;
-unsigned short mv;
-char s[80];
-
- ok = quit = false;
- player = opponent;
- ft = 0;
- if (hint > 0 && !easy && Book == NULL)
- {
- fflush(stdout);
- time0 = time((long *)0);
- algbr(hint>>8,hint & 0xFF,false);
- strcpy(s,mvstr1);
- tmp = epsquare;
- if (VerifyMove(s,1,&mv))
- {
- SelectMove(computer,2);
- VerifyMove(mvstr1,2,&mv);
- if (Sdepth > 0) Sdepth--;
- }
- ft = time((long *)0) - time0;
- epsquare = tmp;
- }
-
-#ifndef MSDOS
-#endif
- while (!(ok || quit))
- {
- PromptForMove();
- i = scanz("%s",s);
- if (i == EOF || s[0] == 0) ExitChess();
- player = opponent;
- ok = VerifyMove(s,0,&mv);
- if (ok && mv != hint)
- {
- Sdepth = 0;
- ft = 0;
- }
-
- if (strcmp(s,"bd") == 0)
- {
- ClrScreen();
- UpdateDisplay(0,0,1,0);
- }
- if (strcmp(s,"quit") == 0) quit = true;
- if (strcmp(s,"post") == 0) post = !post;
- if (strcmp(s,"set") == 0) EditBoard();
- if (strcmp(s,"go") == 0) ok = true;
- if (strcmp(s,"help") == 0) help();
- if (strcmp(s,"force") == 0) force = !force;
- if (strcmp(s,"book") == 0) Book = NULL;
- if (strcmp(s,"new") == 0) NewGame();
- if (strcmp(s,"list") == 0) ListGame();
- if (strcmp(s,"level") == 0) SelectLevel();
- if (strcmp(s,"hash") == 0) hashflag = !hashflag;
- if (strcmp(s,"beep") == 0) beep = !beep;
- if (strcmp(s,"Awindow") == 0) ChangeAlphaWindow();
- if (strcmp(s,"Bwindow") == 0) ChangeBetaWindow();
- if (strcmp(s,"rcptr") == 0) rcptr = !rcptr;
- if (strcmp(s,"hint") == 0) GiveHint();
- if (strcmp(s,"zero") == 0) ZeroTTable();
- if (strcmp(s,"both") == 0)
- {
- bothsides = !bothsides;
- Sdepth = 0;
- SelectMove(opponent,1);
- ok = true;
- }
- if (strcmp(s,"reverse") == 0)
- {
- reverse = !reverse;
- ClrScreen();
- UpdateDisplay(0,0,1,0);
- }
- if (strcmp(s,"switch") == 0)
- {
- computer = otherside[computer];
- opponent = otherside[opponent];
- force = false;
- Sdepth = 0;
- ok = true;
- }
- if (strcmp(s,"white") == 0)
- {
- computer = white; opponent = black;
- ok = true; force = false;
- Sdepth = 0;
- }
- if (strcmp(s,"black") == 0)
- {
- computer = black; opponent = white;
- ok = true; force = false;
- Sdepth = 0;
- }
- if (strcmp(s,"undo") == 0 && GameCnt >= 0) Undo();
- if (strcmp(s,"remove") == 0 && GameCnt >= 1)
- {
- Undo(); Undo();
- }
- if (strcmp(s,"get") == 0) GetGame();
- if (strcmp(s,"save") == 0) SaveGame();
- if (strcmp(s,"depth") == 0) ChangeSearchDepth();
- if (strcmp(s,"random") == 0) dither = 6;
- if (strcmp(s,"easy") == 0) easy = !easy;
- if (strcmp(s,"contempt") == 0) SetContempt();
- if (strcmp(s,"xwndw") == 0) ChangeXwindow();
- if (strcmp(s,"test") == 0)
- {
- t1 = time(0);
- cnt = 0;
- for (i = 0; i < 10000; i++)
- {
- MoveList(opponent,2);
- cnt += TrPnt[3] - TrPnt[2];
- }
- t2 = time(0);
- rate = cnt / (t2-t1);
- printz("cnt= %ld rate= %ld\n",cnt,rate);
- }
- }
-
- ElapsedTime(1);
- if (force)
- {
- computer = opponent; opponent = otherside[computer];
- }
-#ifndef MSDOS
- (void) times(&tmbuf1);
-#ifdef CHESSTOOL
- printf("%d. %s\n",++mycnt2,s);
-#endif CHESSTOOL
-#endif MSDOS
-}
-
-
-help()
-{
- ClrScreen();
- printz("CHESS command summary\n");
- printz("g1f3 move from g1 to f3\n");
- printz("nf3 move knight to f3\n");
- printz("o-o castle king side\n");
- printz("o-o-o castle queen side\n");
- printz("set edit board\n");
- printz("switch sides with computer\n");
- printz("white computer plays white\n");
- printz("black computer plays black\n");
- printz("reverse board display\n");
- printz("both computer match\n");
- printz("random randomize play\n");
- printz("undo undo last move\n");
- printz("time change level\n");
- printz("depth set search depth\n");
- printz("post principle variation\n");
- printz("hint suggest a move\n");
- printz("bd redraw board\n");
- printz("clock set time control\n");
- printz("force enter game moves\n");
- printz("list game to chess.lst\n");
- printz("save game to file\n");
- printz("get game from file\n");
- printz("new start new game\n");
- printz("quit exit CHESS\n");
- printz("Computer: ");
- if (computer == white) printz("WHITE\n"); else printz("BLACK\n");
- printz("Opponent: ");
- if (opponent == white) printz("WHITE\n"); else printz("BLACK\n");
- printz("Response time: %ld",Level," sec.\n");
- printz("Easy mode: ");
- if (easy) printz("ON\n"); else printz("OFF\n");
- printz("Depth: %d\n",MaxSearchDepth);
- printz("Random: ");
- if (dither) printz("ON\n"); else printz("OFF\n");
- printz("Transposition table: ");
- if (hashflag) printz("ON\n"); else printz("OFF\n");
- UpdateDisplay(0,0,1,0);
-}
-
-
-EditBoard()
-
-/*
- Set up a board position. Pieces are entered by typing the piece
- followed by the location. For example, Nf3 will place a knight on
- square f3.
-*/
-
-{
-short a,r,c,sq;
-char s[80];
-
- ClrScreen();
- UpdateDisplay(0,0,1,0);
- printz(". exit to main\n");
- printz("# clear board\n");
- printz("enter piece & location: \n");
-
- a = white;
- do
- {
- scanz("%s",s);
- if (s[0] == '#')
- {
- for (sq = 0; sq < 64; sq++)
- {
- board[sq] = no_piece; color[sq] = neutral;
- }
- UpdateDisplay(0,0,1,0);
- }
- if (s[0] == 'c' || s[0] == 'C') a = otherside[a];
- c = s[1]-'a'; r = s[2]-'1';
- if ((c >= 0) && (c < 8) && (r >= 0) && (r < 8))
- {
- sq = locn[r][c];
- color[sq] = a;
- if (s[0] == 'p') board[sq] = pawn;
- else if (s[0] == 'n') board[sq] = knight;
- else if (s[0] == 'b') board[sq] = bishop;
- else if (s[0] == 'r') board[sq] = rook;
- else if (s[0] == 'q') board[sq] = queen;
- else if (s[0] == 'k') board[sq] = king;
- else { board[sq] = no_piece; color[sq] = neutral; }
- }
- }
- while (s[0] != '.');
- if (board[4] != king) kingmoved[white] = 10;
- if (board[60] != king) kingmoved[black] = 10;
- GameCnt = -1; Game50 = 0; Sdepth = 0;
- InitializeStats();
- ClrScreen();
- UpdateDisplay(0,0,1,0);
-}
-
-
-ShowDepth(ch)
-char ch;
-{
-}
-
-ShowResults(score,bstline,ch)
-short score;
-unsigned short bstline[];
-char ch;
-{
-#ifndef CHESSTOOL
-register int i;
- printz("%2d%c %5d %4ld %7ld ",Sdepth,ch,score,et,NodeCnt);
- for (i = 1; bstline[i] > 0; i++)
- {
- algbr((short)(bstline[i] >> 8),(short)(bstline[i] & 0xFF),false);
- if (i == 9 || i == 17) printz("\n ");
- printz("%5s ",mvstr1);
- }
- printz("\n");
-#endif
-}
-
-
-SearchStartStuff(side)
-short side;
-{
-#ifndef MSDOS
-#endif
-#ifndef CHESSTOOL
- printz("\nMove# %d Target= %ld Clock: %ld\n",
- TCmoves-TimeControl.moves[side]+1,
- ResponseTime,TimeControl.clock[side]);
-#endif
-}
-
-
-OutputMove()
-{
-#ifdef CHESSTOOL
- printz("%d. ... %s\n",++mycnt1,mvstr1);
- if (root->flags & draw)
- {
- printz("Draw\n");
- ListGame();
- exit(0);
- }
- if (root->score == -9999)
- {
- if (opponent == white) printz("White\n"); else printz("Black\n");
- ListGame();
- exit(0);
- }
- if (root->score == 9998)
- {
- if (computer == white) printz("White\n"); else printz("Black\n");
- ListGame();
- exit(0);
- }
-#else
- printz("Nodes= %ld Eval= %ld Hash= %ld Rate= %ld ",
- NodeCnt,EvalNodes,HashCnt,evrate);
- printz("CPU= %.2ld:%.2ld.%.2ld\n\n",
- cputimer/6000,(cputimer % 6000)/100,cputimer % 100);
-
- if (root->flags & epmask) UpdateDisplay(0,0,1,0);
- else UpdateDisplay(root->f,root->t,0,root->flags & cstlmask);
- printz("My move is: %s\n\n",mvstr1);
- if (beep) printz("%c",7);
-
- if (root->flags & draw) printz("Draw game!\n");
- else if (root->score == -9999) printz("opponent mates!\n");
- else if (root->score == 9998) printz("computer mates!\n");
- else if (root->score < -9000) printz("opponent will soon mate!\n");
- else if (root->score > 9000) printz("computer will soon mate!\n");
-#endif CHESSTOOL
-}
-
-
-ElapsedTime(iop)
-short iop;
-
-/*
- Determine the time that has passed since the search was started. If
- the elapsed time exceeds the target (ResponseTime+ExtraTime) then set
- timeout to true which will terminate the search.
-*/
-
-{
- et = time((long *)0) - time0;
- if (et < 0) et = 0;
- ETnodes += 50;
- if (et > et0 || iop == 1)
- {
- if (et > ResponseTime+ExtraTime && Sdepth > 1) timeout = true;
- et0 = et;
- if (iop == 1)
- {
- time0 = time((long *)0); et0 = 0;
- }
-#ifdef MSDOS
- cputimer = 100*et;
- if (et > 0) evrate = NodeCnt/(et+ft); else evrate = 0;
- if (kbhit() && Sdepth > 1)
- {
- timeout = true;
- bothsides = false;
- }
-#else
- (void) times(&tmbuf2);
- cputimer = 100*(tmbuf2.tms_utime - tmbuf1.tms_utime) / HZ;
- if (cputimer > 0) evrate = (100*NodeCnt)/(cputimer+100*ft);
- else evrate = 0;
-#endif MSDOS
- ETnodes = NodeCnt + 50;
- }
-}
-
-
-SetTimeControl()
-{
- if (TCflag)
- {
- TimeControl.moves[white] = TimeControl.moves[black] = TCmoves;
- TimeControl.clock[white] = TimeControl.clock[black] = 60*(long)TCminutes;
- }
- else
- {
- TimeControl.moves[white] = TimeControl.moves[black] = 0;
- TimeControl.clock[white] = TimeControl.clock[black] = 0;
- Level = 60*(long)TCminutes;
- }
- et = 0;
- ElapsedTime(1);
-}
-
-
-ClrScreen()
-{
-#ifndef CHESSTOOL
- printz("\n");
-#endif
-}
-
-
-UpdateDisplay(f,t,flag,iscastle)
-short f,t,flag,iscastle;
-{
-#ifndef CHESSTOOL
-short r,c,l;
- if (flag)
- {
- printz("\n");
- for (r = 7; r >= 0; r--)
- {
- for (c = 0; c <= 7; c++)
- {
- if (reverse) l = locn[7-r][7-c]; else l = locn[r][c];
- if (color[l] == neutral) printz(" -");
- else if (color[l] == white) printz(" %c",qxx[board[l]]);
- else printz(" %c",pxx[board[l]]);
- }
- printz("\n");
- }
- printz("\n");
- }
-#endif CHESSTOOL
-}
-
-
-GetOpenings()
-
-/*
- Read in the Opening Book file and parse the algebraic notation for a
- move into an unsigned integer format indicating the from and to
- square. Create a linked list of opening lines of play, with
- entry->next pointing to the next line and entry->move pointing to a
- chunk of memory containing the moves. More Opening lines of up to 256
- half moves may be added to gnuchess.book.
-*/
-
-{
-FILE *fd;
-int c,i,j,side;
-char buffr[2048];
-struct BookEntry *entry;
-unsigned short mv,*mp,tmp[100];
-
- if ((fd = fopen("gnuchess.book","r")) != NULL)
- {
-/*
- setvbuf(fd,buffr,_IOFBF,2048);
-*/
- Book = NULL;
- i = 0; side = white;
- while ((c = parse(fd,&mv,side)) >= 0)
- if (c == 1)
- {
- tmp[++i] = mv;
- side = otherside[side];
- }
- else if (c == 0 && i > 0)
- {
- entry = (struct BookEntry *)malloc(sizeof(struct BookEntry));
- mp = (unsigned short *)malloc((i+1)*sizeof(unsigned short));
- entry->mv = mp;
- entry->next = Book;
- Book = entry;
- for (j = 1; j <= i; j++) *(mp++) = tmp[j];
- *mp = 0;
- i = 0; side = white;
- }
- fclose(fd);
- }
-}
-
-
-int parse(fd,mv,side)
-FILE *fd;
-unsigned short *mv;
-short side;
-{
-int c,i,r1,r2,c1,c2;
-char s[100];
- while ((c = getc(fd)) == ' ');
- i = 0; s[0] = c;
- while (c != ' ' && c != '\n' && c != EOF) s[++i] = c = getc(fd);
- s[++i] = '\0';
- if (c == EOF) return(-1);
- if (s[0] == '!' || i < 3)
- {
- while (c != '\n' && c != EOF) c = getc(fd);
- return(0);
- }
- if (s[4] == 'o')
- if (side == black) *mv = 0x3C3A; else *mv = 0x0402;
- else if (s[0] == 'o')
- if (side == black) *mv = 0x3C3E; else *mv = 0x0406;
- else
- {
- c1 = s[0] - 'a'; r1 = s[1] - '1';
- c2 = s[2] - 'a'; r2 = s[3] - '1';
- *mv = (locn[r1][c1]<<8) + locn[r2][c2];
- }
- return(1);
-}
-
-
-GetGame()
-{
-FILE *fd;
-char fname[40];
-int c;
-short sq;
-unsigned short m;
-
- printz("Enter file name: ");
- scanz("%s",fname);
- if (fname[0] == '\0') strcpy(fname,"chess.000");
- if ((fd = fopen(fname,"r")) != NULL)
- {
- fscanf(fd,"%hd%hd%hd",&computer,&opponent,&Game50);
- fscanf(fd,"%hd%hd%hd%hd",
- &castld[white],&castld[black],
- &kingmoved[white],&kingmoved[black]);
- fscanf(fd,"%hd%hd",&TCflag,&OperatorTime);
- fscanf(fd,"%ld%ld%hd%hd",
- &TimeControl.clock[white],&TimeControl.clock[black],
- &TimeControl.moves[white],&TimeControl.moves[black]);
- for (sq = 0; sq < 64; sq++)
- {
- fscanf(fd,"%hd",&m);
- board[sq] = (m >> 8); color[sq] = (m & 0xFF);
- if (color[sq] == 0) color[sq] = neutral; else --color[sq];
- }
- GameCnt = -1; c = '?';
- while (c != EOF)
- {
- ++GameCnt;
- c = fscanf(fd,"%hd%hd%hd%ld%hd%hd%hd",&GameList[GameCnt].gmove,
- &GameList[GameCnt].score,&GameList[GameCnt].depth,
- &GameList[GameCnt].nodes,&GameList[GameCnt].time,
- &GameList[GameCnt].piece,&GameList[GameCnt].color);
- if (GameList[GameCnt].color == 0) GameList[GameCnt].color = neutral;
- else --GameList[GameCnt].color;
- }
- GameCnt--;
- if (TimeControl.clock[white] > 0) TCflag = true;
- computer--; opponent--;
- }
- fclose(fd);
- InitializeStats();
- UpdateDisplay(0,0,1,0);
- Sdepth = 0;
-}
-
-
-SaveGame()
-{
-FILE *fd;
-char fname[40];
-short sq,i,c;
-
- printz("Enter file name: ");
- scanz("%s",fname);
-
- if (fname[0] == '\0' || access(fname,W_OK) == -1) strcpy(fname,"chess.000");
- fd = fopen(fname,"w");
- fprintf(fd,"%d %d %d\n",computer+1,opponent+1,Game50);
- fprintf(fd,"%d %d %d %d\n",
- castld[white],castld[black],kingmoved[white],kingmoved[black]);
- fprintf(fd,"%d %d\n",TCflag,OperatorTime);
- fprintf(fd,"%ld %ld %d %d\n",
- TimeControl.clock[white],TimeControl.clock[black],
- TimeControl.moves[white],TimeControl.moves[black]);
- for (sq = 0; sq < 64; sq++)
- {
- if (color[sq] == neutral) c = 0; else c = color[sq]+1;
- fprintf(fd,"%d\n",256*board[sq] + c);
- }
- for (i = 0; i <= GameCnt; i++)
- {
- if (GameList[i].color == neutral) c = 0;
- else c = GameList[i].color + 1;
- fprintf(fd,"%d %d %d %ld %d %d %d\n",
- GameList[i].gmove,GameList[i].score,GameList[i].depth,
- GameList[i].nodes,GameList[i].time,
- GameList[i].piece,c);
- }
- fclose(fd);
-}
-
-
-ListGame()
-{
-FILE *fd;
-short i,f,t;
- fd = fopen("chess.lst","w");
- fprintf(fd,"\n");
- fprintf(fd," score depth nodes time ");
- fprintf(fd," score depth nodes time\n");
- for (i = 0; i <= GameCnt; i++)
- {
- f = GameList[i].gmove>>8; t = (GameList[i].gmove & 0xFF);
- algbr(f,t,false);
- if ((i % 2) == 0) fprintf(fd,"\n"); else fprintf(fd," ");
- fprintf(fd,"%5s %5d %2d %6ld %5d",mvstr1,
- GameList[i].score,GameList[i].depth,
- GameList[i].nodes,GameList[i].time);
- }
- fprintf(fd,"\n\n");
- fclose(fd);
-}
-
-
-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();
-}
-
-
-ShowMessage(s)
-char *s;
-{
-#ifndef CHESSTOOL
- printz("%s\n");
-#endif CHESSTOOL
-}
-
-ShowSidetomove()
-{
-}
-
-PromptForMove()
-{
-#ifndef CHESSTOOL
- printz("\nYour move is? ");
-#endif CHESSTOOL
-}
-
-
-ShowCurrentMove(pnt,f,t)
-short pnt,f,t;
-{
-}
-
-ChangeAlphaWindow()
-{
- printz("window: ");
- scanz("%hd",&Awindow);
-}
-
-ChangeBetaWindow()
-{
- printz("window: ");
- scanz("%hd",&Bwindow);
-}
-
-GiveHint()
-{
- algbr((short)(hint>>8),(short)(hint & 0xFF),false);
- printz("try %s\n",mvstr1);
-}
-
-
-SelectLevel()
-{
- OperatorTime = 30000;
- printz("Enter #moves #minutes: ");
- scanz("%hd %hd",&TCmoves,&TCminutes);
- printz("Operator time= ");
- scanz("%hd",&OperatorTime);
- TCflag = (TCmoves > 1);
- SetTimeControl();
-}
-
-
-ChangeSearchDepth()
-{
- printz("depth= ");
- scanz("%hd",&MaxSearchDepth);
-}
-
-SetContempt()
-{
- printz("contempt= ");
- scanz("%hd",&contempt);
-}
-
-ChangeXwindow()
-{
- printz("xwndw= ");
- scanz("%hd",&xwndw);
-}
diff --git a/gnu/games/chess/uxdsp.c b/gnu/games/chess/uxdsp.c
deleted file mode 100644
index 84034bc..0000000
--- a/gnu/games/chess/uxdsp.c
+++ /dev/null
@@ -1,933 +0,0 @@
-/*
- ALPHA interface for CHESS
-
- Revision: 4-25-88
-
- Copyright (C) 1986, 1987, 1988 Free Software Foundation, Inc.
- Copyright (c) 1988 John Stanback
-
- This file is part of CHESS.
-
- CHESS is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY. No author or distributor
- accepts responsibility to anyone for the consequences of using it
- or for whether it serves any particular purpose or works at all,
- unless he says so in writing. Refer to the CHESS General Public
- License for full details.
-
- Everyone is granted permission to copy, modify and redistribute
- CHESS, but only under the conditions described in the
- CHESS General Public License. A copy of this license is
- supposed to have been given to you along with CHESS so you
- can know your rights and responsibilities. It should be in a
- file named COPYING. Among other things, the copyright notice
- and this notice must be preserved on all copies.
-*/
-
-
-#include <stdio.h>
-#include <ctype.h>
-#include <sys/param.h>
-#include <sys/times.h>
-#include <sys/file.h>
-#include <curses.h>
-#include <signal.h>
-#include "gnuchess.h"
-#ifdef NEWMOVE
-#include "move.h"
-#endif
-#include "pathnames.h"
-
-struct tms tmbuf1,tmbuf2;
-void TerminateSearch(),Die();
-
-#define scanz fflush(stdout),scanw
-#define printz printw
-
-
-Initialize()
-{
- signal(SIGINT,Die); signal(SIGQUIT,Die);
- initscr();
- crmode();
-}
-
-
-ExitChess()
-{
- nocrmode();
- endwin();
- exit(0);
-}
-
-
-void
-Die()
-{
-char s[80];
- signal(SIGINT,SIG_IGN);
- signal(SIGQUIT,SIG_IGN);
- ShowMessage("Abort? ");
- scanz("%s",s);
- if (strcmp(s,"yes") == 0) ExitChess();
- signal(SIGINT,Die); signal(SIGQUIT,Die);
-}
-
-
-void
-TerminateSearch()
-{
- signal(SIGINT,SIG_IGN);
- signal(SIGQUIT,SIG_IGN);
- timeout = true;
- bothsides = false;
- signal(SIGINT,Die); signal(SIGQUIT,Die);
-}
-
-
-InputCommand()
-
-/*
- Process the users command. If easy mode is OFF (the computer is
- thinking on opponents time) and the program is out of book, then make
- the 'hint' move on the board and call SelectMove() to find a response.
- The user terminates the search by entering ^C (quit siqnal) before
- entering a command. If the opponent does not make the hint move, then
- set Sdepth to zero.
-*/
-
-{
-short ok,i,tmp;
-long cnt,rate,t1,t2;
-unsigned short mv;
-char s[80];
-
- ok = quit = false;
- player = opponent;
- ShowSidetomove();
- ft = 0;
- if (hint > 0 && !easy && Book == NULL)
- {
- fflush(stdout);
- time0 = time((long *)0);
- algbr(hint>>8,hint & 0xFF,false);
- strcpy(s,mvstr1);
- tmp = epsquare;
- if (VerifyMove(s,1,&mv))
- {
- PromptForMove();
- SelectMove(computer,2);
- VerifyMove(mvstr1,2,&mv);
- if (Sdepth > 0) Sdepth--;
- }
- ft = time((time_t *)0) - time0;
- epsquare = tmp;
- }
-
- signal(SIGINT,Die); signal(SIGQUIT,Die);
- while (!(ok || quit))
- {
- PromptForMove();
- scanz("%s",s);
- player = opponent;
- ok = VerifyMove(s,0,&mv);
- if (ok && mv != hint)
- {
- Sdepth = 0;
- ft = 0;
- }
-
- if (strcmp(s,"bd") == 0)
- {
- ClrScreen();
- UpdateDisplay(0,0,1,0);
- }
- if (strcmp(s,"quit") == 0) quit = true;
- if (strcmp(s,"post") == 0) post = !post;
- if (strcmp(s,"edit") == 0) EditBoard();
- if (strcmp(s,"go") == 0) ok = true;
- if (strcmp(s,"help") == 0) help();
- if (strcmp(s,"force") == 0) force = !force;
- if (strcmp(s,"book") == 0) Book = NULL;
- if (strcmp(s,"undo") == 0 && GameCnt >= 0) Undo();
- if (strcmp(s,"new") == 0) NewGame();
- if (strcmp(s,"list") == 0) ListGame();
- if (strcmp(s,"level") == 0) SelectLevel();
- if (strcmp(s,"hash") == 0) hashflag = !hashflag;
- if (strcmp(s,"beep") == 0) beep = !beep;
- if (strcmp(s,"Awindow") == 0) ChangeAlphaWindow();
- if (strcmp(s,"Bwindow") == 0) ChangeBetaWindow();
- if (strcmp(s,"hint") == 0) GiveHint();
- if (strcmp(s,"both") == 0)
- {
- bothsides = !bothsides;
- Sdepth = 0;
- SelectMove(opponent,1);
- ok = true;
- }
- if (strcmp(s,"reverse") == 0)
- {
- reverse = !reverse;
- ClrScreen();
- UpdateDisplay(0,0,1,0);
- }
- if (strcmp(s,"switch") == 0)
- {
- computer = otherside[computer];
- opponent = otherside[opponent];
- force = false;
- Sdepth = 0;
- ok = true;
- }
- if (strcmp(s,"white") == 0)
- {
- computer = white; opponent = black;
- ok = true; force = false;
- Sdepth = 0;
- }
- if (strcmp(s,"black") == 0)
- {
- computer = black; opponent = white;
- ok = true; force = false;
- Sdepth = 0;
- }
- if (strcmp(s,"remove") == 0 && GameCnt >= 1)
- {
- Undo(); Undo();
- }
- if (strcmp(s,"get") == 0) GetGame();
- if (strcmp(s,"save") == 0) SaveGame();
- if (strcmp(s,"depth") == 0) ChangeSearchDepth();
- if (strcmp(s,"random") == 0) dither = 6;
- if (strcmp(s,"easy") == 0) easy = !easy;
- if (strcmp(s,"contempt") == 0) SetContempt();
- if (strcmp(s,"xwndw") == 0) ChangeXwindow();
- if (strcmp(s,"test") == 0)
- {
- t1 = time(0);
- cnt = 0;
- for (i = 0; i < 10000; i++)
- {
- MoveList(opponent,2);
- cnt += TrPnt[3] - TrPnt[2];
- }
- t2 = time(0);
- rate = cnt / (t2-t1);
- gotoXY(50,24);
- printz("cnt= %ld rate= %ld",cnt,rate);
- ClrEoln();
- }
- if (strcmp(s,"p") == 0) ShowPostnValues();
- if (strcmp(s,"debug") == 0) DoDebug();
- }
-
- ClearMessage();
- ElapsedTime(1);
- if (force)
- {
- computer = opponent; opponent = otherside[computer];
- }
- (void) times(&tmbuf1);
- signal(SIGINT,TerminateSearch); signal(SIGQUIT,TerminateSearch);
-}
-
-
-EditBoard()
-
-/*
- Set up a board position. Pieces are entered by typing the piece
- followed by the location. For example, Nf3 will place a knight on
- square f3.
-*/
-
-{
-short a,r,c,sq;
-char s[80];
-
- ClrScreen();
- UpdateDisplay(0,0,1,0);
- gotoXY(50,2); printz(". Exit to main");
- gotoXY(50,3); printz("# Clear board");
- gotoXY(49,5); printz("Enter piece & location: ");
- a = white;
- do
- {
- gotoXY(73,5); ClrEoln(); scanz("%s",s);
- if (s[0] == '#')
- {
- for (sq = 0; sq < 64; sq++)
- {
- board[sq] = no_piece; color[sq] = neutral;
- }
- UpdateDisplay(0,0,1,0);
- }
- if (s[0] == 'c' || s[0] == 'C') a = otherside[a];
- c = s[1]-'a'; r = s[2]-'1';
- if ((c >= 0) && (c < 8) && (r >= 0) && (r < 8))
- {
- sq = locn[r][c];
- color[sq] = a;
- if (s[0] == 'p') board[sq] = pawn;
- else if (s[0] == 'n') board[sq] = knight;
- else if (s[0] == 'b') board[sq] = bishop;
- else if (s[0] == 'r') board[sq] = rook;
- else if (s[0] == 'q') board[sq] = queen;
- else if (s[0] == 'k') board[sq] = king;
- else { board[sq] = no_piece; color[sq] = neutral; }
- DrawPiece(sq);
- }
- }
- while (s[0] != '.');
- if (board[4] != king) kingmoved[white] = 10;
- if (board[60] != king) kingmoved[black] = 10;
- GameCnt = -1; Game50 = 0; Sdepth = 0;
- InitializeStats();
- ClrScreen();
- UpdateDisplay(0,0,1,0);
-}
-
-
-help()
-{
- ClrScreen();
- gotoXY(28,1); printz("CHESS command summary");
- gotoXY(1,3); printz("g1f3 move from g1 to f3");
- gotoXY(1,4); printz("nf3 move knight to f3");
- gotoXY(1,5); printz("o-o castle king side");
- gotoXY(1,6); printz("o-o-o castle queen side");
- gotoXY(1,7); printz("edit edit board");
- gotoXY(1,8); printz("switch sides with computer");
- gotoXY(1,9); printz("white computer plays white");
- gotoXY(1,10); printz("black computer plays black");
- gotoXY(1,11); printz("reverse board display");
- gotoXY(1,12); printz("both computer match");
- gotoXY(1,13); printz("random randomize play");
- gotoXY(1,14); printz("undo undo last move");
- gotoXY(42,3); printz("level change level");
- gotoXY(42,4); printz("depth set search depth");
- gotoXY(42,5); printz("post principle variation");
- gotoXY(42,6); printz("hint suggest a move");
- gotoXY(42,7); printz("bd redraw board");
- gotoXY(42,8); printz("force enter game moves");
- gotoXY(42,9); printz("list game to chess.lst");
- gotoXY(42,10); printz("save game to file");
- gotoXY(42,11); printz("get game from file");
- gotoXY(42,12); printz("new start new game");
- gotoXY(42,13); printz("quit exit CHESS");
- gotoXY(10,21); printz("Computer: ");
- if (computer == white) printz("WHITE"); else printz("BLACK");
- gotoXY(10,22); printz("Opponent: ");
- if (opponent == white) printz("WHITE"); else printz("BLACK");
- gotoXY(10,23); printz("Level: %ld",Level," sec.");
- gotoXY(10,24); printz("Easy mode: ");
- if (easy) printz("ON"); else printz("OFF");
- gotoXY(40,21); printz("Depth: %d",MaxSearchDepth);
- gotoXY(40,22); printz("Random: ");
- if (dither) printz("ON"); else printz("OFF");
- gotoXY(40,23); printz("Transposition table: ");
- if (hashflag) printz("ON"); else printz("OFF");
- refresh();
- while (getchar() != 27);
- ClrScreen();
- UpdateDisplay(0,0,1,0);
-}
-
-
-ShowDepth(ch)
-char ch;
-{
- gotoXY(50,4); printz("Depth= %d%c ",Sdepth,ch); ClrEoln();
-}
-
-
-ShowResults(score,bstline,ch)
-short score;
-unsigned short bstline[];
-char ch;
-{
-short d,e,ply;
- if (post && player == computer)
- {
- e = lpost;
- gotoXY(50,5); printz("Score= %d",score); ClrEoln();
- d = 8; gotoXY(50,d); ClrEoln();
- for (ply = 1; bstline[ply] > 0; ply++)
- {
- algbr(bstline[ply] >> 8,bstline[ply] & 0xFF,false);
- if (ply == 5 || ply == 9 || ply == 13 || ply == 17)
- {
- gotoXY(50,++d); ClrEoln();
- }
- printz("%5s ",mvstr1);
- }
- ClrEoln();
- lpost = d;
- while (++d <= e)
- {
- gotoXY(50,d); ClrEoln();
- }
- }
-}
-
-
-SearchStartStuff(side)
-short side;
-{
-short i;
- signal(SIGINT,TerminateSearch); signal(SIGQUIT,TerminateSearch);
- if (player == computer)
- for (i = 5; i < 14; i++)
- {
- gotoXY(50,i); ClrEoln();
- }
-}
-
-
-OutputMove()
-{
- if (root->flags & epmask) UpdateDisplay(0,0,1,0);
- else UpdateDisplay(root->f,root->t,0,root->flags & cstlmask);
- gotoXY(50,17); printz("My move is: %s",mvstr1);
- if (beep) putchar(7);
- ClrEoln();
-
- gotoXY(50,24);
- if (root->flags & draw) printz("Draw game!");
- else if (root->score == -9999) printz("opponent mates!");
- else if (root->score == 9998) printz("computer mates!");
- else if (root->score < -9000) printz("opponent will soon mate!");
- else if (root->score > 9000) printz("computer will soon mate!");
- ClrEoln();
-
- if (post)
- {
- gotoXY(50,22); printz("Nodes= %6ld",NodeCnt); ClrEoln();
- gotoXY(50,23); printz("Nodes/Sec= %4ld",evrate); ClrEoln();
- }
-}
-
-
-ElapsedTime(iop)
-
-/*
- Determine the time that has passed since the search was started. If
- the elapsed time exceeds the target (ResponseTime+ExtraTime) then set
- timeout to true which will terminate the search.
-*/
-
-short iop;
-{
- et = time((time_t *)0) - time0;
- if (et < 0) et = 0;
- ETnodes += 50;
- if (et > et0 || iop == 1)
- {
- if (et > ResponseTime+ExtraTime && Sdepth > 1) timeout = true;
- et0 = et;
- if (iop == 1)
- {
- time0 = time((time_t *)0); et0 = 0;
- }
- (void) times(&tmbuf2);
- cputimer = 100*(tmbuf2.tms_utime - tmbuf1.tms_utime) / HZ;
- if (cputimer > 0) evrate = (100*NodeCnt)/(cputimer+100*ft);
- else evrate = 0;
- ETnodes = NodeCnt + 50;
- UpdateClocks();
- }
-}
-
-
-UpdateClocks()
-{
-short m,s;
- m = et/60; s = (et - 60*m);
- if (TCflag)
- {
- m = (TimeControl.clock[player] - et) / 60;
- s = TimeControl.clock[player] - et - 60*m;
- }
- if (m < 0) m = 0;
- if (s < 0) s = 0;
- if (player == white)
- if (reverse) gotoXY(20,2); else gotoXY(20,23);
- else
- if (reverse) gotoXY(20,23); else gotoXY(20,2);
- printz("%d:%2d ",m,s);
- if (post)
- {
- gotoXY(50,22); printz("Nodes= %6ld",NodeCnt);
- gotoXY(50,23); printz("Nodes/Sec= %4ld",evrate);
- }
- refresh();
-}
-
-
-
-SetTimeControl()
-{
- if (TCflag)
- {
- TimeControl.moves[white] = TimeControl.moves[black] = TCmoves;
- TimeControl.clock[white] = TimeControl.clock[black] = 60*(long)TCminutes;
- }
- else
- {
- TimeControl.moves[white] = TimeControl.moves[black] = 0;
- TimeControl.clock[white] = TimeControl.clock[black] = 0;
- Level = 60*(long)TCminutes;
- }
- et = 0;
- ElapsedTime(1);
-}
-
-
-gotoXY(x,y)
-short x,y;
-{
- move(y-1,x-1);
-}
-
-
-ClrScreen()
-{
- clear(); refresh();
-}
-
-
-ClrEoln()
-{
- clrtoeol(); refresh();
-}
-
-
-DrawPiece(sq)
-short sq;
-{
-short r,c; char x;
- if (reverse) r = 7-row[sq]; else r = row[sq];
- if (reverse) c = 7-column[sq]; else c = column[sq];
- if (color[sq] == black) x = '*'; else x = ' ';
- gotoXY(5+5*c,5+2*(7-r)); printz("%c%c ",x,pxx[board[sq]]);
-}
-
-
-UpdateDisplay(f,t,flag,iscastle)
-short f,t,flag,iscastle;
-{
-short i,l,z;
- if (flag)
- {
- gotoXY(56,2); printz("CHESS");
- i = 3;
- gotoXY(3,++i);
- printz("|----|----|----|----|----|----|----|----|");
- while (i<19)
- {
- gotoXY(1,++i);
- if (reverse) z = (i/2)-1; else z = 10-(i/2);
- printz("%d | | | | | | | | |",z);
- gotoXY(3,++i);
- if (i < 19)
- printz("+----+----+----+----+----+----+----+----+");
- }
- printz("|----|----|----|----|----|----|----|----|");
- gotoXY(3,21);
- if (reverse) printz(" h g f e d c b a");
- else printz(" a b c d e f g h");
- if (reverse) gotoXY(5,23); else gotoXY(5,2);
- if (computer == black) printz("Computer"); else printz("Human ");
- if (reverse) gotoXY(5,2); else gotoXY(5,23);
- if (computer == white) printz("Computer"); else printz("Human ");
- for (l = 0; l < 64; l++) DrawPiece(l);
- }
- else
- {
- DrawPiece(f); DrawPiece(t);
- if (iscastle)
- if (t > f)
- { DrawPiece(f+3); DrawPiece(t-1); }
- else
- { DrawPiece(f-4); DrawPiece(t+1); }
- }
- refresh();
-}
-
-
-GetOpenings()
-
-/*
- Read in the Opening Book file and parse the algebraic notation for a
- move into an unsigned integer format indicating the from and to
- square. Create a linked list of opening lines of play, with
- entry->next pointing to the next line and entry->move pointing to a
- chunk of memory containing the moves. More Opening lines of up to 256
- half moves may be added to gnuchess.book.
-*/
-
-{
-FILE *fd;
-int c,i,j,side;
-struct BookEntry *entry;
-unsigned short mv,*mp,tmp[100];
-
- if ((fd = fopen(_PATH_CHESSBOOK,"r")) != NULL)
- {
- Book = NULL;
- i = 0; side = white;
- while ((c = parse(fd,&mv,side)) >= 0)
- if (c == 1)
- {
- tmp[++i] = mv;
- side = otherside[side];
- }
- else if (c == 0 && i > 0)
- {
- entry = (struct BookEntry *)malloc(sizeof(struct BookEntry));
- mp = (unsigned short *)malloc((i+1)*sizeof(unsigned short));
- entry->mv = mp;
- entry->next = Book;
- Book = entry;
- for (j = 1; j <= i; j++) *(mp++) = tmp[j];
- *mp = 0;
- i = 0; side = white;
- }
- fclose(fd);
- }
- else
- {
- fprintf(stderr, "\nchess: can't read %s.\n", _PATH_CHESSBOOK);
- exit(1);
- }
-}
-
-
-int parse(fd,mv,side)
-FILE *fd;
-unsigned short *mv;
-short side;
-{
-int c,i,r1,r2,c1,c2;
-char s[100];
- while ((c = getc(fd)) == ' ');
- i = 0; s[0] = c;
- while (c != ' ' && c != '\n' && c != EOF) s[++i] = c = getc(fd);
- s[++i] = '\0';
- if (c == EOF) return(-1);
- if (s[0] == '!' || i < 3)
- {
- while (c != '\n' && c != EOF) c = getc(fd);
- return(0);
- }
- if (s[4] == 'o')
- if (side == black) *mv = 0x3C3A; else *mv = 0x0402;
- else if (s[0] == 'o')
- if (side == black) *mv = 0x3C3E; else *mv = 0x0406;
- else
- {
- c1 = s[0] - 'a'; r1 = s[1] - '1';
- c2 = s[2] - 'a'; r2 = s[3] - '1';
- *mv = (locn[r1][c1]<<8) + locn[r2][c2];
- }
- return(1);
-}
-
-
-GetGame()
-{
-FILE *fd;
-char fname[40];
-int c;
-short sq;
-unsigned short m;
-
- ShowMessage("File name: ");
- scanz("%s",fname);
- if (fname[0] == '\0') strcpy(fname,"chess.000");
- if ((fd = fopen(fname,"r")) != NULL)
- {
- fscanf(fd,"%hd%hd%hd",&computer,&opponent,&Game50);
- fscanf(fd,"%hd%hd%hd%hd",
- &castld[white],&castld[black],
- &kingmoved[white],&kingmoved[black]);
- fscanf(fd,"%hd%hd",&TCflag,&OperatorTime);
- fscanf(fd,"%ld%ld%hd%hd",
- &TimeControl.clock[white],&TimeControl.clock[black],
- &TimeControl.moves[white],&TimeControl.moves[black]);
- for (sq = 0; sq < 64; sq++)
- {
- fscanf(fd,"%hd",&m);
- board[sq] = (m >> 8); color[sq] = (m & 0xFF);
- if (color[sq] == 0) color[sq] = neutral; else --color[sq];
- }
- GameCnt = -1; c = '?';
- while (c != EOF)
- {
- ++GameCnt;
- c = fscanf(fd,"%hd%hd%hd%ld%hd%hd%hd",&GameList[GameCnt].gmove,
- &GameList[GameCnt].score,&GameList[GameCnt].depth,
- &GameList[GameCnt].nodes,&GameList[GameCnt].time,
- &GameList[GameCnt].piece,&GameList[GameCnt].color);
- if (GameList[GameCnt].color == 0) GameList[GameCnt].color = neutral;
- else --GameList[GameCnt].color;
- }
- GameCnt--;
- if (TimeControl.clock[white] > 0) TCflag = true;
- computer--; opponent--;
- }
- fclose(fd);
- InitializeStats();
- UpdateDisplay(0,0,1,0);
- Sdepth = 0;
-}
-
-
-SaveGame()
-{
-FILE *fd;
-char fname[40];
-short sq,i,c;
-
- ShowMessage("File name: ");
- scanz("%s",fname);
-
- if (fname[0] == '\0' || access(fname,W_OK) == -1) strcpy(fname,"chess.000");
- fd = fopen(fname,"w");
- fprintf(fd,"%d %d %d\n",computer+1,opponent+1,Game50);
- fprintf(fd,"%d %d %d %d\n",
- castld[white],castld[black],kingmoved[white],kingmoved[black]);
- fprintf(fd,"%d %d\n",TCflag,OperatorTime);
- fprintf(fd,"%ld %ld %d %d\n",
- TimeControl.clock[white],TimeControl.clock[black],
- TimeControl.moves[white],TimeControl.moves[black]);
- for (sq = 0; sq < 64; sq++)
- {
- if (color[sq] == neutral) c = 0; else c = color[sq]+1;
- fprintf(fd,"%d\n",256*board[sq] + c);
- }
- for (i = 0; i <= GameCnt; i++)
- {
- if (GameList[i].color == neutral) c = 0;
- else c = GameList[i].color + 1;
- fprintf(fd,"%d %d %d %ld %d %d %d\n",
- GameList[i].gmove,GameList[i].score,GameList[i].depth,
- GameList[i].nodes,GameList[i].time,
- GameList[i].piece,c);
- }
- fclose(fd);
-}
-
-
-ListGame()
-{
-FILE *fd;
-short i,f,t;
- fd = fopen("chess.lst","w");
- fprintf(fd,"\n");
- fprintf(fd," score depth nodes time ");
- fprintf(fd," score depth nodes time\n");
- for (i = 0; i <= GameCnt; i++)
- {
- f = GameList[i].gmove>>8; t = (GameList[i].gmove & 0xFF);
- algbr(f,t,false);
- if ((i % 2) == 0) fprintf(fd,"\n"); else fprintf(fd," ");
- fprintf(fd,"%5s %5d %2d %6ld %5d",mvstr1,
- GameList[i].score,GameList[i].depth,
- GameList[i].nodes,GameList[i].time);
- }
- fprintf(fd,"\n\n");
- fclose(fd);
-}
-
-
-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();
-}
-
-
-ShowMessage(s)
-char *s;
-{
- gotoXY(50,24); printz("%s",s); ClrEoln();
-}
-
-ClearMessage()
-{
- gotoXY(50,24); ClrEoln();
-}
-
-ShowSidetomove()
-{
- gotoXY(50,14);
- if (player == white) printz("%2d: WHITE",1+(GameCnt+1)/2);
- else printz("%2d: BLACK",1+(GameCnt+1)/2);
- ClrEoln();
-}
-
-PromptForMove()
-{
- gotoXY(50,19); printz("Your move is? "); ClrEoln();
-}
-
-ShowCurrentMove(pnt,f,t)
-short pnt,f,t;
-{
- algbr(f,t,false);
- gotoXY(50,7); printz("(%2d) %4s",pnt,mvstr1);
-}
-
-ChangeAlphaWindow()
-{
- ShowMessage("window: ");
- scanz("%hd",&Awindow);
-}
-
-ChangeBetaWindow()
-{
- ShowMessage("window: ");
- scanz("%hd",&Bwindow);
-}
-
-GiveHint()
-{
-char s[40];
- algbr((short)(hint>>8),(short)(hint & 0xFF),false);
- strcpy(s,"try ");
- strcat(s,mvstr1);
- ShowMessage(s);
-}
-
-ChangeSearchDepth()
-{
- ShowMessage("depth= ");
- scanz("%hd",&MaxSearchDepth);
-}
-
-SetContempt()
-{
- ShowMessage("contempt= ");
- scanz("%hd",&contempt);
-}
-
-ChangeXwindow()
-{
- ShowMessage("xwndw= ");
- scanz("%hd",&xwndw);
-}
-
-
-SelectLevel()
-{
- ClrScreen();
- gotoXY(32,2); printz("CHESS");
- gotoXY(20,4); printz(" 1. 60 moves in 5 minutes");
- gotoXY(20,5); printz(" 2. 60 moves in 15 minutes");
- gotoXY(20,6); printz(" 3. 60 moves in 30 minutes");
- gotoXY(20,7); printz(" 4. 40 moves in 30 minutes");
- gotoXY(20,8); printz(" 5. 40 moves in 60 minutes");
- gotoXY(20,9); printz(" 6. 40 moves in 120 minutes");
- gotoXY(20,10); printz(" 7. 40 moves in 240 minutes");
- gotoXY(20,11); printz(" 8. 1 move in 15 minutes");
- gotoXY(20,12); printz(" 9. 1 move in 60 minutes");
- gotoXY(20,13); printz("10. 1 move in 600 minutes");
-
- OperatorTime = 0; TCmoves = 60; TCminutes = 5;
-
- gotoXY(20,17); printz("Enter Level: ");
- refresh();
- scanz("%ld",&Level);
- switch (Level)
- {
- case 1 : TCmoves = 60; TCminutes = 5; break;
- case 2 : TCmoves = 60; TCminutes = 15; break;
- case 3 : TCmoves = 60; TCminutes = 30; break;
- case 4 : TCmoves = 40; TCminutes = 30; break;
- case 5 : TCmoves = 40; TCminutes = 60; break;
- case 6 : TCmoves = 40; TCminutes = 120; break;
- case 7 : TCmoves = 40; TCminutes = 240; break;
- case 8 : TCmoves = 1; TCminutes = 15; break;
- case 9 : TCmoves = 1; TCminutes = 60; break;
- case 10 : TCmoves = 1; TCminutes = 600; break;
- }
-
- TCflag = (TCmoves > 1);
- SetTimeControl();
- ClrScreen();
- UpdateDisplay(0,0,1,0);
-}
-
-
-ShowPostnValues()
-{
-short i,r,c;
- ExaminePosition();
- for (i = 0; i < 64; i++)
- {
- if (reverse) r = 7-row[i]; else r = row[i];
- if (reverse) c = 7-column[i]; else c = column[i];
- gotoXY(4+5*c,5+2*(7-r));
- c1 = color[i]; c2 = otherside[c1];
- PC1 = PawnCnt[c1]; PC2 = PawnCnt[c2];
- atk1 = atak[c1]; atk2 = atak[c2];
- if (color[i] == neutral) printz(" ");
- else printz("%3d ",SqValue(i,opponent));
- }
- ScorePosition(opponent,&i);
- gotoXY(50,24);
- printz("Score= %d",i); ClrEoln();
-}
-
-
-DoDebug()
-{
-short k,p,i,r,c,tp,tc;
-char s[40];
- ExaminePosition();
- ShowMessage("Enter piece: ");
- scanz("%s",s);
- if (s[0] == 'w') k = white; else k = black;
- if (s[1] == 'p') p = pawn;
- else if (s[1] == 'n') p = knight;
- else if (s[1] == 'b') p = bishop;
- else if (s[1] == 'r') p = rook;
- else if (s[1] == 'q') p = queen;
- else if (s[1] == 'k') p = king;
- else p = no_piece;
- for (i = 0; i < 64; i++)
- {
- if (reverse) r = 7-row[i]; else r = row[i];
- if (reverse) c = 7-column[i]; else c = column[i];
- gotoXY(4+5*c,5+2*(7-r));
- tp = board[i]; tc = color[i];
- board[i] = p; color[i] = k;
- c1 = k; c2 = otherside[c1];
- PC1 = PawnCnt[c1]; PC2 = PawnCnt[c2];
- atk1 = atak[c1]; atk2 = atak[c2];
- printz("%3d ",SqValue(i,opponent));
- board[i] = tp; color[i] = tc;
- }
- ScorePosition(opponent,&i);
- gotoXY(50,24);
- printz("Score= %d",i); ClrEoln();
-}
OpenPOWER on IntegriCloud