Annotation of 43BSDReno/games/chess/nondsp.c, revision 1.1

1.1     ! root        1: /*
        !             2:   UNIX & MSDOS NON-DISPLAY, AND CHESSTOOL interface for Chess
        !             3:    
        !             4:   Revision: 4-25-88
        !             5:    
        !             6:   Copyright (C) 1986, 1987, 1988 Free Software Foundation, Inc.
        !             7:   Copyright (c) 1988  John Stanback
        !             8: 
        !             9:   This file is part of CHESS.
        !            10: 
        !            11:   CHESS is distributed in the hope that it will be useful,
        !            12:   but WITHOUT ANY WARRANTY.  No author or distributor
        !            13:   accepts responsibility to anyone for the consequences of using it
        !            14:   or for whether it serves any particular purpose or works at all,
        !            15:   unless he says so in writing.  Refer to the CHESS General Public
        !            16:   License for full details.
        !            17: 
        !            18:   Everyone is granted permission to copy, modify and redistribute
        !            19:   CHESS, but only under the conditions described in the
        !            20:   CHESS General Public License.   A copy of this license is
        !            21:   supposed to have been given to you along with CHESS so you
        !            22:   can know your rights and responsibilities.  It should be in a
        !            23:   file named COPYING.  Among other things, the copyright notice
        !            24:   and this notice must be preserved on all copies.
        !            25: */
        !            26: 
        !            27: 
        !            28: #include <stdio.h>
        !            29: #include <ctype.h>
        !            30: #ifdef MSDOS
        !            31: #include <dos.h>
        !            32: #include <stdlib.h>
        !            33: #include <time.h>
        !            34: #else
        !            35: #include <sys/param.h>
        !            36: #include <sys/times.h>
        !            37: #include <sys/file.h>
        !            38: struct tms tmbuf1,tmbuf2;
        !            39: int TerminateSearch(),Die();
        !            40: #endif MSDOS
        !            41: 
        !            42: #include "gnuchess.h"
        !            43: #ifdef NEWMOVE
        !            44: #include "move.h"
        !            45: #endif
        !            46: 
        !            47: #define printz printf
        !            48: #define scanz scanf
        !            49: int mycnt1,mycnt2;
        !            50: 
        !            51: 
        !            52: Initialize()
        !            53: {
        !            54:   mycnt1 = mycnt2 = 0;
        !            55: #ifndef MSDOS
        !            56: #endif
        !            57: #ifdef CHESSTOOL
        !            58:   setlinebuf(stdout);
        !            59: /*
        !            60:   setvbuf(stdout,NULL,_IOLBF,BUFSIZ);
        !            61: */
        !            62:   printf("Chess\n");
        !            63:   if (Level == 0 && !TCflag) Level = 15;
        !            64: #endif CHESSTOOL
        !            65: }
        !            66: 
        !            67: ExitChess()
        !            68: {
        !            69:   ListGame();
        !            70:   exit(0);
        !            71: }
        !            72: 
        !            73: #ifndef MSDOS
        !            74: Die()
        !            75: {
        !            76: char s[80];
        !            77:   printz("Abort? ");
        !            78:   scanz("%s",s);
        !            79:   if (strcmp(s,"yes") == 0) ExitChess();
        !            80: }
        !            81: 
        !            82: TerminateSearch()
        !            83: {
        !            84:   timeout = true;
        !            85:   bothsides = false;
        !            86: }
        !            87: #endif MSDOS
        !            88: 
        !            89: 
        !            90: InputCommand()
        !            91: 
        !            92: /*
        !            93:    Process the users command. If easy mode is OFF (the computer is 
        !            94:    thinking on opponents time) and the program is out of book, then make 
        !            95:    the 'hint' move on the board and call SelectMove() to find a response. 
        !            96:    The user terminates the search by entering ^C (quit siqnal) before 
        !            97:    entering a command. If the opponent does not make the hint move, then 
        !            98:    set Sdepth to zero. 
        !            99: */
        !           100: 
        !           101: {
        !           102: int i;
        !           103: short ok,tmp;
        !           104: long cnt,rate,t1,t2;
        !           105: unsigned short mv;
        !           106: char s[80];
        !           107: 
        !           108:   ok = quit = false;
        !           109:   player = opponent;
        !           110:   ft = 0;
        !           111:   if (hint > 0 && !easy && Book == NULL)
        !           112:     {
        !           113:       fflush(stdout);
        !           114:       time0 = time((long *)0);
        !           115:       algbr(hint>>8,hint & 0xFF,false);
        !           116:       strcpy(s,mvstr1);
        !           117:       tmp = epsquare;
        !           118:       if (VerifyMove(s,1,&mv))
        !           119:         {
        !           120:           SelectMove(computer,2);
        !           121:           VerifyMove(mvstr1,2,&mv);
        !           122:           if (Sdepth > 0) Sdepth--;
        !           123:         }
        !           124:       ft = time((long *)0) - time0;
        !           125:       epsquare = tmp;
        !           126:     }
        !           127:   
        !           128: #ifndef MSDOS
        !           129: #endif
        !           130:   while (!(ok || quit))
        !           131:     {
        !           132:       PromptForMove();
        !           133:       i = scanz("%s",s);
        !           134:       if (i == EOF || s[0] == 0) ExitChess();
        !           135:       player = opponent;
        !           136:       ok = VerifyMove(s,0,&mv);
        !           137:       if (ok && mv != hint)
        !           138:         {
        !           139:           Sdepth = 0;
        !           140:           ft = 0;
        !           141:         }
        !           142:         
        !           143:       if (strcmp(s,"bd") == 0)
        !           144:         {
        !           145:           ClrScreen();
        !           146:           UpdateDisplay(0,0,1,0);
        !           147:         }
        !           148:       if (strcmp(s,"quit") == 0) quit = true;
        !           149:       if (strcmp(s,"post") == 0) post = !post;
        !           150:       if (strcmp(s,"set") == 0) EditBoard();
        !           151:       if (strcmp(s,"go") == 0) ok = true;
        !           152:       if (strcmp(s,"help") == 0) help();
        !           153:       if (strcmp(s,"force") == 0) force = !force;
        !           154:       if (strcmp(s,"book") == 0) Book = NULL;
        !           155:       if (strcmp(s,"new") == 0) NewGame();
        !           156:       if (strcmp(s,"list") == 0) ListGame();
        !           157:       if (strcmp(s,"level") == 0) SelectLevel();
        !           158:       if (strcmp(s,"hash") == 0) hashflag = !hashflag;
        !           159:       if (strcmp(s,"beep") == 0) beep = !beep;
        !           160:       if (strcmp(s,"Awindow") == 0) ChangeAlphaWindow();
        !           161:       if (strcmp(s,"Bwindow") == 0) ChangeBetaWindow();
        !           162:       if (strcmp(s,"rcptr") == 0) rcptr = !rcptr;
        !           163:       if (strcmp(s,"hint") == 0) GiveHint();
        !           164:       if (strcmp(s,"zero") == 0) ZeroTTable();
        !           165:       if (strcmp(s,"both") == 0)
        !           166:         {
        !           167:           bothsides = !bothsides;
        !           168:           Sdepth = 0;
        !           169:           SelectMove(opponent,1);
        !           170:           ok = true;
        !           171:         }
        !           172:       if (strcmp(s,"reverse") == 0)
        !           173:         {
        !           174:           reverse = !reverse;
        !           175:           ClrScreen();
        !           176:           UpdateDisplay(0,0,1,0);
        !           177:         }
        !           178:       if (strcmp(s,"switch") == 0)
        !           179:         {
        !           180:           computer = otherside[computer];
        !           181:           opponent = otherside[opponent];
        !           182:           force = false;
        !           183:           Sdepth = 0;
        !           184:           ok = true;
        !           185:         }
        !           186:       if (strcmp(s,"white") == 0)  
        !           187:         {
        !           188:           computer = white; opponent = black;
        !           189:           ok = true; force = false;
        !           190:           Sdepth = 0;
        !           191:         }
        !           192:       if (strcmp(s,"black") == 0)
        !           193:         {
        !           194:           computer = black; opponent = white;
        !           195:           ok = true; force = false;
        !           196:           Sdepth = 0;
        !           197:         }
        !           198:       if (strcmp(s,"undo") == 0 && GameCnt >= 0) Undo();
        !           199:       if (strcmp(s,"remove") == 0 && GameCnt >= 1) 
        !           200:         {
        !           201:           Undo(); Undo();
        !           202:         }
        !           203:       if (strcmp(s,"get") == 0) GetGame();
        !           204:       if (strcmp(s,"save") == 0) SaveGame();
        !           205:       if (strcmp(s,"depth") == 0) ChangeSearchDepth();
        !           206:       if (strcmp(s,"random") == 0) dither = 6;
        !           207:       if (strcmp(s,"easy") == 0) easy = !easy;
        !           208:       if (strcmp(s,"contempt") == 0) SetContempt();
        !           209:       if (strcmp(s,"xwndw") == 0) ChangeXwindow();
        !           210:       if (strcmp(s,"test") == 0)
        !           211:         {
        !           212:           t1 = time(0);
        !           213:           cnt = 0;
        !           214:           for (i = 0; i < 10000; i++)
        !           215:             {
        !           216:               MoveList(opponent,2);
        !           217:               cnt += TrPnt[3] - TrPnt[2];
        !           218:             }
        !           219:           t2 = time(0);
        !           220:           rate = cnt / (t2-t1);
        !           221:           printz("cnt= %ld  rate= %ld\n",cnt,rate);
        !           222:         }
        !           223:     }
        !           224:     
        !           225:   ElapsedTime(1);
        !           226:   if (force)
        !           227:     {
        !           228:       computer = opponent; opponent = otherside[computer];
        !           229:     }
        !           230: #ifndef MSDOS
        !           231:   (void) times(&tmbuf1);
        !           232: #ifdef CHESSTOOL
        !           233:   printf("%d. %s\n",++mycnt2,s);
        !           234: #endif CHESSTOOL
        !           235: #endif MSDOS
        !           236: }
        !           237: 
        !           238: 
        !           239: help()
        !           240: {
        !           241:   ClrScreen();
        !           242:   printz("CHESS command summary\n");
        !           243:   printz("g1f3      move from g1 to f3\n");
        !           244:   printz("nf3       move knight to f3\n");
        !           245:   printz("o-o       castle king side\n");
        !           246:   printz("o-o-o     castle queen side\n");
        !           247:   printz("set       edit board\n");
        !           248:   printz("switch    sides with computer\n");
        !           249:   printz("white     computer plays white\n");
        !           250:   printz("black     computer plays black\n");
        !           251:   printz("reverse   board display\n");
        !           252:   printz("both      computer match\n");
        !           253:   printz("random    randomize play\n");
        !           254:   printz("undo      undo last move\n");
        !           255:   printz("time      change level\n");
        !           256:   printz("depth     set search depth\n");
        !           257:   printz("post      principle variation\n");
        !           258:   printz("hint      suggest a move\n");
        !           259:   printz("bd        redraw board\n");
        !           260:   printz("clock     set time control\n");
        !           261:   printz("force     enter game moves\n");
        !           262:   printz("list      game to chess.lst\n");
        !           263:   printz("save      game to file\n");
        !           264:   printz("get       game from file\n");
        !           265:   printz("new       start new game\n");
        !           266:   printz("quit      exit CHESS\n");
        !           267:   printz("Computer: ");
        !           268:   if (computer == white) printz("WHITE\n"); else printz("BLACK\n");
        !           269:   printz("Opponent: ");
        !           270:   if (opponent == white) printz("WHITE\n"); else printz("BLACK\n");
        !           271:   printz("Response time: %ld",Level," sec.\n");
        !           272:   printz("Easy mode: ");
        !           273:   if (easy) printz("ON\n"); else printz("OFF\n");
        !           274:   printz("Depth: %d\n",MaxSearchDepth);
        !           275:   printz("Random: "); 
        !           276:   if (dither) printz("ON\n"); else printz("OFF\n");
        !           277:   printz("Transposition table: ");
        !           278:   if (hashflag) printz("ON\n"); else printz("OFF\n");
        !           279:   UpdateDisplay(0,0,1,0);
        !           280: }
        !           281: 
        !           282: 
        !           283: EditBoard()
        !           284: 
        !           285: /* 
        !           286:    Set up a board position. Pieces are entered by typing the piece 
        !           287:    followed by the location. For example, Nf3 will place a knight on 
        !           288:    square f3. 
        !           289: */
        !           290: 
        !           291: {
        !           292: short a,r,c,sq;
        !           293: char s[80];
        !           294: 
        !           295:   ClrScreen();
        !           296:   UpdateDisplay(0,0,1,0);
        !           297:   printz(".   exit to main\n");
        !           298:   printz("#   clear board\n");
        !           299:   printz("enter piece & location: \n");
        !           300:   
        !           301:   a = white;
        !           302:   do
        !           303:   {
        !           304:     scanz("%s",s);
        !           305:     if (s[0] == '#')
        !           306:       {
        !           307:         for (sq = 0; sq < 64; sq++)
        !           308:           {
        !           309:             board[sq] = no_piece; color[sq] = neutral;
        !           310:           }
        !           311:         UpdateDisplay(0,0,1,0);
        !           312:       }
        !           313:     if (s[0] == 'c' || s[0] == 'C') a = otherside[a];
        !           314:     c = s[1]-'a'; r = s[2]-'1';
        !           315:     if ((c >= 0) && (c < 8) && (r >= 0) && (r < 8))
        !           316:       {
        !           317:         sq = locn[r][c];
        !           318:         color[sq] = a;
        !           319:         if (s[0] == 'p') board[sq] = pawn;
        !           320:         else if (s[0] == 'n') board[sq] = knight;
        !           321:         else if (s[0] == 'b') board[sq] = bishop;
        !           322:         else if (s[0] == 'r') board[sq] = rook;
        !           323:         else if (s[0] == 'q') board[sq] = queen;
        !           324:         else if (s[0] == 'k') board[sq] = king;
        !           325:         else { board[sq] = no_piece; color[sq] = neutral; }
        !           326:       }
        !           327:   }
        !           328:   while (s[0] != '.');
        !           329:   if (board[4] != king) kingmoved[white] = 10;
        !           330:   if (board[60] != king) kingmoved[black] = 10;
        !           331:   GameCnt = -1; Game50 = 0; Sdepth = 0;
        !           332:   InitializeStats();
        !           333:   ClrScreen();
        !           334:   UpdateDisplay(0,0,1,0);
        !           335: }
        !           336: 
        !           337: 
        !           338: ShowDepth(ch)
        !           339: char ch;
        !           340: {
        !           341: }
        !           342: 
        !           343: ShowResults(score,bstline,ch)
        !           344: short score;
        !           345: unsigned short bstline[];
        !           346: char ch;
        !           347: {
        !           348: #ifndef CHESSTOOL
        !           349: register int i;
        !           350:   printz("%2d%c  %5d %4ld %7ld   ",Sdepth,ch,score,et,NodeCnt);
        !           351:   for (i = 1; bstline[i] > 0; i++)
        !           352:     {
        !           353:       algbr((short)(bstline[i] >> 8),(short)(bstline[i] & 0xFF),false);
        !           354:       if (i == 9 || i == 17) printz("\n                          ");
        !           355:       printz("%5s ",mvstr1);
        !           356:     }
        !           357:   printz("\n");
        !           358: #endif
        !           359: }
        !           360: 
        !           361: 
        !           362: SearchStartStuff(side)
        !           363: short side;
        !           364: {
        !           365: #ifndef MSDOS
        !           366: #endif
        !           367: #ifndef CHESSTOOL
        !           368:   printz("\nMove# %d    Target= %ld    Clock: %ld\n",
        !           369:           TCmoves-TimeControl.moves[side]+1,
        !           370:           ResponseTime,TimeControl.clock[side]);
        !           371: #endif
        !           372: }
        !           373: 
        !           374: 
        !           375: OutputMove()
        !           376: {
        !           377: #ifdef CHESSTOOL
        !           378:   printz("%d. ... %s\n",++mycnt1,mvstr1);
        !           379:   if (root->flags & draw)
        !           380:     {
        !           381:       printz("Draw\n");
        !           382:       ListGame();
        !           383:       exit(0);
        !           384:     }
        !           385:   if (root->score == -9999)
        !           386:     {
        !           387:       if (opponent == white) printz("White\n"); else printz("Black\n");
        !           388:       ListGame();
        !           389:       exit(0);
        !           390:     }
        !           391:   if (root->score == 9998)
        !           392:     {
        !           393:       if (computer == white) printz("White\n"); else printz("Black\n");
        !           394:       ListGame();
        !           395:       exit(0);
        !           396:     }
        !           397: #else
        !           398:   printz("Nodes= %ld  Eval= %ld  Hash= %ld  Rate= %ld  ",
        !           399:           NodeCnt,EvalNodes,HashCnt,evrate);
        !           400:   printz("CPU= %.2ld:%.2ld.%.2ld\n\n",
        !           401:           cputimer/6000,(cputimer % 6000)/100,cputimer % 100);
        !           402:           
        !           403:   if (root->flags & epmask) UpdateDisplay(0,0,1,0);
        !           404:   else UpdateDisplay(root->f,root->t,0,root->flags & cstlmask);
        !           405:   printz("My move is: %s\n\n",mvstr1);
        !           406:   if (beep) printz("%c",7);
        !           407:   
        !           408:   if (root->flags & draw) printz("Draw game!\n");
        !           409:   else if (root->score == -9999) printz("opponent mates!\n");
        !           410:   else if (root->score == 9998) printz("computer mates!\n");
        !           411:   else if (root->score < -9000) printz("opponent will soon mate!\n");
        !           412:   else if (root->score > 9000)  printz("computer will soon mate!\n");
        !           413: #endif CHESSTOOL
        !           414: }
        !           415: 
        !           416: 
        !           417: ElapsedTime(iop)
        !           418: short iop;
        !           419: 
        !           420: /* 
        !           421:    Determine the time that has passed since the search was started. If 
        !           422:    the elapsed time exceeds the target (ResponseTime+ExtraTime) then set 
        !           423:    timeout to true which will terminate the search. 
        !           424: */
        !           425: 
        !           426: {
        !           427:   et = time((long *)0) - time0;
        !           428:   if (et < 0) et = 0;
        !           429:   ETnodes += 50;
        !           430:   if (et > et0 || iop == 1)
        !           431:     {
        !           432:       if (et > ResponseTime+ExtraTime && Sdepth > 1) timeout = true;
        !           433:       et0 = et;
        !           434:       if (iop == 1)
        !           435:         {
        !           436:           time0 = time((long *)0); et0 = 0;
        !           437:         }
        !           438: #ifdef MSDOS
        !           439:       cputimer = 100*et;
        !           440:       if (et > 0) evrate = NodeCnt/(et+ft); else evrate = 0;
        !           441:       if (kbhit() && Sdepth > 1)
        !           442:         {
        !           443:           timeout = true;
        !           444:           bothsides = false;
        !           445:         }
        !           446: #else
        !           447:       (void) times(&tmbuf2);
        !           448:       cputimer = 100*(tmbuf2.tms_utime - tmbuf1.tms_utime) / HZ;
        !           449:       if (cputimer > 0) evrate = (100*NodeCnt)/(cputimer+100*ft);
        !           450:       else evrate = 0;
        !           451: #endif MSDOS
        !           452:       ETnodes = NodeCnt + 50;
        !           453:     }
        !           454: }
        !           455: 
        !           456: 
        !           457: SetTimeControl()
        !           458: {
        !           459:   if (TCflag)
        !           460:     {
        !           461:       TimeControl.moves[white] = TimeControl.moves[black] = TCmoves;
        !           462:       TimeControl.clock[white] = TimeControl.clock[black] = 60*(long)TCminutes;
        !           463:     }
        !           464:   else
        !           465:     {
        !           466:       TimeControl.moves[white] = TimeControl.moves[black] = 0;
        !           467:       TimeControl.clock[white] = TimeControl.clock[black] = 0;
        !           468:       Level = 60*(long)TCminutes;
        !           469:     }
        !           470:   et = 0;
        !           471:   ElapsedTime(1);
        !           472: }
        !           473: 
        !           474: 
        !           475: ClrScreen()
        !           476: {
        !           477: #ifndef CHESSTOOL
        !           478:   printz("\n");
        !           479: #endif
        !           480: }
        !           481: 
        !           482: 
        !           483: UpdateDisplay(f,t,flag,iscastle)
        !           484: short f,t,flag,iscastle;
        !           485: {
        !           486: #ifndef CHESSTOOL
        !           487: short r,c,l;
        !           488:   if (flag)
        !           489:     {
        !           490:       printz("\n");
        !           491:       for (r = 7; r >= 0; r--)
        !           492:         {
        !           493:           for (c = 0; c <= 7; c++)
        !           494:             {
        !           495:               if (reverse) l = locn[7-r][7-c]; else l = locn[r][c];
        !           496:               if (color[l] == neutral) printz(" -");
        !           497:               else if (color[l] == white) printz(" %c",qxx[board[l]]);
        !           498:               else printz(" %c",pxx[board[l]]);
        !           499:             }
        !           500:           printz("\n");
        !           501:         }
        !           502:       printz("\n");
        !           503:     }
        !           504: #endif CHESSTOOL
        !           505: }
        !           506: 
        !           507: 
        !           508: GetOpenings()
        !           509: 
        !           510: /*
        !           511:    Read in the Opening Book file and parse the algebraic notation for a 
        !           512:    move into an unsigned integer format indicating the from and to 
        !           513:    square. Create a linked list of opening lines of play, with 
        !           514:    entry->next pointing to the next line and entry->move pointing to a 
        !           515:    chunk of memory containing the moves. More Opening lines of up to 256 
        !           516:    half moves may be added to gnuchess.book. 
        !           517: */
        !           518: 
        !           519: {
        !           520: FILE *fd;
        !           521: int c,i,j,side;
        !           522: char buffr[2048];
        !           523: struct BookEntry *entry;
        !           524: unsigned short mv,*mp,tmp[100];
        !           525: 
        !           526:   if ((fd = fopen("gnuchess.book","r")) != NULL)
        !           527:     {
        !           528: /*
        !           529:       setvbuf(fd,buffr,_IOFBF,2048);
        !           530: */
        !           531:       Book = NULL;
        !           532:       i = 0; side = white;
        !           533:       while ((c = parse(fd,&mv,side)) >= 0)
        !           534:         if (c == 1)
        !           535:           {
        !           536:             tmp[++i] = mv;
        !           537:             side = otherside[side];
        !           538:           }
        !           539:         else if (c == 0 && i > 0)
        !           540:           {
        !           541:             entry = (struct BookEntry *)malloc(sizeof(struct BookEntry));
        !           542:             mp = (unsigned short *)malloc((i+1)*sizeof(unsigned short));
        !           543:             entry->mv = mp;
        !           544:             entry->next = Book;
        !           545:             Book = entry; 
        !           546:             for (j = 1; j <= i; j++) *(mp++) = tmp[j];
        !           547:             *mp = 0;
        !           548:             i = 0; side = white;
        !           549:           }
        !           550:       fclose(fd);
        !           551:     }
        !           552: }
        !           553: 
        !           554: 
        !           555: int parse(fd,mv,side)
        !           556: FILE *fd;
        !           557: unsigned short *mv;
        !           558: short side;
        !           559: {
        !           560: int c,i,r1,r2,c1,c2;
        !           561: char s[100];
        !           562:   while ((c = getc(fd)) == ' ');
        !           563:   i = 0; s[0] = c;
        !           564:   while (c != ' ' && c != '\n' && c != EOF) s[++i] = c = getc(fd);
        !           565:   s[++i] = '\0';
        !           566:   if (c == EOF) return(-1);
        !           567:   if (s[0] == '!' || i < 3)
        !           568:     {
        !           569:       while (c != '\n' && c != EOF) c = getc(fd);
        !           570:       return(0);
        !           571:     }
        !           572:   if (s[4] == 'o')
        !           573:     if (side == black) *mv = 0x3C3A; else *mv = 0x0402;
        !           574:   else if (s[0] == 'o')
        !           575:     if (side == black) *mv = 0x3C3E; else *mv = 0x0406;
        !           576:   else
        !           577:     {
        !           578:       c1 = s[0] - 'a'; r1 = s[1] - '1';
        !           579:       c2 = s[2] - 'a'; r2 = s[3] - '1';
        !           580:       *mv = (locn[r1][c1]<<8) + locn[r2][c2];
        !           581:     }
        !           582:   return(1);
        !           583: }
        !           584: 
        !           585: 
        !           586: GetGame()
        !           587: {
        !           588: FILE *fd;
        !           589: char fname[40];
        !           590: int c;
        !           591: short sq;
        !           592: unsigned short m;
        !           593: 
        !           594:   printz("Enter file name: ");
        !           595:   scanz("%s",fname);
        !           596:   if (fname[0] == '\0') strcpy(fname,"chess.000");
        !           597:   if ((fd = fopen(fname,"r")) != NULL)
        !           598:     {
        !           599:       fscanf(fd,"%hd%hd%hd",&computer,&opponent,&Game50);
        !           600:       fscanf(fd,"%hd%hd%hd%hd",
        !           601:              &castld[white],&castld[black],
        !           602:              &kingmoved[white],&kingmoved[black]);
        !           603:       fscanf(fd,"%hd%hd",&TCflag,&OperatorTime);
        !           604:       fscanf(fd,"%ld%ld%hd%hd",
        !           605:              &TimeControl.clock[white],&TimeControl.clock[black],
        !           606:              &TimeControl.moves[white],&TimeControl.moves[black]);
        !           607:       for (sq = 0; sq < 64; sq++)
        !           608:         {
        !           609:           fscanf(fd,"%hd",&m);
        !           610:           board[sq] = (m >> 8); color[sq] = (m & 0xFF);
        !           611:           if (color[sq] == 0) color[sq] = neutral; else --color[sq];
        !           612:         }
        !           613:       GameCnt = -1; c = '?';
        !           614:       while (c != EOF)
        !           615:         {
        !           616:           ++GameCnt;
        !           617:           c = fscanf(fd,"%hd%hd%hd%ld%hd%hd%hd",&GameList[GameCnt].gmove,
        !           618:                      &GameList[GameCnt].score,&GameList[GameCnt].depth,
        !           619:                      &GameList[GameCnt].nodes,&GameList[GameCnt].time,
        !           620:                      &GameList[GameCnt].piece,&GameList[GameCnt].color);
        !           621:           if (GameList[GameCnt].color == 0) GameList[GameCnt].color = neutral;
        !           622:           else --GameList[GameCnt].color;
        !           623:         }
        !           624:       GameCnt--;
        !           625:       if (TimeControl.clock[white] > 0) TCflag = true;
        !           626:       computer--; opponent--;
        !           627:     }
        !           628:   fclose(fd);
        !           629:   InitializeStats();
        !           630:   UpdateDisplay(0,0,1,0);
        !           631:   Sdepth = 0;
        !           632: }
        !           633: 
        !           634: 
        !           635: SaveGame()
        !           636: {
        !           637: FILE *fd;
        !           638: char fname[40];
        !           639: short sq,i,c;
        !           640: 
        !           641:   printz("Enter file name: ");
        !           642:   scanz("%s",fname);
        !           643:   
        !           644:   if (fname[0] == '\0' || access(fname,W_OK) == -1) strcpy(fname,"chess.000");
        !           645:   fd = fopen(fname,"w");
        !           646:   fprintf(fd,"%d %d %d\n",computer+1,opponent+1,Game50);
        !           647:   fprintf(fd,"%d %d %d %d\n",
        !           648:           castld[white],castld[black],kingmoved[white],kingmoved[black]);
        !           649:   fprintf(fd,"%d %d\n",TCflag,OperatorTime);
        !           650:   fprintf(fd,"%ld %ld %d %d\n",
        !           651:           TimeControl.clock[white],TimeControl.clock[black],
        !           652:           TimeControl.moves[white],TimeControl.moves[black]);
        !           653:   for (sq = 0; sq < 64; sq++)
        !           654:     {
        !           655:       if (color[sq] == neutral) c = 0; else c = color[sq]+1;
        !           656:       fprintf(fd,"%d\n",256*board[sq] + c);
        !           657:     }
        !           658:   for (i = 0; i <= GameCnt; i++)
        !           659:     {
        !           660:       if (GameList[i].color == neutral) c = 0;
        !           661:       else c = GameList[i].color + 1;
        !           662:       fprintf(fd,"%d %d %d %ld %d %d %d\n",
        !           663:               GameList[i].gmove,GameList[i].score,GameList[i].depth,
        !           664:               GameList[i].nodes,GameList[i].time,
        !           665:               GameList[i].piece,c);
        !           666:     }
        !           667:   fclose(fd);
        !           668: }
        !           669: 
        !           670: 
        !           671: ListGame()
        !           672: {
        !           673: FILE *fd;
        !           674: short i,f,t;
        !           675:   fd = fopen("chess.lst","w");
        !           676:   fprintf(fd,"\n");
        !           677:   fprintf(fd,"       score  depth  nodes  time         ");
        !           678:   fprintf(fd,"       score  depth  nodes  time\n");
        !           679:   for (i = 0; i <= GameCnt; i++)
        !           680:     {
        !           681:       f = GameList[i].gmove>>8; t = (GameList[i].gmove & 0xFF);
        !           682:       algbr(f,t,false);
        !           683:       if ((i % 2) == 0) fprintf(fd,"\n"); else fprintf(fd,"         ");
        !           684:       fprintf(fd,"%5s  %5d     %2d %6ld %5d",mvstr1,
        !           685:               GameList[i].score,GameList[i].depth,
        !           686:               GameList[i].nodes,GameList[i].time);
        !           687:     }
        !           688:   fprintf(fd,"\n\n");
        !           689:   fclose(fd);
        !           690: } 
        !           691: 
        !           692: 
        !           693: Undo()
        !           694: 
        !           695: /*
        !           696:    Undo the most recent half-move.
        !           697: */
        !           698: 
        !           699: {
        !           700: short f,t;
        !           701:   f = GameList[GameCnt].gmove>>8;
        !           702:   t = GameList[GameCnt].gmove & 0xFF;
        !           703:   if (board[t] == king && distance(t,f) > 1)
        !           704:     castle(GameList[GameCnt].color,f,t,2);
        !           705:   else
        !           706:     {
        !           707:       board[f] = board[t]; color[f] = color[t];
        !           708:       board[t] = GameList[GameCnt].piece;
        !           709:       color[t] = GameList[GameCnt].color;
        !           710:       if (board[f] == king) --kingmoved[color[f]];
        !           711:     }
        !           712:   if (TCflag) ++TimeControl.moves[color[f]];
        !           713:   GameCnt--; mate = false; Sdepth = 0;
        !           714:   UpdateDisplay(0,0,1,0);
        !           715:   InitializeStats();
        !           716: }
        !           717: 
        !           718: 
        !           719: ShowMessage(s)
        !           720: char *s;
        !           721: {
        !           722: #ifndef CHESSTOOL
        !           723:   printz("%s\n");
        !           724: #endif CHESSTOOL
        !           725: }
        !           726: 
        !           727: ShowSidetomove()
        !           728: {
        !           729: }
        !           730: 
        !           731: PromptForMove()
        !           732: {
        !           733: #ifndef CHESSTOOL
        !           734:   printz("\nYour move is? ");
        !           735: #endif CHESSTOOL
        !           736: }
        !           737: 
        !           738: 
        !           739: ShowCurrentMove(pnt,f,t)
        !           740: short pnt,f,t;
        !           741: {
        !           742: }
        !           743: 
        !           744: ChangeAlphaWindow()
        !           745: {
        !           746:   printz("window: ");
        !           747:   scanz("%hd",&Awindow);
        !           748: }
        !           749: 
        !           750: ChangeBetaWindow()
        !           751: {
        !           752:   printz("window: ");
        !           753:   scanz("%hd",&Bwindow);
        !           754: }
        !           755: 
        !           756: GiveHint()
        !           757: {
        !           758:   algbr((short)(hint>>8),(short)(hint & 0xFF),false);
        !           759:   printz("try %s\n",mvstr1);
        !           760: }
        !           761: 
        !           762: 
        !           763: SelectLevel()
        !           764: {
        !           765:   OperatorTime = 30000;
        !           766:   printz("Enter #moves #minutes: ");
        !           767:   scanz("%hd %hd",&TCmoves,&TCminutes);
        !           768:   printz("Operator time= ");
        !           769:   scanz("%hd",&OperatorTime);
        !           770:   TCflag = (TCmoves > 1);
        !           771:   SetTimeControl();
        !           772: }
        !           773: 
        !           774: 
        !           775: ChangeSearchDepth()
        !           776: {
        !           777:   printz("depth= ");
        !           778:   scanz("%hd",&MaxSearchDepth);
        !           779: }
        !           780: 
        !           781: SetContempt()
        !           782: {
        !           783:   printz("contempt= ");
        !           784:   scanz("%hd",&contempt);
        !           785: }
        !           786: 
        !           787: ChangeXwindow()
        !           788: {
        !           789:   printz("xwndw= ");
        !           790:   scanz("%hd",&xwndw);
        !           791: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.