mikew@wyse.wyse.com (Mike Wexler) (12/06/88)
Submitted-by: aperez@blazer.prime.com (Arturo Perez Ext.) Posting-number: Volume 2, Issue 30 Archive-name: xchess/part03 #! /bin/sh # This is a shell archive. Remove anything before this line, then unpack # it by saving it into a file and typing "sh file". To overwrite existing # files, type "sh file -c". You can also feed this as standard input via # unshar, or by typing "sh <file", e.g.. If this archive is complete, you # will see the following message at the end: # "End of archive 3 (of 6)." # Contents: COPYING button.c clock.c jail.c std.c valid.c xchess.1 # xchess.h xchess.icon # Wrapped by mikew@wyse on Mon Dec 5 18:32:48 1988 PATH=/bin:/usr/bin:/usr/ucb ; export PATH if test -f 'COPYING' -a "${1}" != "-c" ; then echo shar: Will not clobber existing file \"'COPYING'\" else echo shar: Extracting \"'COPYING'\" \(6476 characters\) sed "s/^X//" >'COPYING' <<'END_OF_FILE' X GNU X-CHESS GENERAL PUBLIC LICENSE X X Copyright (C) 1986 Free Software Foundation, Inc. X Everyone is permitted to copy and distribute verbatim copies X of this license, but changing it is not allowed. X X The license agreements of most software companies keep you at the Xmercy of those companies. By contrast, our general public license is Xintended to give everyone the right to share GNU X-Chess. To make Xsure that you get the rights we want you to have, we need to make Xrestrictions that forbid anyone to deny you these rights or to ask you Xto surrender the rights. Hence this license agreement. X X Specifically, we want to make sure that you have the right to give Xaway copies of GNU X-Chess, that you receive source code or else can get it Xif you want it, that you can change GNU X-Chess or use pieces of it in new Xfree programs, and that you know you can do these things. X X To make sure that everyone has such rights, we have to forbid you to Xdeprive anyone else of these rights. For example, if you distribute Xcopies of GNU X-Chess, you must give the recipients all the rights that you Xhave. You must make sure that they, too, receive or can get the Xsource code. And you must tell them their rights. X X Also, for our own protection, we must make certain that everyone Xfinds out that there is no warranty for GNU X-Chess. If GNU X-Chess is Xmodified by someone else and passed on, we want its recipients to know Xthat what they have is not what we distributed, so that any problems Xintroduced by others will not reflect on our reputation. X X Therefore the Free Software Foundation, Inc. makes the following Xterms which say what you must do to be allowed to distribute or change XGNU X-Chess. X X COPYING POLICIES X X 1. You may copy and distribute verbatim copies of GNU X-Chess source Xcode as you receive it, in any medium, provided that you conspicuously Xand appropriately publish on each file a valid copyright notice X"Copyright (C) 1986 Free Software Foundation, Inc.", containing the Xyear of last change for the file in question; keep intact the notices Xon all files that refer to this License Agreement and to the absence Xof any warranty; and give any other recipients of the GNU X-Chess Xprogram a copy of this License Agreement along with the program. X X 2. You may modify your copy or copies of GNU X-Chess source code or Xany portion of it, and copy and distribute such modifications under Xthe terms of Paragraph 1 above, provided that you also do the following: X X a) cause the modified files to carry prominent notices stating X who last changed such files and the date of any change; and X X b) cause the whole of any work that you distribute or publish, X that in whole or in part contains or is a derivative of GNU X-Chess X or any part thereof, to be freely distributed X and licensed to all third parties on terms identical to those X contained in this License Agreement (except that you may choose X to grant more extensive warranty protection to third parties, X at your option). X X c) if the modified program serves as a text editor, cause it X when started running in the simplest and usual way, to print X an announcement including a valid copyright notice ("Copyright X (C)", the year of authorship, and all copyright owners' names), X saying that there is no warranty (or else, saying that you provide X a warranty) and that users may redistribute the program under X these conditions, and telling the user how to view a copy of X this License Agreement. X X 3. You may copy and distribute GNU X-Chess or any portion of it in Xcompiled, executable or object code form under the terms of Paragraphs X1 and 2 above provided that you do the following: X X a) cause each such copy of GNU X-Chess to be accompanied by the X corresponding machine-readable source code; or X X b) cause each such copy of GNU X-Chess to be accompanied by a X written offer, with no time limit, to give any third party X free (except for a nominal shipping charge) machine readable X copy of the corresponding source code; or X X c) in the case of a recipient of GNU X-Chess in compiled, executable X or object code form (without the corresponding source code) you X shall cause copies you distribute to be accompanied by a copy X of the written offer of source code which you received along X with the copy of GNU X-Chess. X X 4. You may not copy, sublicense, distribute or transfer GNU X-Chess Xexcept as expressly provided under this License Agreement. Any attempt Xotherwise to copy, sublicense, distribute or transfer GNU X-Chess is void and Xyour rights to use GNU X-Chess under this License agreement shall be Xautomatically terminated. However, parties who have received computer Xsoftware programs from you with this License Agreement will not have Xtheir licenses terminated so long as such parties remain in full compliance. X XYour comments and suggestions about our licensing policies and our Xsoftware are welcome! Please contact the Free Software Foundation, Inc., X1000 Mass Ave, Cambridge, MA 02138, or call (617) 876-3296. X X NO WARRANTY X X BECAUSE GNU X-CHESS IS LICENSED FREE OF CHARGE, WE PROVIDE ABSOLUTELY XNO WARRANTY, TO THE EXTENT PERMITTED BY APPLICABLE STATE LAW. EXCEPT XWHEN OTHERWISE STATED IN WRITING, FREE SOFTWARE FOUNDATION, INC, XAND/OR OTHER PARTIES PROVIDE GNU X-CHESS "AS IS" WITHOUT WARRANTY OF ANY XKIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE XIMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR XPURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE XPROGRAM IS WITH YOU. SHOULD THE GNU X-CHESS PROGRAM PROVE DEFECTIVE, XYOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. X X IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW WILL FREE SOFTWARE XFOUNDATION, INC., AND/OR ANY OTHER PARTY WHO MAY MODIFY AND XREDISTRIBUTE GNU X-CHESS AS PERMITTED ABOVE, BE LIABLE TO YOU FOR XDAMAGES, INCLUDING ANY LOST PROFITS, LOST MONIES, OR OTHER SPECIAL, XINCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR XINABILITY TO USE (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA XBEING RENDERED INACCURATE OR LOSSES SUSTAINED BY THIRD PARTIES OR A XFAILURE OF THE PROGRAM TO OPERATE WITH PROGRAMS NOT DISTRIBUTED BY XFREE SOFTWARE FOUNDATION, INC.) THE PROGRAM, EVEN IF YOU HAVE BEEN XADVISED OF THE POSSIBILITY OF SUCH DAMAGES, OR FOR ANY CLAIM BY ANY XOTHER PARTY. X====================================================================== END_OF_FILE if test 6476 -ne `wc -c <'COPYING'`; then echo shar: \"'COPYING'\" unpacked with wrong size! fi # end of 'COPYING' fi if test -f 'button.c' -a "${1}" != "-c" ; then echo shar: Will not clobber existing file \"'button.c'\" else echo shar: Extracting \"'button.c'\" \(9108 characters\) sed "s/^X//" >'button.c' <<'END_OF_FILE' X/* This file contains code for X-CHESS. X Copyright (C) 1986 Free Software Foundation, Inc. X XThis file is part of X-CHESS. X XX-CHESS is distributed in the hope that it will be useful, Xbut WITHOUT ANY WARRANTY. No author or distributor Xaccepts responsibility to anyone for the consequences of using it Xor for whether it serves any particular purpose or works at all, Xunless he says so in writing. Refer to the X-CHESS General Public XLicense for full details. X XEveryone is granted permission to copy, modify and redistribute XX-CHESS, but only under the conditions described in the XX-CHESS General Public License. A copy of this license is Xsupposed to have been given to you along with X-CHESS so you Xcan know your rights and responsibilities. It should be in a Xfile named COPYING. Among other things, the copyright notice Xand this notice must be preserved on all copies. */ X X X/* RCS Info: $Revision: 1.4 $ on $Date: 86/11/26 12:09:41 $ X * $Source: /users/faustus/xchess/RCS/button.c,v $ X * Copyright (c) 1986 Wayne A. Christopher, U. C. Berkeley CAD Group X * Permission is granted to do anything with this code except sell it X * or remove this message. X * X * Do stuff with the buttons. X * The configuration we're using is: Draw Back Pause X * Resign Fwd Flip X * Reset Save Easy (Switch) X */ X X#include "xchess.h" X Xtypedef enum choice { NOCHOICE, DRAW, RESIGN, REPLAY, SWITCH, FORE, SAVE, X STOP, FLIP, RESTART, EASY } choice; X Xstatic struct but { X char *label; X int x, y; X int width, height; X choice which; X} buts[] = { X { "Draw", 0, 20, 108, 29, DRAW } , X { "Back", 109, 20, 108, 29, REPLAY } , X { "Pause", 219, 20, 108, 29, STOP } , X { "Resign", 0, 50, 108, 29, RESIGN } , X { "Fwd", 109, 50, 108, 29, FORE } , X { "Flip", 219, 50, 108, 29, FLIP } , X { "Reset", 0, 80, 108, 29, RESTART } , X { "Save", 109, 80, 108, 29, SAVE } , X#define EASY_OFFSET 8 X { "Switch", 219, 80, 108, 29, SWITCH } X/* { "NoEasy", 219, 80, 108, 29, EASY }*/ X} ; Xstatic int easy = 1; X Xvoid Xbutton_draw(win) X windata *win; X{ X int i, x, numbuts = sizeof (buts) / sizeof (struct but); X X XSetState(win->display, DefaultGC(win->display, 0), X win->border.pixel, WhitePixel(win->display, 0), X GXcopy, AllPlanes); X XSetLineAttributes(win->display, DefaultGC(win->display, 0), X BORDER_WIDTH, LineSolid, CapButt, X JoinMiter); X X XDrawLine(win->display, win->buttonwin, X DefaultGC(win->display, 0), X 0, 29, BUTTON_WIDTH, 29); X XDrawLine(win->display, win->buttonwin, X DefaultGC(win->display, 0), X 0, 60, BUTTON_WIDTH, 60); X XDrawLine(win->display, win->buttonwin, X DefaultGC(win->display, 0), X 108, 0, 108, BUTTON_HEIGHT); X XDrawLine(win->display, win->buttonwin, X DefaultGC(win->display, 0), X 219, 0, 219, BUTTON_HEIGHT); X X XSetFont(win->display, DefaultGC(win->display, 0), win->large->fid); X XSetForeground(win->display, DefaultGC(win->display, 0), X win->textcolor.pixel); X XSetBackground(win->display, DefaultGC(win->display, 0), X win->textback.pixel); X X for (i = 0; i < numbuts; i++) { X x = (buts[i].width - X XTextWidth(win->large, buts[i].label, X strlen(buts[i].label))) / 2; X X XDrawImageString(win->display, win->buttonwin, X DefaultGC(win->display, 0), X buts[i].x + x, buts[i].y, buts[i].label, X strlen(buts[i].label)); X } X return; X} X Xvoid Xbutton_service(win, event) X windata *win; X XEvent *event; X{ X XKeyEvent *ev = &event->xkey; X choice c; X int i, numbuts = sizeof (buts) / sizeof (struct but); X char *s; X X ev->y += 15; X for (i = 0; i < numbuts; i++) X if ((ev->x >= buts[i].x) && (ev->x <= buts[i].x + X buts[i].width) && (ev->y >= buts[i].y) && X (ev->y <= buts[i].y + buts[i].height)) { X c = buts[i].which; X break; X } X if ((i == numbuts) || (c == NOCHOICE)) { X message_add(win, "Bad choice.\n", true); X return; X } X X if (loading_flag && (c != STOP)) { X message_add(win, "You can only use PAUSE now\n", true); X return; X } X X switch (c) { X case DRAW: X if (!oneboard) { X message_add(win, "Just a sec...\n", false); X if (!pop_question(((win == win1) ? win2 : win1), X"The other player wants\nto call the game a draw.\nDo you agree?\n")) { X message_add(win, X "The other player declines the draw\n", false); X return; X } X } X message_add(win1, "Draw agreed.\n", false); X if (!oneboard) X message_add(win2, "Draw agreed.\n", false); X cleanup("Draw agreed."); X break; X X case RESIGN: X if (!pop_question(win, "Are you sure\nyou want to resign?")) X return; X if ((oneboard && !progflag) || (nexttomove == win->color)) { X if (nexttomove == WHITE) X s = "White resigns."; X else X s = "Black resigns."; X if (oneboard) { X message_add(win, s, false); X message_add(win, "\n", false); X } else { X message_add(win1, s, false); X message_add(win, "\n", false); X message_add(win2, s, false); X message_add(win, "\n", false); X } X sleep(5); X cleanup(s); X } else { X message_add(win, "It's not your turn.\n", true); X } X break; X X case REPLAY: X if (!oneboard) { X message_add(win, "Just a sec...\n", false); X if (!pop_question(((win == win1) ? win2 : win1), X"The other player wants\nto take back his last move.\nDo you let him?\n")) { X message_add(win, X "The other player refuses...\n", false); X return; X } X } X if (!moves) { X message_add(win, "Can't back up...\n", true); X break; X } X message_add(win1, "Replaying...\n", false); X if (!oneboard) X message_add(win2, "Replaying...\n", false); X replay(); X if (progflag) X replay(); X break; X X case FORE: X if (!oneboard) { X message_add(win, "Just a sec...\n", false); X if (!pop_question(((win == win1) ? win2 : win1), X"The other player wants\nto do a 'fore'.\nIs that ok with you?\n")) { X message_add(win, X "The other player refuses...\n", false); X return; X } X } X if (!foremoves) { X message_add(win, "Can't go forward...\n", true); X break; X } X message_add(win1, "Moving forward...\n", false); X if (!oneboard) X message_add(win2, "Moving forward...\n", false); X forward(); X break; X X case SWITCH: X message_add(win, "You can't switch yet.\n", false); X break; X X case SAVE: X if (saveflag) { X message_add(win, X "Game is already being logged in file '", true); X message_add(win, record_file, true); X message_add(win, "'.\n", true); X } else { X message_add(win, "Saving game to file '", false); X message_add(win, record_file, false); X message_add(win, "'.\n", false); X record_save(); X } X break; X X case STOP: X if (loading_flag) { X loading_paused = (loading_paused ? false : true); X message_add(win, loading_paused ? X "Stopped.\nHit 'Pause' again to restart.\n" : X "Restarted.\n", false); X } else if (clock_started) { X if (!oneboard) { X message_add(win, "Just a sec...\n", false); X if (!pop_question(((win == win1) ? win2 : win1), X"The other player wants\nto stop the clock.\nDo you let him?\n")) { X message_add(win, X "The other player refuses to pause.\n", X false); X return; X } X } X message_add(win1, X "Clock stopped.\nHit 'Pause' again to restart.\n", X false); X if (!oneboard) X message_add(win2, X "Clock stopped.\nHit 'Pause' again to restart.\n", X false); X clock_started = false; X } else { X if (!oneboard) { X message_add(win, "Just a sec...\n", false); X if (!pop_question(((win == win1) ? win2 : win1), X"The other player wants\nto start the clock again.\nIs that ok?\n")) { X message_add(win, X "The other player refuses to resume.\n", X false); X return; X } X } X message_add(win1, "Clock restarted.\n", false); X if (!oneboard) X message_add(win2, "Clock restarted.\n", false); X clock_started = true; X } X break; X X case FLIP: X message_add(win, "Flipping window...\n", false); X win->flipped = win->flipped ? false : true; X win_redraw(win, (XEvent *) NULL); X break; X X case RESTART: X if (!oneboard) { X message_add(win, "Just a sec...\n", false); X if (!pop_question(((win == win1) ? win2 : win1), X"The other player wants\nto restart the game.\nDo you agree?\n")) { X message_add(win, X "The other player refuses to reset\n", false); X return; X } X } X message_add(win, "Restarting game.\n", false); X restart(); X break; X case EASY: X if (oneboard) { X int x; X if (easy) X easy = 0; X else X easy = 1; X X if (easy) X buts[EASY_OFFSET].label = " Easy "; X else X buts[EASY_OFFSET].label = "NoEasy"; X X program_easy(easy); X X x = (buts[EASY_OFFSET].width - X XTextWidth(win->large, X buts[EASY_OFFSET].label, X strlen(buts[EASY_OFFSET].label))) / 2; X X XSetFont(win->display, DefaultGC(win->display, X 0), win->large->fid); X XSetForeground(win->display, X DefaultGC(win->display, 0), X win->textcolor.pixel); X XSetBackground(win->display, X DefaultGC(win->display, 0), X win->textback.pixel); X X XDrawImageString(win->display, X win->buttonwin, X DefaultGC(win->display, 0), X buts[EASY_OFFSET].x + x, X buts[EASY_OFFSET].y, X buts[EASY_OFFSET].label, X strlen(buts[EASY_OFFSET].label)); X } X break; X } X return; X} X END_OF_FILE if test 9108 -ne `wc -c <'button.c'`; then echo shar: \"'button.c'\" unpacked with wrong size! fi # end of 'button.c' fi if test -f 'clock.c' -a "${1}" != "-c" ; then echo shar: Will not clobber existing file \"'clock.c'\" else echo shar: Extracting \"'clock.c'\" \(7232 characters\) sed "s/^X//" >'clock.c' <<'END_OF_FILE' X/* This file contains code for X-CHESS. X Copyright (C) 1986 Free Software Foundation, Inc. X XThis file is part of X-CHESS. X XX-CHESS is distributed in the hope that it will be useful, Xbut WITHOUT ANY WARRANTY. No author or distributor Xaccepts responsibility to anyone for the consequences of using it Xor for whether it serves any particular purpose or works at all, Xunless he says so in writing. Refer to the X-CHESS General Public XLicense for full details. X XEveryone is granted permission to copy, modify and redistribute XX-CHESS, but only under the conditions described in the XX-CHESS General Public License. A copy of this license is Xsupposed to have been given to you along with X-CHESS so you Xcan know your rights and responsibilities. It should be in a Xfile named COPYING. Among other things, the copyright notice Xand this notice must be preserved on all copies. */ X X X/* RCS Info: $Revision: 1.4 $ on $Date: 86/11/26 12:09:47 $ X * $Source: /users/faustus/xchess/RCS/clock.c,v $ X * Copyright (c) 1986 Wayne A. Christopher, U. C. Berkeley CAD Group X * Permission is granted to do anything with this code except sell it X * or remove this message. X * X * Do stuff with the clocks. The way things work is as follows. We call X * clock_init to draw the clocks initially, but they don't actually start X * running until we call clock_switch for the first time. X */ X X#include "xchess.h" X Xint movesperunit = 0; Xint timeunit = 0; Xbool clock_started = false; Xint whiteseconds, blackseconds; X Xstatic bool white_running = true; Xstatic long lastwhite, lastblack; Xstatic bool firstmove = true; X Xextern void dohands(), hilight(); X X#define PI 3.1415926535897932384 X Xvoid Xclock_draw(win, col) X windata *win; X color col; X{ X int i; X char buf[BSIZE]; X int x = CLOCK_WIDTH / 2, y = CLOCK_WIDTH / 2; X int xp, yp; X int rad = CLOCK_WIDTH / 2 - 10; X Window w = ((col == WHITE) ? win->wclockwin : win->bclockwin); X X /* Draw a clock face and the hands. */ X XCircle(w, x, y, rad, 0.0, 0.0, 1, 1, win->textcolor.pixel, GXcopy, X AllPlanes); X rad -= 8; X X XSetFont(win->display, DefaultGC(win->display, 0), X win->small->fid); X XSetForeground(win->display, DefaultGC(win->display, 0), X win->textcolor.pixel); X XSetBackground(win->display, DefaultGC(win->display, 0), X win->textback.pixel); X for (i = 1; i <= 12; i++) { X xp = x + rad * cos(PI * 3 / 2 + i * PI / 6) - 4; X yp = y + rad * sin(PI * 3 / 2 + i * PI / 6) - 5; X sprintf(buf, "%d", i); X XDrawString(win->display, w, DefaultGC(win->display, 0), X xp, yp, buf, strlen(buf)); X } X X dohands(win, col); X X if (white_running) { X hilight(win, WHITE, true); X hilight(win, BLACK, false); X } else { X hilight(win, WHITE, false); X hilight(win, BLACK, true); X } X return; X} X Xvoid Xclock_init(win, col) X windata *win; X color col; X{ X whiteseconds = blackseconds = 0; X clock_started = false; X firstmove = true; X clock_draw(win, col); X X return; X} X Xvoid Xclock_update() X{ X int now = time((long *) NULL); X int i; X X if (!clock_started) { X lastwhite = lastblack = now; X return; X } X X if (white_running) { X whiteseconds += now - lastwhite; X lastwhite = now; X dohands(win1, WHITE); X if (!oneboard) X dohands(win2, WHITE); X if (timeunit) { X i = whiteseconds / timeunit; X if ((i > 0) && (whiteseconds > i * timeunit) && X (whiteseconds < i * timeunit + 10) && X (movesperunit * i > movenum)) { X message_add(win1, X "White has exceeded his time limit\n", X true); X if (!oneboard) { X message_add(win2, X "White has exceeded his time limit\n", X true); X } X timeunit = 0; X } X } X } else { X blackseconds += now - lastblack; X lastblack = now; X dohands(win1, BLACK); X if (!oneboard) X dohands(win2, BLACK); X if (timeunit) { X i = blackseconds / timeunit; X if ((i > 0) && (blackseconds > i * timeunit) && X (blackseconds < i * timeunit + 10) && X (movesperunit * i > movenum)) { X message_add(win1, X "Black has exceeded his time limit\n", X true); X if (!oneboard) { X message_add(win2, X "Black has exceeded his time limit\n", X true); X } X timeunit = 0; X } X } X } X return; X} X Xvoid Xclock_switch() X{ X if (firstmove) { X clock_started = true; X firstmove = false; X lastwhite = lastblack = time((long *) NULL); X } X if (white_running) { X white_running = false; X lastblack = time((long *) NULL); X hilight(win1, WHITE, false); X hilight(win1, BLACK, true); X if (!oneboard) { X hilight(win2, WHITE, false); X hilight(win2, BLACK, true); X } X } else { X white_running = true; X lastwhite = time((long *) NULL); X hilight(win1, WHITE, true); X hilight(win1, BLACK, false); X if (!oneboard) { X hilight(win2, WHITE, true); X hilight(win2, BLACK, false); X } X } X return; X} X Xstatic void Xdohands(win, col) X windata *win; X color col; X{ X int cx = CLOCK_WIDTH / 2, cy = CLOCK_WIDTH / 2; X double *h = (col == WHITE) ? win->whitehands : win->blackhands; X Window w = (col == WHITE) ? win->wclockwin : win->bclockwin; X long secs = (col == WHITE) ? whiteseconds : blackseconds; X int rad, x, y, i; X X /* First erase the old hands. */ X XSetState(win->display, DefaultGC(win->display, 0), X win->textback.pixel, win->textback.pixel, X GXcopy, AllPlanes); X X rad = CLOCK_WIDTH / 2 - 30; X for (i = 0; i < 3; i++) { X x = cx + rad * sin(PI - h[i]); X y = cy + rad * cos(PI - h[i]); X XSetLineAttributes(win->display, X DefaultGC(win->display, 0), X i, LineSolid, 0, 0); X XDrawLine(win->display, w, DefaultGC(win->display, 0), X cx, cy, x, y); X rad -= 8; X } X X h[0] = (secs % 60) * 2 * PI / 60; X h[1] = ((secs / 60) % 60) * 2 * PI / 60; X h[2] = ((secs / 3600) % 12) * 2 * PI / 12; X X /* Now draw the new ones. */ X X XSetState(win->display, DefaultGC(win->display, 0), X win->textcolor.pixel, win->textback.pixel, X GXcopy, AllPlanes); X X rad = CLOCK_WIDTH / 2 - 30; X for (i = 0; i < 3; i++) { X x = cx + rad * sin(PI - h[i]); X y = cy + rad * cos(PI - h[i]); X XSetLineAttributes(win->display, X DefaultGC(win->display, 0), X i, LineSolid, 0, 0); X XDrawLine(win->display, w, DefaultGC(win->display, 0), X cx, cy, x, y); X rad -= 8; X } X XFlush(win->display); X return; X} X Xstatic void Xhilight(win, col, on) X windata *win; X color col; X bool on; X{ X Window w = (col == WHITE) ? win->wclockwin : win->bclockwin; X char *s = (col == WHITE) ? " WHITE " : " BLACK "; X int x; X X X x = XTextWidth(win->large, s, strlen(s)); X if (on) X XSetState(win->display, DefaultGC(win->display, 0), X win->textback.pixel, X win->textcolor.pixel, X GXcopy, X AllPlanes); X else X XSetState(win->display, DefaultGC(win->display, 0), X win->textcolor.pixel, X win->textback.pixel, X GXcopy, AllPlanes); X X XSetLineAttributes(win->display, DefaultGC(win->display, 0), X BORDER_WIDTH, LineSolid, CapButt, JoinMiter); X XSetFont(win->display, DefaultGC(win->display, 0), X win->large->fid); X X XDrawLine(win->display, w, DefaultGC(win->display, 0), X 0, CLOCK_HEIGHT - 26, X CLOCK_WIDTH, CLOCK_HEIGHT - 26); X X XDrawImageString(win->display, w, DefaultGC(win->display, 0), X (CLOCK_WIDTH - x) / 2, CLOCK_HEIGHT, X s, strlen(s)); X X if (on) X XSetState(win->display, DefaultGC(win->display, 0), X win->textcolor.pixel, X win->textback.pixel, X GXcopy, AllPlanes); X return; X} X END_OF_FILE if test 7232 -ne `wc -c <'clock.c'`; then echo shar: \"'clock.c'\" unpacked with wrong size! fi # end of 'clock.c' fi if test -f 'jail.c' -a "${1}" != "-c" ; then echo shar: Will not clobber existing file \"'jail.c'\" else echo shar: Extracting \"'jail.c'\" \(7568 characters\) sed "s/^X//" >'jail.c' <<'END_OF_FILE' X/* This file contains code for X-CHESS. X Copyright (C) 1986 Free Software Foundation, Inc. X XThis file is part of X-CHESS. X XX-CHESS is distributed in the hope that it will be useful, Xbut WITHOUT ANY WARRANTY. No author or distributor Xaccepts responsibility to anyone for the consequences of using it Xor for whether it serves any particular purpose or works at all, Xunless he says so in writing. Refer to the X-CHESS General Public XLicense for full details. X XEveryone is granted permission to copy, modify and redistribute XX-CHESS, but only under the conditions described in the XX-CHESS General Public License. A copy of this license is Xsupposed to have been given to you along with X-CHESS so you Xcan know your rights and responsibilities. It should be in a Xfile named COPYING. Among other things, the copyright notice Xand this notice must be preserved on all copies. */ X X X/* RCS Info: $Revision: 1.3 $ on $Date: 86/11/26 12:09:54 $ X * $Source: /users/faustus/xchess/RCS/jail.c,v $ X * Copyright (c) 1986 Wayne A. Christopher, U. C. Berkeley CAD Group X * Permission is granted to do anything with this code except sell it X * or remove this message. X * X */ X X#include "xchess.h" X X#include "pawn_small.bitmap" X#include "rook_small.bitmap" X#include "knight_small.bitmap" X#include "bishop_small.bitmap" X#include "queen_small.bitmap" X#include "king_small.bitmap" X X#include "pawn_small_outline.bitmap" X#include "rook_small_outline.bitmap" X#include "knight_small_outline.bitmap" X#include "bishop_small_outline.bitmap" X#include "queen_small_outline.bitmap" X#include "king_small_outline.bitmap" X Xstatic bool pos[32]; X Xstatic piecetype pcs[] = { KING, QUEEN, ROOK, ROOK, BISHOP, BISHOP, KNIGHT, X KNIGHT, PAWN, PAWN, PAWN, PAWN, PAWN, PAWN, PAWN, PAWN } ; X Xextern int piecepos(); Xextern char *bitsget(); X Xvoid Xjail_init(win) X windata *win; X{ X int i; X X for (i = 0; i < 32; i++) X pos[i] = false; X jail_draw(win); X return; X} X X#define JAIL_HEADER "Captured Pieces" X Xvoid Xjail_draw(win) X windata *win; X{ X int i; X char *bits; X Pixmap tmpPM; X piece p; X X i = XTextWidth(win->large, JAIL_HEADER, strlen(JAIL_HEADER)); X XSetFont(win->display, DefaultGC(win->display, 0), X win->large->fid); X XSetForeground(win->display, DefaultGC(win->display, 0), X win->textcolor.pixel); X XSetBackground(win->display, DefaultGC(win->display, 0), X win->textback.pixel); X X XDrawImageString(win->display, win->jailwin, X DefaultGC(win->display, 0), X (JAIL_WIDTH - i) / 2, 20, JAIL_HEADER, X strlen(JAIL_HEADER)); X X XSetForeground(win->display, DefaultGC(win->display, 0), X win->blackpiece.pixel); X XSetBackground(win->display, DefaultGC(win->display, 0), X win->textback.pixel); X XSetFillStyle(win->display, DefaultGC(win->display, 0), X FillSolid); X XSetFunction(win->display, DefaultGC(win->display, 0), X GXcopy); X X for (i = 0; i < 16; i++) X if (pos[i]) { X p.color = WHITE; X p.type = pcs[i]; X bits = bitsget(&p); X tmpPM = XCreateBitmapFromData(win->display, X win->jailwin, bits, X 32, 32); X X XCopyPlane(win->display, tmpPM, win->jailwin, X DefaultGC(win->display, 0), X 0, 0, 32, 32, X 5 + (i % 8) * 32, 25 + (i / 8) * 32, X 1); X XFreePixmap(win->display, tmpPM); X } else { X XFillRectangle(win->display, win->jailwin, X DefaultGC(win->display, 0), X 5 + (i % 8) * 32, X 25 + (i / 8) * 32, X 32, 32); X } X for (i = 0; i < 16; i++) X if (pos[i + 16]) { X p.color = BLACK; X p.type = pcs[i]; X bits = bitsget(&p); X tmpPM = XCreateBitmapFromData(win->display, X win->jailwin, bits, X 32, 32); X X XCopyPlane(win->display, tmpPM, win->jailwin, X DefaultGC(win->display, 0), X 0, 0, 32, 32, X 5 + (i % 8) * 32, 94 + (i / 8) * 32, X 1); X XFreePixmap(win->display, tmpPM); X } else { X XFillRectangle(win->display, win->jailwin, X DefaultGC(win->display, 0), X 5 + (i % 8) * 32, 94 + (i / 8) * 32, X 32, 32); X } X X return; X} X Xvoid Xjail_add(p) X piece *p; X{ X int i = piecepos(p, false); X char *bits; X Pixmap tmpPM; X X pos[i] = true; X X bits = bitsget(p); X X XSetState(win1->display, DefaultGC(win1->display, 0), X win1->blackpiece.pixel, X win1->textback.pixel, X GXcopy, X AllPlanes); X X tmpPM = XCreateBitmapFromData(win1->display, X win1->jailwin, bits, X 32, 32); X X XCopyPlane(win1->display, tmpPM, win1->jailwin, X DefaultGC(win1->display, 0), X 0, 0, 32, 32, X 5 + (i % 8) * 32, ((i >= 16) ? 30 : 25) + (i / 8) * 32, X 1); X XFreePixmap(win1->display, tmpPM); X X if (!oneboard) { X XSetState(win2->display, DefaultGC(win2->display, 0), X win2->blackpiece.pixel, X win2->textback.pixel, X GXcopy, X AllPlanes); X X X tmpPM = XCreateBitmapFromData(win2->display, X win2->jailwin, bits, X 32, 32); X X XCopyPlane(win2->display, tmpPM, win2->jailwin, X DefaultGC(win2->display, 0), X 0, 0, 32, 32, X 5 + (i % 8) * 32, ((i >= 16) ? 30 : 25) + (i / 8) * 32, X 1); X XFreePixmap(win2->display, tmpPM); X } X X return; X} X Xvoid Xjail_remove(p) X piece *p; X{ X int i = piecepos(p, true); X X pos[i] = false; X X X XSetForeground(win1->display, X DefaultGC(win1->display, 0), X win1->blackpiece.pixel); X XSetBackground(win1->display, X DefaultGC(win1->display, 0), X win1->textback.pixel); X XSetFillStyle(win1->display, X DefaultGC(win1->display, 0), X FillSolid); X X XFillRectangle(win1->display, win1->jailwin, X DefaultGC(win1->display, 0), X 5 + (i % 8) * 32, X ((i >= 16) ? 30 : 25) + (i / 8) * 32, X 32, 32); X X if (!oneboard) { X XSetForeground(win2->display, X DefaultGC(win2->display, 0), X win2->blackpiece.pixel); X XSetBackground(win2->display, X DefaultGC(win2->display, 0), X win2->textback.pixel); X XSetFillStyle(win2->display, X DefaultGC(win2->display, 0), X FillSolid); X X XFillRectangle(win2->display, win2->jailwin, X DefaultGC(win2->display, 0), X 5 + (i % 8) * 32, X ((i >= 16) ? 30 : 25) + (i / 8) * 32, X 32, 32); X } X X return; X} X Xstatic char *bitsget(p) X piece *p; X{ X char *bits; X X switch (p->type) { X case PAWN: X bits = (p->color == WHITE) ? pawn_small_outline_bits : X pawn_small_bits; X break; X X case ROOK: X bits = (p->color == WHITE) ? rook_small_outline_bits : X rook_small_bits; X break; X X case KNIGHT: X bits = (p->color == WHITE) ? knight_small_outline_bits : X knight_small_bits; X break; X X case BISHOP: X bits = (p->color == WHITE) ? bishop_small_outline_bits : X bishop_small_bits; X break; X X case QUEEN: X bits = (p->color == WHITE) ? queen_small_outline_bits : X queen_small_bits; X break; X X case KING: X bits = (p->color == WHITE) ? king_small_outline_bits : X king_small_bits; X break; X } X return (bits); X} X Xstatic int Xpiecepos(p, there) X piece *p; X bool there; X{ X int i, base = (p->color == WHITE) ? 0 : 16; X X switch (p->type) { X case PAWN: X for (i = base + 8; (i < base + 15) && pos[i]; i++) X ; X if (there && !pos[i]) X i--; X break; X X case KING: X /* Hmm... */ X i = base; X break; X X case QUEEN: X i = base + 1; X break; X X case ROOK: X i = base + 2; X if ((there && pos[i + 1]) || (!there && pos[i])) X i++; X break; X X case BISHOP: X i = base + 4; X if ((there && pos[i + 1]) || (!there && pos[i])) X i++; X break; X X case KNIGHT: X i = base + 6; X if ((there && pos[i + 1]) || (!there && pos[i])) X i++; X break; X } X return (i); X} END_OF_FILE if test 7568 -ne `wc -c <'jail.c'`; then echo shar: \"'jail.c'\" unpacked with wrong size! fi # end of 'jail.c' fi if test -f 'std.c' -a "${1}" != "-c" ; then echo shar: Will not clobber existing file \"'std.c'\" else echo shar: Extracting \"'std.c'\" \(6617 characters\) sed "s/^X//" >'std.c' <<'END_OF_FILE' X/* This file contains code for X-CHESS. X Copyright (C) 1986 Free Software Foundation, Inc. X XThis file is part of X-CHESS. X XX-CHESS is distributed in the hope that it will be useful, Xbut WITHOUT ANY WARRANTY. No author or distributor Xaccepts responsibility to anyone for the consequences of using it Xor for whether it serves any particular purpose or works at all, Xunless he says so in writing. Refer to the X-CHESS General Public XLicense for full details. X XEveryone is granted permission to copy, modify and redistribute XX-CHESS, but only under the conditions described in the XX-CHESS General Public License. A copy of this license is Xsupposed to have been given to you along with X-CHESS so you Xcan know your rights and responsibilities. It should be in a Xfile named COPYING. Among other things, the copyright notice Xand this notice must be preserved on all copies. */ X X X/* RCS Info: $Revision: 1.1 $ on $Date: 86/11/01 17:08:40 $ X * $Source: /users/faustus/xchess/RCS/std.c,v $ X * Copyright (c) 1985 Wayne A. Christopher, U. C. Berkeley CAD Group X * X * Utility routines. X */ X X#include "std.h" X X#ifndef IBMPC X#include <sys/types.h> X#endif not IBMPC X#ifdef UNIX X#include <signal.h> X#include <pwd.h> X#endif UNIX X#ifdef BSD X#include <sys/time.h> X#include <sys/resource.h> X#endif BSD X Xextern char **environ; X Xbool Xprefix(p, s) X register char *p, *s; X{ X while (*p && (*p == *s)) X p++, s++; X if (!*p) X return (true); X else X return (false); X} X X/* Create a copy of a string. */ X Xchar * Xcopy(str) X char *str; X{ X char *p, *tmalloc(); X X p = tmalloc(strlen(str) + 1); X strcpy(p, str); X return(p); X} X X/* Determine whether sub is a substring of str. */ X Xbool Xsubstring(sub, str) X register char *str, *sub; X{ X register char *s; X X while(*str) { X if(*str == *sub) { X for(s = sub; *s; s++) X if(*s != *str++) X break; X if(*s == '\0') X return (true); X } X str++; X } X return (false); X} X X/* Malloc num bytes and initialize to zero. Fatal error if the space can't X * be malloc'd. X */ X Xchar * Xtmalloc(num) X register int num; X{ X register char *s; X char *malloc(); X X s = malloc((unsigned) num); X if (!s) { X fatal("malloc: can't allocate %d bytes", num); X } X bzero(s, num); X return(s); X} X Xchar * Xtrealloc(ptr, num) X char *ptr; X int num; X{ X register char *s; X char *realloc(); X X s = realloc(ptr, (unsigned) num); X if (!s) { X fatal("realloc: can't allocate %d bytes", num); X } X /* Well, this won't be zeroed... Too bad... */ X return(s); X} X X/* Append one character to a string. Don't check for overflow. */ X Xvoid Xappendc(s, c) X char *s, c; X{ X while (*s) X s++; X *s++ = c; X *s = '\0'; X return; X} X Xint Xscannum(str) X char *str; X{ X int i = 0; X X while(isdigit(*str)) X i = i * 10 + *(str++) - '0'; X return(i); X} X X/* Case insensitive prefix. */ X Xbool Xciprefix(p, s) X register char *p, *s; X{ X while (*p) { X if ((isupper(*p) ? tolower(*p) : *p) != X (isupper(*s) ? tolower(*s) : *s)) X return(false); X p++; X s++; X } X return (true); X} X X/* Case insensitive strcmp... */ X Xbool Xcieq(p, s) X register char *p, *s; X{ X while (*p) { X if ((isupper(*p) ? tolower(*p) : *p) != X (isupper(*s) ? tolower(*s) : *s)) X return(false); X p++; X s++; X } X return (!*s); X} X X#ifdef BSD X X/* Return the date. Return value is static data. */ X Xchar * Xdatestring() X{ X register char *tzn; X struct tm *tp; X static char tbuf[40]; X char *ap; X struct timeval tv; X struct timezone tz; X char *timezone(), *asctime(); X int i; X struct tm *localtime(); X X (void) gettimeofday(&tv, &tz); X tp = localtime((time_t *) &tv.tv_sec); X ap = asctime(tp); X tzn = timezone(tz.tz_minuteswest, tp->tm_isdst); X sprintf(tbuf, "%.20s", ap); X if (tzn) X strcat(tbuf, tzn); X strcat(tbuf, ap + 19); X i = strlen(tbuf); X tbuf[i - 1] = '\0'; X return (tbuf); X} X X#else BSD X X/* Give it a try... */ X Xchar * Xdatestring() X{ X long i; X static char buf[64]; X X i = time(0); X strcpy(buf, ctime(&i)); X buf[strlen(buf) - 1] = '\0'; /* Kill the nl. */ X return (buf); X} X X#endif X X/* How many seconds have elapsed in running time. */ X Xint Xseconds() X{ X#ifdef BSD X struct rusage ruse; X X getrusage(RUSAGE_SELF, &ruse); X return (ruse.ru_utime.tv_sec); X#else BSD X#endif BSD X} X X/* A few things that may not exist on non-unix systems. */ X X#ifndef BSD X X#ifndef index X Xchar * Xindex(s, c) X register char *s; X register char c; X{ X while ((*s != c) && (*s != '\0')) X s++; X if (*s == '\0') X return ((char *) 0); X else X return (s); X} X X#endif not index X X#ifndef rindex X Xchar * Xrindex(s, c) X register char *s; X register char c; X{ X register char *t; X X for (t = s; *t != '\0'; t++); X while ((*t != c) && (t != s)) X t--; X if (t == s) X return ((char *) 0); X else X return (t); X} X X#endif not rindex X X#ifndef bcopy X Xvoid Xbcopy(from, to, num) X register char *from, *to; X register int num; X{ X while (num-- > 0) X *to++ = *from++; X return; X} X X#endif not bcopy X X#ifndef bzero X Xvoid Xbzero(ptr, num) X register char *ptr; X register int num; X{ X while (num-- > 0) X *ptr++ = '\0'; X return; X} X X#endif not bzero X X/* This might not be around... If not then forget about sorting... */ X Xvoid qsort() {} X X#endif BSD X Xchar * Xgettok(s) X char **s; X{ X char buf[BSIZE]; X int i = 0; X X while (isspace(**s)) X (*s)++; X if (!**s) X return (NULL); X while (**s && !isspace(**s)) X buf[i++] = *(*s)++; X buf[i] = '\0'; X while (isspace(**s)) X (*s)++; X return (copy(buf)); X} X X/* Die horribly. */ X X/* VARARGS1 */ Xvoid Xfatal(s, args) X char *s; X{ X fputs("Internal Error: ", stderr); X _doprnt(s, &args, stderr); X putc('\n', stderr); X X kill(getpid(), SIGIOT); X /* NOTREACHED */ X} X Xvoid Xsetenv(name, value) X char *name, *value; X{ X int i; X char **xx, *s; X X s = tmalloc(strlen(name) + 2); X sprintf(s, "%s=", name); X X /* Copy the old environment... */ X for (i = 0; environ[i]; i++) X if (prefix(s, environ[i])) X break; X if (!environ[i]) { X xx = (char **) tmalloc((i + 2) * sizeof (char *)); X for (i = 0; environ[i]; i++) X xx[i] = environ[i]; X xx[i + 1] = NULL; X environ = xx; X } else X xx = environ; X X xx[i] = tmalloc(strlen(name) + strlen(value) + 2); X sprintf(xx[i], "%s=%s", name, value); X return; X} X Xchar * Xgetusername() X{ X int i = getuid(); X struct passwd *pw = getpwuid(i); X X return (pw ? pw->pw_name : NULL); X} X Xchar * Xgethome() X{ X int i = getuid(); X struct passwd *pw = getpwuid(i); X X return (pw ? pw->pw_dir : "/strange"); X} X Xchar * Xtildexpand(s) X char *s; X{ X struct passwd *pw; X char *n, buf[64]; X int i; X X if (*s != '~') X return (copy(s)); X X for (s++, i = 0; *s != '/'; s++, i++) X buf[i] = *s; X buf[i] = '\0'; X if (!i) X pw = getpwuid(getuid()); X else X pw = getpwnam(buf); X if (!pw) X return (s); X n = tmalloc(strlen(s) + strlen(pw->pw_dir) + 1); X strcpy(n, pw->pw_dir); X strcat(n, s); X return (n); X} X END_OF_FILE if test 6617 -ne `wc -c <'std.c'`; then echo shar: \"'std.c'\" unpacked with wrong size! fi # end of 'std.c' fi if test -f 'valid.c' -a "${1}" != "-c" ; then echo shar: Will not clobber existing file \"'valid.c'\" else echo shar: Extracting \"'valid.c'\" \(6907 characters\) sed "s/^X//" >'valid.c' <<'END_OF_FILE' X/* This file contains code for X-CHESS. X Copyright (C) 1986 Free Software Foundation, Inc. X XThis file is part of X-CHESS. X XX-CHESS is distributed in the hope that it will be useful, Xbut WITHOUT ANY WARRANTY. No author or distributor Xaccepts responsibility to anyone for the consequences of using it Xor for whether it serves any particular purpose or works at all, Xunless he says so in writing. Refer to the X-CHESS General Public XLicense for full details. X XEveryone is granted permission to copy, modify and redistribute XX-CHESS, but only under the conditions described in the XX-CHESS General Public License. A copy of this license is Xsupposed to have been given to you along with X-CHESS so you Xcan know your rights and responsibilities. It should be in a Xfile named COPYING. Among other things, the copyright notice Xand this notice must be preserved on all copies. */ X X X/* RCS Info: $Revision: 1.3 $ on $Date: 86/11/23 17:18:35 $ X * $Source: /users/faustus/xchess/RCS/valid.c,v $ X * Copyright (c) 1986 Wayne A. Christopher, U. C. Berkeley CAD Group X * Permission is granted to do anything with this code except sell it X * or remove this message. X * X * Validate a move. X */ X X#include "xchess.h" X Xextern bool ischeck(), couldmove(); X Xbool Xvalid_move(m, b) X move *m; X board *b; X{ X board tb; X X /* First check that the piece can make the move at all... */ X if (!couldmove(m, b)) X return (false); X X /* Now see if the king is in check now. */ X bcopy((char *) b, (char *) &tb, sizeof (board)); X board_move(&tb, m); X if (ischeck(&tb, m->piece.color)) X return (false); X X if (ischeck(&tb, ((m->piece.color == WHITE) ? BLACK : WHITE))) X m->check = true; X X return (true); X} X Xstatic bool Xcouldmove(m, b) X move *m; X board *b; X{ X int x, y; X X switch (m->type) { X case KCASTLE: X if ((m->piece.color == WHITE) && (b->white_cant_castle_k) || X (m->piece.color == BLACK) && X (b->black_cant_castle_k)) X return (false); X if ((b->square[m->fromy][5].color != NONE) || X (b->square[m->fromy][6].color != NONE)) X return (false); X if (ischeck(b, m->piece.color)) X return (false); X break; X X case QCASTLE: X if ((m->piece.color == WHITE) && (b->white_cant_castle_q) || X (m->piece.color == BLACK) && X (b->black_cant_castle_q)) X return (false); X if ((b->square[m->fromy][1].color != NONE) || X (b->square[m->fromy][2].color != NONE) || X (b->square[m->fromy][3].color != NONE)) X return (false); X if (ischeck(b, m->piece.color)) X return (false); X break; X X case MOVE: X case CAPTURE: X /* There is one special case here, that of taking a pawn X * en passant. In this case we change the move field to X * CAPTURE if it's ok. X */ X switch (m->piece.type) { X case PAWN: X if ((m->type == MOVE) && (m->fromx == m->tox)) { X /* A normal move. */ X if ((m->piece.color == WHITE) && (m->fromy == X m->toy + 1)) X break; X if ((m->piece.color == WHITE) && (m->fromy == X 6) && (m->toy == 4) && X (b->square[5][m->fromx].color X == NONE)) X break; X if ((m->piece.color == BLACK) && (m->fromy == X m->toy - 1)) X break; X if ((m->piece.color == BLACK) && (m->fromy == X 1) && (m->toy == 3) && X (b->square[2][m->fromx].color X == NONE)) X break; X return (false); X } else if (m->type == CAPTURE) { X if ((((m->piece.color == WHITE) && (m->fromy == X m->toy + 1)) || ((m->piece.color == X BLACK) && (m->fromy == m->toy - X 1))) && ((m->fromx == m->tox + 1) || X (m->fromx == m->tox - 1))) X break; X /* Now maybe it's enpassant... We've already X * checked for some of these things in the X * calling routine. X */ X if (m->enpassant) { X if (b->square[(m->piece.color == WHITE) X ? 3 : 4][m->tox].color == X ((m->piece.color == WHITE) ? X BLACK : WHITE)) X break; X } X return (false); X } X return (false); X X case ROOK: X if (m->fromx == m->tox) { X for (y = m->fromy + ((m->fromy > m->toy) ? -1 : X 1); y != m->toy; y += ((m->fromy X > m->toy) ? -1 : 1)) X if (b->square[y][m->tox].color != NONE) X return (false); X break; X } X if (m->fromy == m->toy) { X for (x = m->fromx + ((m->fromx > m->tox) ? -1 : X 1); x != m->tox; x += ((m->fromx X > m->tox) ? -1 : 1)) X if (b->square[m->toy][x].color != NONE) X return (false); X break; X } X return (false); X X case KNIGHT: X x = m->fromx - m->tox; X y = m->fromy - m->toy; X if ((((x == 2) || (x == -2)) && X ((y == 1) || (y == -1))) || X (((x == 1) || (x == -1)) && X ((y == 2) || (y == -2)))) X break; X return (false); X X case BISHOP: X x = m->fromx - m->tox; X y = m->fromy - m->toy; X if ((x != y) && (x != - y)) X return (false); X for (x = m->fromx + ((m->fromx > m->tox) ? -1 : 1), y = X m->fromy + ((m->fromy > m->toy) ? -1 : X 1); x != m->tox; X x += ((m->fromx > m->tox) ? -1 : 1), X y += ((m->fromy > m->toy) ? -1 : 1)) X if (b->square[y][x].color != NONE) X return (false); X break; X X case QUEEN: X if (m->fromx == m->tox) { X for (y = m->fromy + ((m->fromy > m->toy) ? -1 : X 1); y != m->toy; y += ((m->fromy X > m->toy) ? -1 : 1)) X if (b->square[y][m->tox].color != NONE) X return (false); X break; X } X if (m->fromy == m->toy) { X for (x = m->fromx + ((m->fromx > m->tox) ? -1 : X 1); x != m->tox; x += ((m->fromx X > m->tox) ? -1 : 1)) X if (b->square[m->toy][x].color != NONE) X return (false); X break; X } X x = m->fromx - m->tox; X y = m->fromy - m->toy; X if ((x != y) && (x != - y)) X return (false); X for (x = m->fromx + ((m->fromx > m->tox) ? -1 : 1), y = X m->fromy + ((m->fromy > m->toy) ? -1 : X 1); x != m->tox; X x += ((m->fromx > m->tox) ? -1 : 1), X y += ((m->fromy > m->toy) ? -1 : 1)) X if (b->square[y][x].color != NONE) X return (false); X break; X X case KING: X x = m->fromx - m->tox; X y = m->fromy - m->toy; X if ((x >= -1) && (x <= 1) && (y >= -1) && (y <= 1)) X break; X return (false); X } X break; X } X return (true); X} X X/* Say whether either king is in check... If move is non-NULL, say whether he X * in in check after the move takes place. We do this in a rather stupid way. X */ X Xstatic bool Xischeck(b, col) X board *b; X color col; X{ X int x, y, kx, ky; X move ch; X X for (x = 0; x < SIZE; x++) X for (y = 0; y < SIZE; y++) X if ((b->square[y][x].color == col) && X (b->square[y][x].type == KING)) { X kx = x; X ky = y; X } X X for (x = 0; x < SIZE; x++) X for (y = 0; y < SIZE; y++) X if (b->square[y][x].color == ((col == WHITE) ? X BLACK : WHITE)) { X ch.type = CAPTURE; X ch.piece.color = b->square[y][x].color; X ch.piece.type = b->square[y][x].type; X ch.fromx = x; X ch.fromy = y; X ch.tox = kx; X ch.toy = ky; X ch.enpassant = false; X if (couldmove(&ch, b)) X return (true); X } X X return (false); X} X END_OF_FILE if test 6907 -ne `wc -c <'valid.c'`; then echo shar: \"'valid.c'\" unpacked with wrong size! fi # end of 'valid.c' fi if test -f 'xchess.1' -a "${1}" != "-c" ; then echo shar: Will not clobber existing file \"'xchess.1'\" else echo shar: Extracting \"'xchess.1'\" \(6181 characters\) sed "s/^X//" >'xchess.1' <<'END_OF_FILE' X.TH XCHESS 1 "14 Nov 1986" "X Version 10" X.SH NAME Xxchess \- X chess display X.SH SYNOPSIS X.B xchess X[ option ... ] [ white-display ] [ black-display ] X.SH DESCRIPTION X.PP X.B xchess Xis a chess display program which allows players to play a game on either Xone or two displays, or play a chess-playing program. It uses the X.B X Xwindow system. If one or no display names are given, it will open up one Xwindow and both black and white at the same board. If two displays are Xgiven, X.B xchess Xwill accept moves from each player in his turn. Black's board will be drawn Xwith his pieces at the bottom. X.PP X.B xchess Xwill not allow a player to make an illegal move. It accepts all legal moves, Xincluding castling and pawn capture \fIen passant\fR. X.SH OPTIONS X.TP 8 X.B -d XTurn on debugging. X.TP 8 X.B -f record-file XUse \fBrecord-file\fR for saving the game when the \fBSave\fR button is Xselected, or if the \fB-s\fR flag is given. The default is "xchess.game". X.TP 8 X.B -r saved-game XStart with the position at the end of the saved game in the named file. XThis file may be the result of the \fBSave\fR command, and may be in Xeither English or International format. When reading moves, one move Xit made per second. X.TP 8 X.B -q XDon't pause for a second every time a move is made when a game is being Xrestored. X.TP 8 X.B -v XWhenever a piece is moved, outline the path with a "lightning bolt". XThis option and the \fB-n\fR option are useful if you don't want to miss Xan opponent's move when he makes it. X.TP 8 X.B -i XUse International format for recording moves (squares numbered 1-8, a-h) Xas opposed to English (e.g, \fIp/k4xp/q5\fR). X.TP 8 X.B -t moves/timeunit XAllows \fBtimeunit\fR seconds for every \fBmoves\fR moves. If either player Xexceeds this allowance both recieve a message saying informing them of Xthis fact. X.TP 8 X.B -c XPlay the computer. X.B xchess Xwill start up a chess-playing program (currently the only one it knows Xhow to talk to is \fBGNU Chess\fR). X.TP 8 X.B -p program XThe name of the program to use if the \fB-c\fR option is given. The Xdefault is "/usr/public/gnuchess". Note that \fBgnuchess\fR must be Xcompiled with the \fIcompat\fR flag (in the file "main.c") set to 1. X.TP 8 X.B -b XIf the \fB-c\fR flag was given, have the computer play white. X.TP 8 X.B -bnw XIf the display has more than one display plane (i.e, is color), pretend Xit's black and white. X.TP 8 X.B -s XSave the moves in the record file as they are made. This is useful if Xyou don't want your game to be lost when \fBxchess\fR core dumps. X.TP 8 X.B -n XBe noisy \- beep after every move is made. X.TP 8 X.B -h host XRun GNU Chess on the specified \fBhost\fR. X.TP 8 X.B -R XRandomly chose who plays white and who plays black, if two displays are Xgiven. X.SH CONTROLS X.PP XThe window is divided up into several sub-windows. The pieces are moved by Xpushing down any mouse button on top of the piece, moving to the destination Xsquare, and releasing it. Castling is done by moving the king to the Xright square. If you push down on a piece and then let the button Xup without moving it, you must move that piece. ("Touch it, move it.") X.PP XThe progress of the game is listed in the "Game Record" window. Error Xmessages and such things are printed in the "Message" window. Both these Xwindows have scroll bars that you can use to move around. XThere are also windows for clocks and for a record of the pieces captured. X.PP XIf you type any keys in the window, the text will go into the message Xwindow of both players. This provides a simple communication facility. X.PP XThere are 9 buttons in the control window. They are as follows: X.TP 8 X.B Draw XBoth players must push this button to agree on a draw (just one is ok Xif only one display is being used). X.TP 8 X.B Resign XThe player whose turn it is to move resigns. X.TP 8 X.B Reset XStart over from the beginning. X.TP 8 X.B Back XRetract a move. If two displays are being used the other player will be Xasked to confirm this. X.TP 8 X.B Fwd XThis will re-play the most recently retracted move. This button in conjunction Xwith \fBBack\fR is useful for "scrolling around" in a saved game. X.TP 8 X.B Save XSave the game in the record file. X.TP 8 X.B Flip XRotate the board so that Black will have his pieces at the bottom. X.TP 8 X.B Switch XChange the mapping of boards to players. X.TP 8 X.B Pause XThis button has two functions. When a game is being restored, pieces will Xbe moved once a second. Hitting \fBPause\fR will stop this process, and Xhitting it again will restart it. During the time that it is stopped no Xother action can be made except restarting it. While a game is being played, X\fBPause\fR will stop the clock and restart it. X.SH DEFAULTS X.PP X\fBxchess\fR uses the following \fI.Xdefaults\fR: X.TP 8 X.B Noisy XThe -n flag. X.TP 8 X.B SaveMoves XThe -s flag. X.TP 8 X.B Algebraic XThe -i flag. X.TP 8 X.B BlackAndWhite XThe -bnw flag. X.TP 8 X.B QuickRestore XThe -q flag. X.TP 8 X.B Flash XThe -v flag. X.TP 8 X.B NumFlashes XHow many times to flash the move. The default is 5. X.TP 8 X.B FlashWidth XHow big to make the lightning bolt. The default is 10 pixels. X.TP 8 X.B ProgName XThe -p option. This may also be changed in the Makefile (-DDEF_PROG_NAME). X.TP 8 X.B ProgHost XThe -h option. X.TP 8 X.B RecordFile XThe -f option. X.TP 8 X.B BlackPiece XThe color of the black pieces. X.TP 8 X.B WhitePiece XThe color of the white pieces. X.TP 8 X.B BorderColor XThe color of the borders. X.TP 8 X.B BlackSquare XThe color of the black squares. X.TP 8 X.B WhiteSquare XThe color of the white squares. X.TP 8 X.B TextColor XThe color of routine messages and the move record text. X.TP 8 X.B ErrorText XThe color of error messages. X.TP 8 X.B PlayerText XThe color of player-entered text. X.TP 8 X.B TextBack XThe background color for the two text windows. X.TP 8 X.B CursorColor XThe color of the mouse and the text cursors. X.SH "SEE ALSO" XX(8), gnuchess(1), chess(5) X.SH AUTHOR XWayne A. Christopher (faustus@ic.berkeley.edu) X.SH BUGS X.PP XCheckmate and stalemate are not detected, so the appropriate player must resign Xor agree to a draw respectively. X.PP X\fBSwitch\fR doesn't work. X.PP XIf you are playing \fBgnuchess\fR, and you select Undo a few times so that it Xis \fBgnuchess\fR's turn to move, it won't do anything. END_OF_FILE if test 6181 -ne `wc -c <'xchess.1'`; then echo shar: \"'xchess.1'\" unpacked with wrong size! fi # end of 'xchess.1' fi if test -f 'xchess.h' -a "${1}" != "-c" ; then echo shar: Will not clobber existing file \"'xchess.h'\" else echo shar: Extracting \"'xchess.h'\" \(7124 characters\) sed "s/^X//" >'xchess.h' <<'END_OF_FILE' X/* This file contains code for X-CHESS. X Copyright (C) 1986 Free Software Foundation, Inc. X XThis file is part of X-CHESS. X XX-CHESS is distributed in the hope that it will be useful, Xbut WITHOUT ANY WARRANTY. No author or distributor Xaccepts responsibility to anyone for the consequences of using it Xor for whether it serves any particular purpose or works at all, Xunless he says so in writing. Refer to the X-CHESS General Public XLicense for full details. X XEveryone is granted permission to copy, modify and redistribute XX-CHESS, but only under the conditions described in the XX-CHESS General Public License. A copy of this license is Xsupposed to have been given to you along with X-CHESS so you Xcan know your rights and responsibilities. It should be in a Xfile named COPYING. Among other things, the copyright notice Xand this notice must be preserved on all copies. */ X X X/* RCS Info: $Revision: 1.5 $ on $Date: 86/11/26 12:11:39 $ X * $Source: /users/faustus/xchess/RCS/xchess.h,v $ X * Copyright (c) 1986 Wayne A. Christopher, U. C. Berkeley CAD Group X * Permission is granted to do anything with this code except sell it X * or remove this message. X * X * Definitions for the X chess program. X */ X X#include "std.h" X#include <X11/Xlib.h> X#include "scrollText.h" X X#define SIZE 8 X Xtypedef enum piecetype { PAWN, ROOK, KNIGHT, BISHOP, QUEEN, KING } piecetype; Xtypedef enum movetype { MOVE, QCASTLE, KCASTLE, CAPTURE } movetype; Xtypedef enum color { WHITE, BLACK, NONE } color; X Xtypedef struct piece { X enum piecetype type; X enum color color; X} piece; X X/* The board has y=0 and black at the top... This probably isn't the best X * place to keep track of who can castle, but it's part of the game state... X */ X Xtypedef struct board { X piece square[SIZE][SIZE]; X bool white_cant_castle_k; X bool white_cant_castle_q; X bool black_cant_castle_k; X bool black_cant_castle_q; X} board; X Xtypedef struct move { X movetype type; X piece piece; X piece taken; X int fromx, fromy; X int tox, toy; X struct move *next; X bool enpassant; X bool check; X} move; X X#define iswhite(win, i, j) (!(((i) + (j)) % 2)) X X/* Stuff for the display. */ X Xtypedef struct windata { X Display *display; X Window basewin; X Window boardwin; X Window recwin; X Window wclockwin; X Window bclockwin; X Window messagewin; X Window buttonwin; X Window jailwin; X Window icon; X Pixmap iconpixmap; X XColor blackpiece; X XColor whitepiece; X XColor blacksquare; X XColor whitesquare; X XColor border; X XColor textcolor; X XColor textback; X XColor errortext; X XColor playertext; X XColor cursorcolor; X XFontStruct *small; X XFontStruct *medium; X XFontStruct *large; X bool bnw; X color color; X bool flipped; X double whitehands[3]; X double blackhands[3]; X char *txtassoc; X} windata; X X#define SMALL_FONT "6x10" X#define MEDIUM_FONT "8x13" X#define LARGE_FONT "9x15" X#define JAIL_FONT "6x10" X X#define SQUARE_WIDTH 80 X#define SQUARE_HEIGHT 80 X X#define BORDER_WIDTH 3 X X#define BOARD_WIDTH 8 * SQUARE_WIDTH + 7 * BORDER_WIDTH X#define BOARD_HEIGHT 8 * SQUARE_HEIGHT + 7 * BORDER_WIDTH X#define BOARD_XPOS 0 X#define BOARD_YPOS 0 X X#define RECORD_WIDTH 265 /* 40 chars * 6 pixels / character. */ X#define RECORD_HEIGHT 433 X#define RECORD_XPOS BOARD_WIDTH + BORDER_WIDTH X#define RECORD_YPOS 0 X X#define JAIL_WIDTH RECORD_WIDTH X#define JAIL_HEIGHT 163 X#define JAIL_XPOS RECORD_XPOS X#define JAIL_YPOS RECORD_YPOS + RECORD_HEIGHT + BORDER_WIDTH X X#define CLOCK_WIDTH 131 X#define CLOCK_HEIGHT 131 + BORDER_WIDTH + 20 X#define WCLOCK_XPOS RECORD_XPOS X#define WCLOCK_YPOS RECORD_HEIGHT + JAIL_HEIGHT + BORDER_WIDTH * 2 X#define BCLOCK_XPOS WCLOCK_XPOS + CLOCK_WIDTH + BORDER_WIDTH X#define BCLOCK_YPOS WCLOCK_YPOS X X#define MESS_WIDTH 329 X#define MESS_HEIGHT 92 X#define MESS_XPOS 0 X#define MESS_YPOS BOARD_HEIGHT + BORDER_WIDTH X X#define BUTTON_WIDTH MESS_WIDTH X#define BUTTON_HEIGHT MESS_HEIGHT X#define BUTTON_XPOS MESS_WIDTH + BORDER_WIDTH X#define BUTTON_YPOS MESS_YPOS X X#define BASE_WIDTH BOARD_WIDTH + RECORD_WIDTH + BORDER_WIDTH * 3 X#define BASE_HEIGHT BOARD_HEIGHT + MESS_HEIGHT + BORDER_WIDTH * 3 X X#define BASE_XPOS 50 X#define BASE_YPOS 50 X X#define BLACK_PIECE_COLOR "#202020" X#define WHITE_PIECE_COLOR "#FFFFCC" X#define BLACK_SQUARE_COLOR "#77A26D" X#define WHITE_SQUARE_COLOR "#C8C365" X#define BORDER_COLOR "#902E39" X#define TEXT_COLOR "#006D6D" X#define TEXT_BACK "#FFFFDD" X#define ERROR_TEXT "Red" X#define PLAYER_TEXT "Blue" X#define CURSOR_COLOR "#FF606F" X X#define DEF_RECORD_FILE "xchess.game" X X#define NUM_FLASHES 5 X#define FLASH_SIZE 10 X X/* xchess.c */ X Xextern void main(); Xextern bool debug; Xextern char *progname; Xextern char *proghost; Xextern char *piecenames[]; Xextern char *colornames[]; Xextern char *movetypenames[]; Xextern char *dispname1, *dispname2; Xextern bool oneboard; Xextern bool bnwflag; Xextern bool progflag; Xextern bool blackflag; Xextern bool quickflag; Xextern int num_flashes; Xextern int flash_size; Xextern char *black_piece_color; Xextern char *white_piece_color; Xextern char *black_square_color; Xextern char *white_square_color; Xextern char *border_color; Xextern char *text_color; Xextern char *text_back; Xextern char *error_text; Xextern char *player_text; Xextern char *cursor_color; X X/* board.c */ X Xextern void board_setup(); Xextern void board_drawall(); Xextern void board_move(); Xextern board *chessboard; Xextern void board_init(); X X/* window.c */ X Xextern bool win_setup(); Xextern void win_redraw(); Xextern void win_restart(); Xextern void win_drawboard(); Xextern void win_drawpiece(); Xextern void win_erasepiece(); Xextern void win_process(); Xextern void win_flash(); Xextern windata *win1, *win2; Xextern bool win_flashmove; X X/* control.c */ X Xextern void button_pressed(); Xextern void button_released(); Xextern void move_piece(); Xextern void prog_move(); Xextern move *moves; Xextern move *foremoves; Xextern color nexttomove; Xextern void replay(); Xextern void forward(); Xextern void cleanup(); Xextern void restart(); Xextern bool noisyflag; X X/* valid.c */ X Xextern bool valid_move(); X X/* record.c */ X Xextern void record_move(); Xextern void record_reset(); Xextern void record_save(); Xextern void record_back(); Xextern void record_init(); Xextern void record_end(); Xextern bool record_english; Xextern char *record_file; Xextern int movenum; Xextern bool saveflag; X X/* message.c */ X Xextern void message_init(); Xextern void message_add(); Xextern void message_send(); X X/* clock.c */ X Xextern void clock_init(); Xextern void clock_draw(); Xextern void clock_update(); Xextern void clock_switch(); Xextern bool clock_started; Xextern int movesperunit; Xextern int timeunit; Xextern int whiteseconds; Xextern int blackseconds; X X/* button.c */ X Xextern void button_draw(); Xextern void button_service(); X X/* jail.c */ X Xextern void jail_init(); Xextern void jail_draw(); Xextern void jail_add(); Xextern void jail_remove(); X X/* program.c */ Xextern bool program_init(); Xextern void program_end(); Xextern void program_send(); Xextern void program_undo(); Xextern move *program_get(); X X/* parse.c */ X Xextern void load_game(); Xextern move *parse_file(); Xextern move *parse_move(); Xextern move *parse_imove(); Xextern bool loading_flag; Xextern bool loading_paused; X X/* popup.c */ X Xextern bool pop_question(); X END_OF_FILE if test 7124 -ne `wc -c <'xchess.h'`; then echo shar: \"'xchess.h'\" unpacked with wrong size! fi # end of 'xchess.h' fi if test -f 'xchess.icon' -a "${1}" != "-c" ; then echo shar: Will not clobber existing file \"'xchess.icon'\" else echo shar: Extracting \"'xchess.icon'\" \(1874 characters\) sed "s/^X//" >'xchess.icon' <<'END_OF_FILE' X#define icon_width 48 X#define icon_height 48 Xstatic char icon_bits[] = { X 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x01, 0x00, 0x00, 0x00, 0x00, 0x80, X 0xc1, 0xff, 0xff, 0xff, 0xff, 0x83, 0x41, 0x00, 0x00, 0x00, 0x00, 0x82, X 0x41, 0xf0, 0xf0, 0xf0, 0xf0, 0x82, 0x41, 0xf0, 0xf0, 0xf0, 0xf0, 0x82, X 0x41, 0xf0, 0xf0, 0xf0, 0xf0, 0x82, 0x41, 0xf0, 0xf0, 0xf0, 0xf0, 0x82, X 0x41, 0x0f, 0x0f, 0x0f, 0x0f, 0x82, 0x41, 0x0f, 0x0f, 0x0f, 0x0f, 0x82, X 0x41, 0x0f, 0x0f, 0x0f, 0x0f, 0x82, 0x41, 0x0f, 0x0f, 0x0f, 0x0f, 0x82, X 0x41, 0xf0, 0xf0, 0xf0, 0xf0, 0x82, 0x41, 0xf0, 0xf0, 0xf0, 0xf0, 0x82, X 0x41, 0xf0, 0xf0, 0xf0, 0xf0, 0x82, 0x41, 0xf0, 0xf0, 0xf0, 0xf0, 0x82, X 0x41, 0x0f, 0x0f, 0x0f, 0x0f, 0x82, 0x41, 0x0f, 0x0f, 0x0f, 0x0f, 0x82, X 0x41, 0x0f, 0x0f, 0x0f, 0x0f, 0x82, 0x41, 0x0f, 0x0f, 0x0f, 0x0f, 0x82, X 0x41, 0xf0, 0xf0, 0xf0, 0xf0, 0x82, 0x41, 0xf0, 0xf0, 0xf0, 0xf0, 0x82, X 0x41, 0xf0, 0xf0, 0xf0, 0xf0, 0x82, 0x41, 0xf0, 0xf0, 0xf0, 0xf0, 0x82, X 0x41, 0x0f, 0x0f, 0x0f, 0x0f, 0x82, 0x41, 0x0f, 0x0f, 0x0f, 0x0f, 0x82, X 0x41, 0x0f, 0x0f, 0x0f, 0x0f, 0x82, 0x41, 0x0f, 0x0f, 0x0f, 0x0f, 0x82, X 0x41, 0xf0, 0xf0, 0xf0, 0xf0, 0x82, 0x41, 0xf0, 0xf0, 0xf0, 0xf0, 0x82, X 0x41, 0xf0, 0xf0, 0xf0, 0xf0, 0x82, 0x41, 0xf0, 0xf0, 0xf0, 0xf0, 0x82, X 0x41, 0x0f, 0x0f, 0x0f, 0x0f, 0x82, 0x41, 0x0f, 0x0f, 0x0f, 0x0f, 0x82, X 0x41, 0x0f, 0x0f, 0x0f, 0x0f, 0x82, 0x41, 0x0f, 0x0f, 0x0f, 0x0f, 0x82, X 0x41, 0x00, 0x00, 0x00, 0x00, 0x82, 0xc1, 0xff, 0xff, 0xff, 0xff, 0x83, X 0x01, 0x00, 0x00, 0x00, 0x00, 0x80, 0x41, 0xc4, 0x89, 0x3c, 0xcf, 0x83, X 0x41, 0x24, 0x88, 0x04, 0x41, 0x80, 0x81, 0x22, 0x88, 0x04, 0x41, 0x80, X 0x01, 0x21, 0xf8, 0x1c, 0xcf, 0x83, 0x81, 0x22, 0x88, 0x04, 0x08, 0x82, X 0x41, 0x24, 0x88, 0x04, 0x08, 0x82, 0x41, 0xc4, 0x89, 0x3c, 0xcf, 0x83, X 0x01, 0x00, 0x00, 0x00, 0x00, 0x80, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff}; END_OF_FILE if test 1874 -ne `wc -c <'xchess.icon'`; then echo shar: \"'xchess.icon'\" unpacked with wrong size! fi # end of 'xchess.icon' fi echo shar: End of archive 3 \(of 6\). cp /dev/null ark3isdone MISSING="" for I in 1 2 3 4 5 6 ; do if test ! -f ark${I}isdone ; then MISSING="${MISSING} ${I}" fi done if test "${MISSING}" = "" ; then echo You have unpacked all 6 archives. rm -f ark[1-9]isdone else echo You still need to unpack the following archives: echo " " ${MISSING} fi ## End of shell archive. exit 0 -- Mike Wexler(wyse!mikew) Phone: (408)433-1000 x1330 Moderator of comp.sources.x