home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Usenet 1994 October
/
usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso
/
games
/
volume13
/
gnuchess4
/
part08
< prev
next >
Wrap
Internet Message Format
|
1992-08-03
|
56KB
Path: uunet!zephyr.ens.tek.com!master!saab!billr
From: billr@saab.CNA.TEK.COM (Bill Randle)
Newsgroups: comp.sources.games
Subject: v13i096: gnuchess4 - GNU Chess 4.0, Part08/12
Message-ID: <3063@master.CNA.TEK.COM>
Date: 19 Jun 92 15:54:47 GMT
Sender: news@master.CNA.TEK.COM
Lines: 1849
Approved: billr@saab.CNA.TEK.COM
Submitted-by: cracraft@rice-chex.ai.mit.edu (Stuart Cracraft)
Posting-number: Volume 13, Issue 96
Archive-name: gnuchess4/Part08
Supersedes: gnuchess2: Volume 4, Issue 37-40
Environment:
#! /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 8 (of 12)."
# Contents: doc/COPYING doc/TODO src/gnuan.c src/init.c
# Wrapped by billr@saab on Fri Jun 19 08:36:02 1992
PATH=/bin:/usr/bin:/usr/ucb ; export PATH
if test -f 'doc/COPYING' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'doc/COPYING'\"
else
echo shar: Extracting \"'doc/COPYING'\" \(17976 characters\)
sed "s/^X//" >'doc/COPYING' <<'END_OF_FILE'
X GNU GENERAL PUBLIC LICENSE
X Version 2, June 1991
X
X Copyright (C) 1989, 1991 Free Software Foundation, Inc.
X 675 Mass Ave, Cambridge, MA 02139, USA
X Everyone is permitted to copy and distribute verbatim copies
X of this license document, but changing it is not allowed.
X
X Preamble
X
X The licenses for most software are designed to take away your
Xfreedom to share and change it. By contrast, the GNU General Public
XLicense is intended to guarantee your freedom to share and change free
Xsoftware--to make sure the software is free for all its users. This
XGeneral Public License applies to most of the Free Software
XFoundation's software and to any other program whose authors commit to
Xusing it. (Some other Free Software Foundation software is covered by
Xthe GNU Library General Public License instead.) You can apply it to
Xyour programs, too.
X
X When we speak of free software, we are referring to freedom, not
Xprice. Our General Public Licenses are designed to make sure that you
Xhave the freedom to distribute copies of free software (and charge for
Xthis service if you wish), that you receive source code or can get it
Xif you want it, that you can change the software or use pieces of it
Xin new free programs; and that you know you can do these things.
X
X To protect your rights, we need to make restrictions that forbid
Xanyone to deny you these rights or to ask you to surrender the rights.
XThese restrictions translate to certain responsibilities for you if you
Xdistribute copies of the software, or if you modify it.
X
X For example, if you distribute copies of such a program, whether
Xgratis or for a fee, you must give the recipients all the rights that
Xyou have. You must make sure that they, too, receive or can get the
Xsource code. And you must show them these terms so they know their
Xrights.
X
X We protect your rights with two steps: (1) copyright the software, and
X(2) offer you this license which gives you legal permission to copy,
Xdistribute and/or modify the software.
X
X Also, for each author's protection and ours, we want to make certain
Xthat everyone understands that there is no warranty for this free
Xsoftware. If the software is modified by someone else and passed on, we
Xwant its recipients to know that what they have is not the original, so
Xthat any problems introduced by others will not reflect on the original
Xauthors' reputations.
X
X Finally, any free program is threatened constantly by software
Xpatents. We wish to avoid the danger that redistributors of a free
Xprogram will individually obtain patent licenses, in effect making the
Xprogram proprietary. To prevent this, we have made it clear that any
Xpatent must be licensed for everyone's free use or not licensed at all.
X
X The precise terms and conditions for copying, distribution and
Xmodification follow.
X
X GNU GENERAL PUBLIC LICENSE
X TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
X
X 0. This License applies to any program or other work which contains
Xa notice placed by the copyright holder saying it may be distributed
Xunder the terms of this General Public License. The "Program", below,
Xrefers to any such program or work, and a "work based on the Program"
Xmeans either the Program or any derivative work under copyright law:
Xthat is to say, a work containing the Program or a portion of it,
Xeither verbatim or with modifications and/or translated into another
Xlanguage. (Hereinafter, translation is included without limitation in
Xthe term "modification".) Each licensee is addressed as "you".
X
XActivities other than copying, distribution and modification are not
Xcovered by this License; they are outside its scope. The act of
Xrunning the Program is not restricted, and the output from the Program
Xis covered only if its contents constitute a work based on the
XProgram (independent of having been made by running the Program).
XWhether that is true depends on what the Program does.
X
X 1. You may copy and distribute verbatim copies of the Program's
Xsource code as you receive it, in any medium, provided that you
Xconspicuously and appropriately publish on each copy an appropriate
Xcopyright notice and disclaimer of warranty; keep intact all the
Xnotices that refer to this License and to the absence of any warranty;
Xand give any other recipients of the Program a copy of this License
Xalong with the Program.
X
XYou may charge a fee for the physical act of transferring a copy, and
Xyou may at your option offer warranty protection in exchange for a fee.
X
X 2. You may modify your copy or copies of the Program or any portion
Xof it, thus forming a work based on the Program, and copy and
Xdistribute such modifications or work under the terms of Section 1
Xabove, provided that you also meet all of these conditions:
X
X a) You must cause the modified files to carry prominent notices
X stating that you changed the files and the date of any change.
X
X b) You must cause any work that you distribute or publish, that in
X whole or in part contains or is derived from the Program or any
X part thereof, to be licensed as a whole at no charge to all third
X parties under the terms of this License.
X
X c) If the modified program normally reads commands interactively
X when run, you must cause it, when started running for such
X interactive use in the most ordinary way, to print or display an
X announcement including an appropriate copyright notice and a
X notice 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 this
X License. (Exception: if the Program itself is interactive but
X does not normally print such an announcement, your work based on
X the Program is not required to print an announcement.)
X
XThese requirements apply to the modified work as a whole. If
Xidentifiable sections of that work are not derived from the Program,
Xand can be reasonably considered independent and separate works in
Xthemselves, then this License, and its terms, do not apply to those
Xsections when you distribute them as separate works. But when you
Xdistribute the same sections as part of a whole which is a work based
Xon the Program, the distribution of the whole must be on the terms of
Xthis License, whose permissions for other licensees extend to the
Xentire whole, and thus to each and every part regardless of who wrote it.
X
XThus, it is not the intent of this section to claim rights or contest
Xyour rights to work written entirely by you; rather, the intent is to
Xexercise the right to control the distribution of derivative or
Xcollective works based on the Program.
X
XIn addition, mere aggregation of another work not based on the Program
Xwith the Program (or with a work based on the Program) on a volume of
Xa storage or distribution medium does not bring the other work under
Xthe scope of this License.
X
X 3. You may copy and distribute the Program (or a work based on it,
Xunder Section 2) in object code or executable form under the terms of
XSections 1 and 2 above provided that you also do one of the following:
X
X a) Accompany it with the complete corresponding machine-readable
X source code, which must be distributed under the terms of Sections
X 1 and 2 above on a medium customarily used for software interchange; or,
X
X b) Accompany it with a written offer, valid for at least three
X years, to give any third party, for a charge no more than your
X cost of physically performing source distribution, a complete
X machine-readable copy of the corresponding source code, to be
X distributed under the terms of Sections 1 and 2 above on a medium
X customarily used for software interchange; or,
X
X c) Accompany it with the information you received as to the offer
X to distribute corresponding source code. (This alternative is
X allowed only for noncommercial distribution and only if you
X received the program in object code or executable form with such
X an offer, in accord with Subsection b above.)
X
XThe source code for a work means the preferred form of the work for
Xmaking modifications to it. For an executable work, complete source
Xcode means all the source code for all modules it contains, plus any
Xassociated interface definition files, plus the scripts used to
Xcontrol compilation and installation of the executable. However, as a
Xspecial exception, the source code distributed need not include
Xanything that is normally distributed (in either source or binary
Xform) with the major components (compiler, kernel, and so on) of the
Xoperating system on which the executable runs, unless that component
Xitself accompanies the executable.
X
XIf distribution of executable or object code is made by offering
Xaccess to copy from a designated place, then offering equivalent
Xaccess to copy the source code from the same place counts as
Xdistribution of the source code, even though third parties are not
Xcompelled to copy the source along with the object code.
X
X 4. You may not copy, modify, sublicense, or distribute the Program
Xexcept as expressly provided under this License. Any attempt
Xotherwise to copy, modify, sublicense or distribute the Program is
Xvoid, and will automatically terminate your rights under this License.
XHowever, parties who have received copies, or rights, from you under
Xthis License will not have their licenses terminated so long as such
Xparties remain in full compliance.
X
X 5. You are not required to accept this License, since you have not
Xsigned it. However, nothing else grants you permission to modify or
Xdistribute the Program or its derivative works. These actions are
Xprohibited by law if you do not accept this License. Therefore, by
Xmodifying or distributing the Program (or any work based on the
XProgram), you indicate your acceptance of this License to do so, and
Xall its terms and conditions for copying, distributing or modifying
Xthe Program or works based on it.
X
X 6. Each time you redistribute the Program (or any work based on the
XProgram), the recipient automatically receives a license from the
Xoriginal licensor to copy, distribute or modify the Program subject to
Xthese terms and conditions. You may not impose any further
Xrestrictions on the recipients' exercise of the rights granted herein.
XYou are not responsible for enforcing compliance by third parties to
Xthis License.
X
X 7. If, as a consequence of a court judgment or allegation of patent
Xinfringement or for any other reason (not limited to patent issues),
Xconditions are imposed on you (whether by court order, agreement or
Xotherwise) that contradict the conditions of this License, they do not
Xexcuse you from the conditions of this License. If you cannot
Xdistribute so as to satisfy simultaneously your obligations under this
XLicense and any other pertinent obligations, then as a consequence you
Xmay not distribute the Program at all. For example, if a patent
Xlicense would not permit royalty-free redistribution of the Program by
Xall those who receive copies directly or indirectly through you, then
Xthe only way you could satisfy both it and this License would be to
Xrefrain entirely from distribution of the Program.
X
XIf any portion of this section is held invalid or unenforceable under
Xany particular circumstance, the balance of the section is intended to
Xapply and the section as a whole is intended to apply in other
Xcircumstances.
X
XIt is not the purpose of this section to induce you to infringe any
Xpatents or other property right claims or to contest validity of any
Xsuch claims; this section has the sole purpose of protecting the
Xintegrity of the free software distribution system, which is
Ximplemented by public license practices. Many people have made
Xgenerous contributions to the wide range of software distributed
Xthrough that system in reliance on consistent application of that
Xsystem; it is up to the author/donor to decide if he or she is willing
Xto distribute software through any other system and a licensee cannot
Ximpose that choice.
X
XThis section is intended to make thoroughly clear what is believed to
Xbe a consequence of the rest of this License.
X
X 8. If the distribution and/or use of the Program is restricted in
Xcertain countries either by patents or by copyrighted interfaces, the
Xoriginal copyright holder who places the Program under this License
Xmay add an explicit geographical distribution limitation excluding
Xthose countries, so that distribution is permitted only in or among
Xcountries not thus excluded. In such case, this License incorporates
Xthe limitation as if written in the body of this License.
X
X 9. The Free Software Foundation may publish revised and/or new versions
Xof the General Public License from time to time. Such new versions will
Xbe similar in spirit to the present version, but may differ in detail to
Xaddress new problems or concerns.
X
XEach version is given a distinguishing version number. If the Program
Xspecifies a version number of this License which applies to it and "any
Xlater version", you have the option of following the terms and conditions
Xeither of that version or of any later version published by the Free
XSoftware Foundation. If the Program does not specify a version number of
Xthis License, you may choose any version ever published by the Free Software
XFoundation.
X
X 10. If you wish to incorporate parts of the Program into other free
Xprograms whose distribution conditions are different, write to the author
Xto ask for permission. For software which is copyrighted by the Free
XSoftware Foundation, write to the Free Software Foundation; we sometimes
Xmake exceptions for this. Our decision will be guided by the two goals
Xof preserving the free status of all derivatives of our free software and
Xof promoting the sharing and reuse of software generally.
X
X NO WARRANTY
X
X 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
XFOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
XOTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
XPROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
XOR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
XMERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
XTO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
XPROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
XREPAIR OR CORRECTION.
X
X 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
XWILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
XREDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
XINCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
XOUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
XTO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
XYOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
XPROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
XPOSSIBILITY OF SUCH DAMAGES.
X
X END OF TERMS AND CONDITIONS
X
X How to Apply These Terms to Your New Programs
X
X If you develop a new program, and you want it to be of the greatest
Xpossible use to the public, the best way to achieve this is to make it
Xfree software which everyone can redistribute and change under these terms.
X
X To do so, attach the following notices to the program. It is safest
Xto attach them to the start of each source file to most effectively
Xconvey the exclusion of warranty; and each file should have at least
Xthe "copyright" line and a pointer to where the full notice is found.
X
X <one line to give the program's name and a brief idea of what it does.>
X Copyright (C) 19yy <name of author>
X
X This program is free software; you can redistribute it and/or modify
X it under the terms of the GNU General Public License as published by
X the Free Software Foundation; either version 2 of the License, or
X (at your option) any later version.
X
X This program is distributed in the hope that it will be useful,
X but WITHOUT ANY WARRANTY; without even the implied warranty of
X MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
X GNU General Public License for more details.
X
X You should have received a copy of the GNU General Public License
X along with this program; if not, write to the Free Software
X Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
X
XAlso add information on how to contact you by electronic and paper mail.
X
XIf the program is interactive, make it output a short notice like this
Xwhen it starts in an interactive mode:
X
X Gnomovision version 69, Copyright (C) 19yy name of author
X Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
X This is free software, and you are welcome to redistribute it
X under certain conditions; type `show c' for details.
X
XThe hypothetical commands `show w' and `show c' should show the appropriate
Xparts of the General Public License. Of course, the commands you use may
Xbe called something other than `show w' and `show c'; they could even be
Xmouse-clicks or menu items--whatever suits your program.
X
XYou should also get your employer (if you work as a programmer) or your
Xschool, if any, to sign a "copyright disclaimer" for the program, if
Xnecessary. Here is a sample; alter the names:
X
X Yoyodyne, Inc., hereby disclaims all copyright interest in the program
X `Gnomovision' (which makes passes at compilers) written by James Hacker.
X
X <signature of Ty Coon>, 1 April 1989
X Ty Coon, President of Vice
X
XThis General Public License does not permit incorporating your program into
Xproprietary programs. If your program is a subroutine library, you may
Xconsider it more useful to permit linking proprietary applications with the
Xlibrary. If this is what you want to do, use the GNU Library General
XPublic License instead of this License.
END_OF_FILE
if test 17976 -ne `wc -c <'doc/COPYING'`; then
echo shar: \"'doc/COPYING'\" unpacked with wrong size!
fi
# end of 'doc/COPYING'
fi
if test -f 'doc/TODO' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'doc/TODO'\"
else
echo shar: Extracting \"'doc/TODO'\" \(1459 characters\)
sed "s/^X//" >'doc/TODO' <<'END_OF_FILE'
XFixup the dos makefile and check it out on dos.
X
Xallow shortend algebraic moves in book.
XRemove opening lines gnuchess doesn't play well.
X
XThe hint problem. If the hint is a promotion move easy mode
Xdoesnt work right. It is currently bypassed in this case.
XSearch doesn't save the fact its a promotion move in the
XPV. So hint and post only show the move without the piece
Xbeing promoted to. Cannot do easy mode off, because it must
Xknow the piece being promoted to. Somehow should save it in PV.
XAlso true for hashtable entries. flags are not saved they should
Xbe.
X
XSomething is wrong with the time calculation, sometimes the number
Xof moves to the next time control is set to -1.
X1. e4 d6 2. d4 Nf6 3. white go make this happen.
X
XMake the timing function more flexible.
XI would like to be able to have n time controls all different.
XI would like to include the Fischer clock.
XMake the timing function smarter.
XAllow extra time whenever the score is changing a lot
XUse the current depth as a parameter.
X(the closer to zero it start the more a change should count)
XIf the opponent seem to have made a blunder it might be a trap.
XIf gnuchess is getting behind there might be a way out. (try to find it)
X
XAdd languages to the language file.
X
XImprove performace by modifying the search extension logic.
X
XMake the hash table include castling flags + ep flag.
XCurrently only the transposition file include any of these and
Xthen only castling for the side to move.
END_OF_FILE
if test 1459 -ne `wc -c <'doc/TODO'`; then
echo shar: \"'doc/TODO'\" unpacked with wrong size!
fi
# end of 'doc/TODO'
fi
if test -f 'src/gnuan.c' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'src/gnuan.c'\"
else
echo shar: Extracting \"'src/gnuan.c'\" \(20399 characters\)
sed "s/^X//" >'src/gnuan.c' <<'END_OF_FILE'
X/*
X * gnuan.c - Analysis interface for gnuchess.
X *
X * Copyright (c) 1988,1989,1990 John Stanback
X * Copyright (c) 1992 Free Software Foundation
X *
X * This file is part of GNU CHESS.
X *
X * GNU Chess is free software; you can redistribute it and/or modify
X * it under the terms of the GNU General Public License as published by
X * the Free Software Foundation; either version 2, or (at your option)
X * any later version.
X *
X * GNU Chess is distributed in the hope that it will be useful,
X * but WITHOUT ANY WARRANTY; without even the implied warranty of
X * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
X * GNU General Public License for more details.
X *
X * You should have received a copy of the GNU General Public License
X * along with GNU Chess; see the file COPYING. If not, write to
X * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
X */
X
X/*
X * This is a front end for a chess analysis program. It takes a file of
X * moves in algebraic notation and creates a file containing each move that
X * was made, the move it would have made, the score it would give itself
X * after making the move it recommended, and the depth it searched for the
X * move.
X *
X * This is a modification of nondsp.c. I have cut out code that was not needed
X * for this application such as the help and edit functions. Most of the
X * modifications were done in InputCommand.
X */
X
X/*
X * This file will generate two different analysis programs. One is meant to
X * be run as a background process inwhich the in and out files are
X * predefined. The other is meant to be run in the foreground where it will
X * prompt you for the name of the file with the game in it, the maximum depth
X * the search should be conducted to and the time limit per move. It would
X * be nice to be able to give these parameters on the command line, but that
X * would mean changing main which is in the gnuchess.c file.
X *
X * For each move it will analyse the move until either it has run out of time or
X * it has reached the maximum depth.
X *
X * To build the version for background processing define BACKGROUND_ANALYSIS
X * either at the top of this file, or in compilation. The files and depth
X * used are defined below. They are MAX_DEPTH, MAX_TIME, OUT_FILE, IN_FILE
X * and PROG_FILE. The PROG_FILE is a file that will be updated as each move
X * is analysed so you can check its progress. This is only updated when
X * running the BACKGROUND_ANALYSIS version. In the version where the
X * filename and depth are entered at runtime, the output goes to stdout.
X */
X
X/* #define BACKGROUND_ANALYSIS 1 */
X
X#define MAX_DEPTH 15
X#define MAX_TIME 20
X#define OUT_FILE "/pad/gnuan.out"
X#define IN_FILE "/pad/gnuan.in"
X#define PROG_FILE "/pad/gnuan.prog"
X
X
X#include <ctype.h>
X#include <signal.h>
X#ifdef MSDOS
X#include <dos.h>
X#include <conio.h>
X#include <stdlib.h>
X#include <string.h>
X#include <time.h>
X#else
X#include <sys/param.h>
X#include <sys/types.h>
X#include <sys/file.h>
X#include <sys/ioctl.h>
Xvoid TerminateSearch (int), Die (int);
X
X#endif /* MSDOS */
X
X#include "gnuchess.h"
X#include "ataks.h"
X#undef rxx
X#undef cxx
X#undef scanz
X#undef printz
X
X#define rxx "12345678"
X#define cxx "abcdefgh"
X#define scanz scanf
X#define printz printf
X
Xchar mvstr[4][6];
Xchar *ColorStr[2] =
X{"White", "Black"};
Xint mycnt1, mycnt2;
X
Xstatic FILE *fpin;
Xstatic FILE *fpout;
Xchar *DRAW;
Xunsigned short int MV[MAXDEPTH];
Xenum
X{
X XBOARD, GNUCHESS, OTHER
X} InFileType;
Xchar InBuf[256];
X
X#ifdef BACKGROUND_ANALYSIS
Xstatic FILE *fpprog;
X
X#endif
Xstatic char white_actual_move[20];
Xstatic char black_actual_move[20];
Xstatic char white_suggest_move[20];
Xstatic char black_suggest_move[20];
Xstatic int white_score;
Xstatic int black_score;
Xstatic int white_moving;
Xstatic int current_depth;
Xstatic int current_score;
Xstatic int enable_update_display = 0;
X
X
Xvoid
XInitialize (void)
X{
X mycnt1 = mycnt2 = 0;
X}
X
Xvoid
XExitChess (void)
X{
X ListGame ();
X exit (0);
X}
X
X#ifndef MSDOS /* never called!!! */
Xvoid
XDie (int sig)
X{
X ExitChess ();
X}
X
X#endif /* MSDOS */
X
Xvoid
XTerminateSearch (int sig)
X{
X#ifdef MSDOS
X sig++; /* shut up the compiler */
X#endif /* MSDOS */
X if (!flag.timeout)
X flag.musttimeout = true;
X flag.bothsides = false;
X}
X
Xvoid
Xalgbr (short int f, short int t, short int flag)
X
X/*
X * Generate move strings in different formats.
X */
X
X{
X int m3p;
X
X if (f != t)
X {
X /* algebraic notation */
X mvstr[0][0] = cxx[column (f)];
X mvstr[0][1] = rxx[row (f)];
X mvstr[0][2] = cxx[column (t)];
X mvstr[0][3] = rxx[row (t)];
X mvstr[0][4] = mvstr[3][0] = '\0';
X if (((mvstr[1][0] = pxx[board[f]]) == 'P') || (flag & promote))
X {
X if (mvstr[0][0] == mvstr[0][2]) /* pawn did not eat */
X {
X mvstr[2][0] = mvstr[1][0] = mvstr[0][2]; /* to column */
X mvstr[2][1] = mvstr[1][1] = mvstr[0][3]; /* to row */
X m3p = 2;
X }
X else
X /* pawn ate */
X {
X mvstr[2][0] = mvstr[1][0] = mvstr[0][0]; /* from column */
X mvstr[2][1] = mvstr[1][1] = mvstr[0][2]; /* to column */
X mvstr[2][2] = mvstr[0][3];
X m3p = 3; /* to row */
X }
X mvstr[2][m3p] = mvstr[1][2] = '\0';
X if (flag & promote)
X {
X mvstr[0][4] = mvstr[1][2] = mvstr[2][m3p] = qxx[flag & pmask];
X mvstr[1][3] = mvstr[2][m3p + 1] = mvstr[0][5] = '\0';
X }
X }
X else
X /* not a pawn */
X {
X mvstr[2][0] = mvstr[1][0];
X mvstr[2][1] = mvstr[0][1];
X mvstr[2][2] = mvstr[1][1] = mvstr[0][2]; /* to column */
X mvstr[2][3] = mvstr[1][2] = mvstr[0][3]; /* to row */
X mvstr[2][4] = mvstr[1][3] = '\0';
X strcpy (mvstr[3], mvstr[2]);
X mvstr[3][1] = mvstr[0][0];
X if (flag & cstlmask)
X {
X if (t > f)
X {
X strcpy (mvstr[1], "o-o");
X strcpy (mvstr[2], "O-O");
X }
X else
X {
X strcpy (mvstr[1], "o-o-o");
X strcpy (mvstr[2], "O-O-O");
X }
X }
X }
X }
X else
X mvstr[0][0] = mvstr[1][0] = mvstr[2][0] = mvstr[3][0] = '\0';
X}
X
X
Xint
XVerifyMove (char *s, short int iop, unsigned short int *mv)
X
X/*
X * Compare the string 's' to the list of legal moves available for the
X * opponent. If a match is found, make the move on the board.
X */
X
X{
X static short pnt, tempb, tempc, tempsf, tempst, cnt;
X static struct leaf xnode;
X struct leaf *node;
X
X *mv = 0;
X if (iop == 2)
X {
X UnmakeMove (opponent, &xnode, &tempb, &tempc, &tempsf, &tempst);
X return (false);
X }
X cnt = 0;
X MoveList (opponent, 2);
X pnt = TrPnt[2];
X while (pnt < TrPnt[3])
X {
X node = &Tree[pnt++];
X algbr (node->f, node->t, (short) node->flags);
X if (strcmp (s, mvstr[0]) == 0 || strcmp (s, mvstr[1]) == 0 ||
X strcmp (s, mvstr[2]) == 0 || strcmp (s, mvstr[3]) == 0)
X {
X cnt++;
X xnode = *node;
X }
X }
X if (cnt == 1)
X {
X MakeMove (opponent, &xnode, &tempb, &tempc, &tempsf, &tempst, &INCscore);
X if (SqAtakd (PieceList[opponent][0], computer))
X {
X UnmakeMove (opponent, &xnode, &tempb, &tempc, &tempsf, &tempst);
X printz ("Illegal move\n");
X return (false);
X }
X else
X {
X if (iop == 1)
X return (true);
X
X /*
X * UpdateDisplay (xnode.f, xnode.t, 0, (short) xnode.flags);
X */
X if ((board[xnode.t] == pawn)
X || (xnode.flags & capture)
X || (xnode.flags & cstlmask))
X {
X Game50 = GameCnt;
X ZeroRPT ();
X }
X GameList[GameCnt].depth = GameList[GameCnt].score = 0;
X GameList[GameCnt].nodes = 0;
X ElapsedTime (1);
X GameList[GameCnt].time = (short) et;
X TimeControl.clock[opponent] -= et;
X --TimeControl.moves[opponent];
X *mv = (xnode.f << 8) | xnode.t;
X algbr (xnode.f, xnode.t, false);
X return (true);
X }
X }
X#ifdef CHESSTOOL
X printz ("Illegal move\n");
X#else
X if (cnt > 1)
X ShowMessage ("Ambiguous Move!");
X#endif
X return (false);
X}
X
Xvoid
Xhelp (void)
X{
X}
X
Xvoid
XEditBoard (void)
X
X/*
X * Set up a board position. Pieces are entered by typing the piece followed
X * by the location. For example, Nf3 will place a knight on square f3.
X */
X
X{
X}
X
Xvoid
XSetupBoard (void)
X
X/*
X * Compatibility with Unix chess and the nchesstool. Set up a board position.
X * Eight lines of eight characters are used to setup the board. a8-h8 is the
X * first line. Black pieces are represented by uppercase characters.
X */
X
X{
X}
X
Xvoid
XShowDepth (char ch)
X{
X#ifdef MSDOS
X ch++; /* shut up the compiler */
X#endif /* MSDOS */
X}
X
Xvoid
XShowResults (short int score, unsigned short int *bstline, char ch)
X{
X int i;
X
X current_score = score;
X current_depth = Sdepth;
X for (i = 1; bstline[i] > 0; i++)
X {
X MV[i] = bstline[i];
X } MV[i] = 0;
X}
X
Xvoid
XSearchStartStuff (short int side)
X{
X signal (SIGINT, TerminateSearch);
X#ifndef MSDOS
X signal (SIGQUIT, TerminateSearch);
X#endif /* MSDOS */
X if (flag.post)
X {
X fprintf (stderr, "\nMove# %d Target= %ld Clock: %ld\n",
X TCmoves - TimeControl.moves[side] + 1,
X ResponseTime, TimeControl.clock[side]);
X }
X}
X
Xvoid
XOutputMove (void)
X{
X if (white_moving)
X {
X strcpy (white_suggest_move, mvstr[0]);
X white_score = current_score;
X }
X else
X {
X strcpy (black_suggest_move, mvstr[0]);
X black_score = current_score;
X }
X}
X
Xvoid
XElapsedTime (short int iop)
X
X/*
X * Determine the time that has passed since the search was started. If the
X * elapsed time exceeds the target (ResponseTime+ExtraTime) then set timeout
X * to true which will terminate the search.
X */
X{
X if (ahead)
X {
X#ifndef MSDOS
X#ifdef FIONREAD
X long nchar;
X
X ioctl (0, FIONREAD, &nchar);
X if (nchar)
X {
X flag.timeout = true;
X flag.bothsides = false;
X }
X#endif
X#else
X if (kbhit ())
X {
X flag.timeout = true;
X flag.bothsides = false;
X }
X#endif /* MSDOS */
X }
X et = (time ((long *) 0) - time0) * 100;
X if (et < 0)
X et = 0;
X ETnodes += ZNODES;
X if (iop == 1)
X {
X if (et > ResponseTime + ExtraTime && Sdepth > 1)
X flag.timeout = true;
X time0 = time ((long *) 0);
X ETnodes = NodeCnt + ZNODES;
X }
X}
X
Xvoid
XSetTimeControl (void)
X{
X if (TCflag)
X {
X TimeControl.moves[white] = TimeControl.moves[black] = TCmoves;
X TimeControl.clock[white] = TimeControl.clock[black] = 6000L * TCminutes;
X }
X else
X {
X TimeControl.moves[white] = TimeControl.moves[black] = 0;
X TimeControl.clock[white] = TimeControl.clock[black] = 0;
X Level = 600000L * TCminutes;
X }
X et = 0;
X ElapsedTime (1);
X}
X
Xvoid
XClrScreen (void)
X{
X#ifndef CHESSTOOL
X printz ("\n");
X#endif
X}
X
Xvoid
XUpdateDisplay (short int f, short int t, short int redraw, short int isspec)
X{
X#ifndef CHESSTOOL
X short r, c, l;
X
X if (!enable_update_display)
X return;
X if (redraw)
X {
X fprintf (fpout, "\n");
X for (r = 7; r >= 0; r--)
X {
X for (c = 0; c <= 7; c++)
X {
X l = locn (r, c);
X if (color[l] == neutral)
X fprintf (fpout, " -");
X else if (color[l] == white)
X fprintf (fpout, " %c", qxx[board[l]]);
X else
X fprintf (fpout, " %c", pxx[board[l]]);
X }
X fprintf (fpout, "\n");
X }
X fprintf (fpout, "\n");
X }
X#endif /* CHESSTOOL */
X#ifdef MSDOS
X f++;
X t++;
X isspec++; /* shut up the compiler */
X#endif /* MSDOS */
X}
X
Xvoid
XGetGame (void)
X{
X}
X
Xvoid
XSaveGame (void)
X{
X}
X
Xvoid
XListGame (void)
X{
X}
X
X
X
Xvoid
XUndo (void)
X
X/*
X * Undo the most recent half-move.
X */
X
X{
X short f, t;
X
X f = GameList[GameCnt].gmove >> 8;
X t = GameList[GameCnt].gmove & 0xFF;
X if (board[t] == king && distance (t, f) > 1)
X (void) castle (GameList[GameCnt].color, f, t, 2);
X else
X {
X /* Check for promotion: */
X if (GameList[GameCnt].flags & promote)
X {
X board[t] = pawn;
X }
X board[f] = board[t];
X color[f] = color[t];
X board[t] = GameList[GameCnt].piece;
X color[t] = GameList[GameCnt].color;
X if (color[t] != neutral)
X Mvboard[t]--;
X Mvboard[f]--;
X }
X if (GameList[GameCnt].flags & epmask)
X EnPassant (color[t], f, t, 2);
X if (TCflag)
X ++TimeControl.moves[color[f]];
X GameCnt--;
X computer = otherside[computer];
X opponent = otherside[opponent];
X flag.mate = false;
X Sdepth = 0;
X InitializeStats ();
X}
X
Xvoid
XShowMessage (char *s)
X{
X fprintf (stderr, "%s\n", s);
X}
X
Xvoid
XShowSidetoMove (void)
X{
X}
X
Xvoid
XPromptForMove (void)
X{
X#ifndef CHESSTOOL
X printz ("\nYour move is? ");
X#endif /* CHESSTOOL */
X}
X
X
Xvoid
XShowCurrentMove (short int pnt, short int f, short int t)
X{
X#ifdef MSDOS
X f++;
X t++;
X pnt++; /* shut up the compiler */
X#endif /* MSDOS */
X}
X
Xvoid
XChangeAlphaWindow (void)
X{
X printz ("window: ");
X}
X
Xvoid
XChangeBetaWindow (void)
X{
X printz ("window: ");
X}
X
Xvoid
XGiveHint (void)
X{
X algbr ((short) (hint >> 8), (short) (hint & 0xFF), false);
X fprintf (stderr, "Hint: %s\n", mvstr[0]);
X}
X
Xvoid
XSelectLevel (void)
X{
X}
X
Xvoid
XChangeSearchDepth (void)
X{
X printz ("depth= ");
X scanz ("%hd", &MaxSearchDepth);
X}
X
Xvoid
XSetContempt (void)
X{
X printz ("contempt= ");
X scanz ("%hd", &contempt);
X}
X
Xvoid
XChangeXwindow (void)
X{
X printz ("xwndw= ");
X scanz ("%hd", &xwndw);
X}
X
Xvoid
XTestSpeed (void (*f) (short int side, short int ply))
X{
X short i;
X long cnt, rate, t1, t2;
X
X t1 = time (0);
X for (i = 0; i < 10000; i++)
X {
X f (opponent, 2);
X }
X t2 = time (0);
X cnt = 10000L * (TrPnt[3] - TrPnt[2]);
X rate = cnt / (t2 - t1);
X printz ("Nodes= %ld Nodes/sec= %ld\n", cnt, rate);
X}
X
X
Xint
XGetNextMove (char *buffer)
X{
X char current;
X
X while (true)
X {
X while ((current = fgetc (fpin)) == ' ' || current == '\n') ;
X if ((current != EOF) && (isdigit (current) || current == '-'))
X {
X while ((current = fgetc (fpin)) != ' ' && current != EOF) ;
X if (current == EOF)
X return 0;
X else
X continue;
X }
X if (current == EOF)
X return (0);
X while (current != ' ' && current != '\n' && current != EOF)
X {
X if (!(current == '-' || current == 'x' || current == 'X'))
X {
X *buffer++ = current;
X }
X current = fgetc (fpin);
X }
X *buffer = '\0';
X return (1);
X }
X}
X
Xvoid
XInputCommand (void)
X
X/*
X * Open the file of moves to analyse. Go through the file move by move and
X * do the following for each move. See what gnuchess would have done in that
X * position. Record the move it would have made along with the score it
X * would have given and the search depth. Take back its move. Force the move
X * that was actually made. Keep track of statistics such as how many moves
X * agreed.
X */
X
X{
X int i;
X short ok, tmp;
X int search_depth, max_minutes;
X long cnt, rate, t1, t2;
X unsigned short mv;
X char s[80];
X char infilename[255];
X char outfilename[255];
X char progfilename[255];
X char inbuf[256];
X int move_number = 1;
X long start_time, end_time, elapsed_time;
X int total_black_moves, total_white_moves;
X int same_black_moves, same_white_moves;
X float white_percent, black_percent;
X
X /* Initialize necessary variables. */
X
X flag.quit = false;
X flag.beep = false;
X player = opponent;
X enable_update_display = 1;
X ft = 0;
X Book = NULL;
X total_black_moves = 0;
X total_white_moves = 0;
X same_black_moves = 0;
X same_white_moves = 0;
X
X#ifdef BACKGROUND_ANALYSIS
X
X /*
X * Set the in files to standard ones for analysis if background
X * processing selected.
X */
X
X strcpy (infilename, IN_FILE);
X strcpy (outfilename, OUT_FILE);
X strcpy (progfilename, PROG_FILE);
X fpout = fopen (outfilename, "w");
X if (fpout == NULL)
X {
X fprintf (fpout, "This file does not exist : %s\n", outfilename);
X flag.quit = 1;
X return;
X }
X MaxSearchDepth = MAX_DEPTH;
X TCminutes = MAX_TIME;
X
X#else
X
X /* Request information on where the file is and the depth an time. */
X
X fpout = stderr;
X fprintf (fpout, "Input the file with the algebraic moves of the game.\n");
X gets (infilename);
X fprintf (fpout, "\n");
X do
X {
X fprintf (fpout, "Input the search depth you want to use. (1 to 29)\n");
X gets (inbuf);
X search_depth = atoi (inbuf);
X } while (search_depth < 1 || search_depth > 29);
X MaxSearchDepth = search_depth;
X
X fprintf (fpout, "\n");
X do
X {
X fprintf (fpout, "Input the maximum number of minutes per move you want to use.\n");
X gets (inbuf);
X max_minutes = atoi (inbuf);
X } while (max_minutes < 1);
X printf ("%d %d \n", search_depth, max_minutes);
X TCminutes = max_minutes;
X
X fprintf (fpout, "\n\n");
X
X#endif
X
X fpin = fopen (infilename, "r");
X if (fpin == NULL)
X {
X fprintf (fpout, "This file does not exist : %s\n", infilename);
X flag.quit = 1;
X return;
X }
X /* lets find out about this file */
X fgets (InBuf, 256, fpin);
X InFileType = OTHER;
X if (!strncmp (InBuf, "xboard", 6))
X {
X InFileType = XBOARD;
X fgets (InBuf, 256, fpin);
X fgets (InBuf, 256, fpin);
X }
X else if (!strncmp (InBuf, "gnuchess", 6))
X {
X InFileType = GNUCHESS;
X fgets (InBuf, 256, fpin);
X }
X else
X rewind (fpin);
X TCmoves = 1;
X TCflag = (TCmoves > 1);
X OperatorTime = 0;
X SetTimeControl ();
X
X fpout = stdout;
X
X fprintf (fpout, "Move White Black Score Depth Best Line\n");
X fprintf (fpout, "------------------------------------------------------------------\n");
X
X#ifdef BACKGROUND_ANALYSIS
X
X /*
X * Update progress in the progress file if this is running in the
X * background.
X */
X
X fpprog = fopen (progfilename, "w");
X fprintf (fpprog, "Done with move #%d.\n", move_number - 1);
X fclose (fpprog);
X
X#endif
X
X time (&start_time);
X while (1)
X {
X opponent = black;
X computer = white;
X player = computer;
X white_moving = 1;
X if (!GetNextMove (s))
X {
X flag.quit = 1;
X break;
X }
X if (!strcmp (s, "Black") || !strcmp (s, "White") || !strcmp (s, "draw"))
X break;
X flag.force = 0;
X SelectMove (computer, 1);
X Undo ();
X flag.force = 1;
X opponent = white;
X computer = black;
X player = opponent;
X ok = VerifyMove (s, 0, &mv);
X if (!ok)
X {
X fprintf (fpout, "\nBad move. %s Board position is: \n", s);
X UpdateDisplay (0, 0, 1, 0);
X flag.quit = 1;
X break;
X }
X else
X {
X char ch, x[80];
X strcpy (white_actual_move, s);
X strcpy (x, white_actual_move);
X if (strcmp (white_actual_move, white_suggest_move))
X strcat (x, "*");
X fprintf (fpout, "%3d %-9s %5d%5d ", move_number, x, white_score, current_depth);
X for (i = 1; MV[i] > 0; i++)
X {
X algbr ((short) (MV[i] >> 8), (short) (MV[i] & 0xFF), false);
X printf ("%5s ", mvstr[0]);
X }
X printf ("\n");
X fflush (fpout);
X move_number++;
X total_white_moves++;
X if (!strcmp (white_actual_move, white_suggest_move))
X same_white_moves++;
X Sdepth = 0;
X ft = 0;
X }
X player = computer;
X white_moving = 0;
X if (!GetNextMove (s))
X {
X flag.quit = 1;
X break;
X }
X if (!strcmp (s, "Black") || !strcmp (s, "White") || !strcmp (s, "draw"))
X break;
X flag.force = 0;
X SelectMove (computer, 1);
X Undo ();
X flag.force = 1;
X opponent = black;
X computer = white;
X player = opponent;
X ok = VerifyMove (s, 0, &mv);
X if (!ok)
X {
X fprintf (fpout, "\nBad move. %s Board position is: \n", s);
X UpdateDisplay (0, 0, 1, 0);
X flag.quit = 1;
X break;
X }
X else
X {
X char x[8];
X strcpy (black_actual_move, s);
X strcpy (x, black_actual_move);
X if (strcmp (black_actual_move, black_suggest_move))
X strcat (x, "*");
X fprintf (fpout, " %-9s%5d%5d ", x, black_score, current_depth);
X for (i = 1; MV[i] > 0; i++)
X {
X algbr ((short) (MV[i] >> 8), (short) (MV[i] & 0xFF), false);
X printf ("%5s ", mvstr[0]);
X }
X printf ("\n");
X fflush (fpout);
X
X#ifdef BACKGROUND_ANALYSIS
X
X /*
X * Update progress in the progress file if this is running in the
X * background.
X */
X
X fpprog = fopen (progfilename, "w");
X fprintf (fpprog, "Done with move #%d.\n", move_number - 1);
X fclose (fpprog);
X#else
X
X /*
X * fprintf(stderr, "Done with move #%d.\n", move_number-1);
X */
X
X#endif
X
X total_black_moves++;
X if (!strcmp (black_actual_move, black_suggest_move))
X same_black_moves++;
X Sdepth = 0;
X ft = 0;
X }
X }
X
X white_percent = ((float) same_white_moves) * 100 / (float) total_white_moves;
X black_percent = ((float) same_black_moves) * 100 / (float) total_black_moves;
X fprintf (fpout, "\n White's percentage was %5.2f%%. Black's percentage was %5.2f%%.\n", white_percent, black_percent);
X time (&end_time);
X elapsed_time = end_time - start_time;
X fprintf (fpout, "\n Elapsed time was %d seconds.\n", elapsed_time);
X fclose (fpin);
X fclose (fpout);
X exit (0);
X}
END_OF_FILE
if test 20399 -ne `wc -c <'src/gnuan.c'`; then
echo shar: \"'src/gnuan.c'\" unpacked with wrong size!
fi
# end of 'src/gnuan.c'
fi
if test -f 'src/init.c' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'src/init.c'\"
else
echo shar: Extracting \"'src/init.c'\" \(11648 characters\)
sed "s/^X//" >'src/init.c' <<'END_OF_FILE'
X/*
X * init.c - C source for GNU CHESS
X *
X * Copyright (c) 1988,1989,1990 John Stanback
X * Copyright (c) 1992 Free Software Foundation
X *
X * This file is part of GNU CHESS.
X *
X * GNU Chess is free software; you can redistribute it and/or modify
X * it under the terms of the GNU General Public License as published by
X * the Free Software Foundation; either version 2, or (at your option)
X * any later version.
X *
X * GNU Chess is distributed in the hope that it will be useful,
X * but WITHOUT ANY WARRANTY; without even the implied warranty of
X * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
X * GNU General Public License for more details.
X *
X * You should have received a copy of the GNU General Public License
X * along with GNU Chess; see the file COPYING. If not, write to
X * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
X */
X#include "gnuchess.h"
X
X/* .... MOVE GENERATION VARIABLES AND INITIALIZATIONS .... */
X
X
Xshort distdata[64][64], taxidata[64][64];
X
X/* put moves to the center first */
Xvoid
XInitialize_killt (void)
X{
X register unsigned short f, t, s;
X register short d;
X for (f = 64; f--;)
X for (t = 64; t--;)
X {
X d = taxidata[f][0x1b];
X if (taxidata[f][0x1c] < d)
X d = taxidata[f][0x1c];
X if (taxidata[f][0x23] < d)
X d = taxidata[f][0x23];
X if (taxidata[f][0x24] < d)
X d = taxidata[f][0x24];
X s = d;
X d = taxidata[t][0x1b];
X if (taxidata[t][0x1c] < d)
X d = taxidata[t][0x1c];
X if (taxidata[t][0x23] < d)
X d = taxidata[t][0x23];
X if (taxidata[t][0x24] < d)
X d = taxidata[t][0x24];
X s -= d;
X killt[(f << 8) | t] = s;
X killt[(f << 8) | t | 0x80] = s;
X }
X}
X
Xvoid
XInitialize_dist (void)
X{
X register short a, b, d, di;
X
X for (a = 0; a < 64; a++)
X for (b = 0; b < 64; b++)
X {
X d = abs (column (a) - column (b));
X di = abs (row (a) - row (b));
X taxidata[a][b] = d + di;
X distdata[a][b] = (d > di ? d : di);
X }
X Initialize_killt ();
X}
X
Xconst short Stboard[64] =
X{rook, knight, bishop, queen, king, bishop, knight, rook,
X pawn, pawn, pawn, pawn, pawn, pawn, pawn, pawn,
X 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
X 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
X pawn, pawn, pawn, pawn, pawn, pawn, pawn, pawn,
X rook, knight, bishop, queen, king, bishop, knight, rook};
Xconst short Stcolor[64] =
X{white, white, white, white, white, white, white, white,
X white, white, white, white, white, white, white, white,
X neutral, neutral, neutral, neutral, neutral, neutral, neutral, neutral,
X neutral, neutral, neutral, neutral, neutral, neutral, neutral, neutral,
X neutral, neutral, neutral, neutral, neutral, neutral, neutral, neutral,
X neutral, neutral, neutral, neutral, neutral, neutral, neutral, neutral,
X black, black, black, black, black, black, black, black,
X black, black, black, black, black, black, black, black};
Xshort board[64], color[64];
X
X/* given epsquare, from where can a pawn be taken? */
Xconst short epmove1[64] =
X{0, 1, 2, 3, 4, 5, 6, 7,
X 8, 9, 10, 11, 12, 13, 14, 15,
X 16, 24, 25, 26, 27, 28, 29, 30,
X 24, 25, 26, 27, 28, 29, 30, 31,
X 32, 33, 34, 35, 36, 37, 38, 39,
X 40, 32, 33, 34, 35, 36, 37, 38,
X 48, 49, 50, 51, 52, 53, 54, 55,
X 56, 57, 58, 59, 60, 61, 62, 63};
Xconst short epmove2[64] =
X{0, 1, 2, 3, 4, 5, 6, 7,
X 8, 9, 10, 11, 12, 13, 14, 15,
X 25, 26, 27, 28, 29, 30, 31, 23,
X 24, 25, 26, 27, 28, 29, 30, 31,
X 32, 33, 34, 35, 36, 37, 38, 39,
X 33, 34, 35, 36, 37, 38, 39, 47,
X 48, 49, 50, 51, 52, 53, 54, 55,
X 56, 57, 58, 59, 60, 61, 62, 63};
X
X
X/*
X * nextpos[piece][from-square] , nextdir[piece][from-square] gives vector of
X * positions reachable from from-square in ppos with piece such that the
X * sequence ppos = nextpos[piece][from-square]; pdir =
X * nextdir[piece][from-square]; u = ppos[sq]; do { u = ppos[u]; if(color[u]
X * != neutral) u = pdir[u]; } while (sq != u); will generate the sequence of
X * all squares reachable from sq.
X *
X * If the path is blocked u = pdir[sq] will generate the continuation of the
X * sequence in other directions.
X */
X
Xunsigned char nextpos[8][64][64];
Xunsigned char nextdir[8][64][64];
X
X/*
X * ptype is used to separate white and black pawns, like this; ptyp =
X * ptype[side][piece] piece can be used directly in nextpos/nextdir when
X * generating moves for pieces that are not black pawns.
X */
Xconst short ptype[2][8] =
X{
X no_piece, pawn, knight, bishop, rook, queen, king, no_piece,
X no_piece, bpawn, knight, bishop, rook, queen, king, no_piece};
X
X/* data used to generate nextpos/nextdir */
Xstatic const short direc[8][8] =
X{
X 0, 0, 0, 0, 0, 0, 0, 0,
X 10, 9, 11, 0, 0, 0, 0, 0,
X 8, -8, 12, -12, 19, -19, 21, -21,
X 9, 11, -9, -11, 0, 0, 0, 0,
X 1, 10, -1, -10, 0, 0, 0, 0,
X 1, 10, -1, -10, 9, 11, -9, -11,
X 1, 10, -1, -10, 9, 11, -9, -11,
X -10, -9, -11, 0, 0, 0, 0, 0};
Xstatic const short max_steps[8] =
X{0, 2, 1, 7, 7, 7, 1, 2};
Xstatic const short nunmap[120] =
X{
X -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
X -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
X -1, 0, 1, 2, 3, 4, 5, 6, 7, -1,
X -1, 8, 9, 10, 11, 12, 13, 14, 15, -1,
X -1, 16, 17, 18, 19, 20, 21, 22, 23, -1,
X -1, 24, 25, 26, 27, 28, 29, 30, 31, -1,
X -1, 32, 33, 34, 35, 36, 37, 38, 39, -1,
X -1, 40, 41, 42, 43, 44, 45, 46, 47, -1,
X -1, 48, 49, 50, 51, 52, 53, 54, 55, -1,
X -1, 56, 57, 58, 59, 60, 61, 62, 63, -1,
X -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
X -1, -1, -1, -1, -1, -1, -1, -1, -1, -1};
X
Xint InitFlag = false;
Xvoid
XInitialize_moves (void)
X
X/*
X * This procedure pre-calculates all moves for every piece from every square.
X * This data is stored in nextpos/nextdir and used later in the move
X * generation routines.
X */
X
X{
X short ptyp, po, p0, d, di, s, delta;
X unsigned char *ppos, *pdir;
X short dest[8][8];
X short steps[8];
X short sorted[8];
X
X for (ptyp = 0; ptyp < 8; ptyp++)
X for (po = 0; po < 64; po++)
X for (p0 = 0; p0 < 64; p0++)
X {
X nextpos[ptyp][po][p0] = (unsigned char) po;
X nextdir[ptyp][po][p0] = (unsigned char) po;
X }
X for (ptyp = 1; ptyp < 8; ptyp++)
X for (po = 21; po < 99; po++)
X if (nunmap[po] >= 0)
X {
X ppos = nextpos[ptyp][nunmap[po]];
X pdir = nextdir[ptyp][nunmap[po]];
X /* dest is a function of direction and steps */
X for (d = 0; d < 8; d++)
X {
X dest[d][0] = nunmap[po];
X delta = direc[ptyp][d];
X if (delta != 0)
X {
X p0 = po;
X for (s = 0; s < max_steps[ptyp]; s++)
X {
X p0 = p0 + delta;
X
X /*
X * break if (off board) or (pawns only move two
X * steps from home square)
X */
X if ((nunmap[p0] < 0) || (((ptyp == pawn) || (ptyp == bpawn))
X && ((s > 0) && ((d > 0) || (Stboard[nunmap[po]] != pawn)))))
X break;
X else
X dest[d][s] = nunmap[p0];
X }
X }
X else
X s = 0;
X
X /*
X * sort dest in number of steps order currently no sort
X * is done due to compability with the move generation
X * order in old gnu chess
X */
X steps[d] = s;
X for (di = d; s > 0 && di > 0; di--)
X if (steps[sorted[di - 1]] == 0) /* should be: < s */
X sorted[di] = sorted[di - 1];
X else
X break;
X sorted[di] = d;
X }
X
X /*
X * update nextpos/nextdir, pawns have two threads (capture
X * and no capture)
X */
X p0 = nunmap[po];
X if (ptyp == pawn || ptyp == bpawn)
X {
X for (s = 0; s < steps[0]; s++)
X {
X ppos[p0] = (unsigned char) dest[0][s];
X p0 = dest[0][s];
X }
X p0 = nunmap[po];
X for (d = 1; d < 3; d++)
X {
X pdir[p0] = (unsigned char) dest[d][0];
X p0 = dest[d][0];
X }
X }
X else
X {
X pdir[p0] = (unsigned char) dest[sorted[0]][0];
X for (d = 0; d < 8; d++)
X for (s = 0; s < steps[sorted[d]]; s++)
X {
X ppos[p0] = (unsigned char) dest[sorted[d]][s];
X p0 = dest[sorted[d]][s];
X if (d < 7)
X pdir[p0] = (unsigned char) dest[sorted[d + 1]][0];
X
X /*
X * else is already initialized
X */
X }
X }
X }
X}
X
Xvoid
XNewGame (void)
X
X/*
X * Reset the board and other variables to start a new game.
X */
X
X{
X short l, c, p;
X
X stage = stage2 = -1; /* the game is not yet started */
X flag.mate = flag.post = flag.quit = flag.reverse = flag.bothsides = false;
X flag.force = false;
X flag.coords = true;
X flag.hash = flag.easy = flag.beep = flag.rcptr = true;
X#if defined(MSDOS) && !defined(SEVENBIT)
X flag.rv = false;
X#else
X flag.stars = false;
X flag.rv = true;
X flag.material = true;
X flag.shade = false;
X flag.musttimeout = false;
X
X#endif /* MSDOS && !SEVENBIT */
X
X NodeCnt = et0 = epsquare = 0;
X dither = 0;
X XCmore = 0;
X WAwindow = WAWNDW;
X WBwindow = WBWNDW;
X BAwindow = BAWNDW;
X BBwindow = BBWNDW;
X xwndw = BXWNDW;
X if (!MaxSearchDepth)
X MaxSearchDepth = MAXDEPTH - 1;
X contempt = 0;
X GameCnt = 0;
X Game50 = 1;
X hint = 0x0C14;
X ZeroRPT ();
X Developed[white] = Developed[black] = false;
X castld[white] = castld[black] = false;
X PawnThreat[0] = CptrFlag[0] = false;
X Pscore[0] = 12000;
X Tscore[0] = 12000;
X opponent = white;
X computer = black;
X for (l = 0; l < TREE; l++)
X Tree[l].f = Tree[l].t = 0;
X#if ttblsz
X ZeroTTable ();
X#endif /* ttblsz */
X srand ((unsigned int) 1);
X if (!InitFlag)
X {
X for (c = white; c <= black; c++)
X for (p = pawn; p <= king; p++)
X for (l = 0; l < 64; l++)
X {
X hashcode[c][p][l].key = (((unsigned long) urand ()));
X hashcode[c][p][l].key += (((unsigned long) urand ()) << 16);
X hashcode[c][p][l].bd = (((unsigned long) urand ()));
X hashcode[c][p][l].bd += (((unsigned long) urand ()) << 16);
X#ifdef LONG64
X hashcode[c][p][l].key += (((unsigned long) urand ()) << 32);
X hashcode[c][p][l].key += (((unsigned long) urand ()) << 48);
X hashcode[c][p][l].bd += (((unsigned long) urand ()) << 32);
X hashcode[c][p][l].bd += (((unsigned long) urand ()) << 48);
X#endif
X }
X }
X for (l = 0; l < 64; l++)
X {
X board[l] = Stboard[l];
X color[l] = Stcolor[l];
X Mvboard[l] = 0;
X }
X ClrScreen ();
X InitializeStats ();
X time0 = time ((long *) 0);
X ElapsedTime (1);
X flag.regularstart = true;
X Book = BOOKFAIL;
X if (!InitFlag)
X {
X if (TCflag)
X SetTimeControl ();
X else if (Level == 0)
X SelectLevel ();
X UpdateDisplay (0, 0, 1, 0);
X GetOpenings ();
X InitFlag = true;
X }
X hashbd = hashkey = 0;
X}
Xvoid
XInitConst (char *lang)
X{
X FILE *constfile;
X char s[256];
X char sl[5];
X int len, entry;
X char *r, *p, *q;
X constfile = fopen (LANGFILE, "r");
X if (!constfile)
X {
X printf ("NO LANGFILE\n");
X exit ();
X }
X while (fgets (s, sizeof (s), constfile))
X {
X if (s[0] == '!')
X continue;
X len = strlen (s);
X for (q = &s[len]; q > &s[8]; q--)
X if (*q == '}')
X break;
X if (q == &s[8])
X {
X printf ("{ error in cinstfile\n");
X exit ();
X }
X *q = '\0';
X if (s[3] != ':' || s[7] != ':' || s[8] != '{')
X {
X printf ("Langfile format error %s\n", s);
X exit ();
X }
X s[3] = s[7] = '\0';
X if (lang == NULL)
X {
X lang = sl;
X strcpy (sl, &s[4]);
X }
X if (strcmp (&s[4], lang))
X continue;
X entry = atoi (s);
X if (entry < 0 || entry >= CPSIZE)
X {
X printf ("Langfile number error\n");
X exit ();
X }
X for (q = p = &s[9]; *p; p++)
X {
X if (*p != '\\')
X {
X *q++ = *p;
X }
X else if (*(p + 1) == 'n')
X {
X *q++ = '\n';
X p++;
X }
X }
X *q = '\0';
X if (entry < 0 || entry > 255)
X {
X printf ("Langfile error %d\n", entry);
X exit (0);
X }
X CP[entry] = (char *) malloc ((unsigned) strlen (&s[9]) + 1);
X if (CP[entry] == NULL)
X {
X perror ("malloc");
X exit (0);
X }
X strcpy (CP[entry], &s[9]);
X
X }
X fclose (constfile);
X}
X
X#ifdef ttblsz
Xvoid
XInitialize_ttable ()
X{
X if (rehash < 0)
X rehash = MAXrehash - 1;
X}
X
X#endif /* ttblsz */
END_OF_FILE
if test 11648 -ne `wc -c <'src/init.c'`; then
echo shar: \"'src/init.c'\" unpacked with wrong size!
fi
# end of 'src/init.c'
fi
echo shar: End of archive 8 \(of 12\).
cp /dev/null ark8isdone
MISSING=""
for I in 1 2 3 4 5 6 7 8 9 10 11 12 ; do
if test ! -f ark${I}isdone ; then
MISSING="${MISSING} ${I}"
fi
done
if test "${MISSING}" = "" ; then
echo You have unpacked all 12 archives.
rm -f ark[1-9]isdone ark[1-9][0-9]isdone
echo Building book file.
cat misc/book.xaa misc/book.xab > misc/gnuchess.nunn.book
rm misc/book.xaa misc/book.xab
else
echo You still need to unpack the following archives:
echo " " ${MISSING}
fi
## End of shell archive.
exit 0