$! ------------------ CUT HERE ----------------------- $ v='f$verify(f$trnlnm("SHARE_VERIFY"))' $! $! This archive created by VMS_SHARE Version 7.2-007 22-FEB-1990 $! On 21-MAY-1992 00:55:15.96 By user MASMUMMY $! $! This VMS_SHARE Written by: $! Andy Harper, Kings College London UK $! $! Acknowledgements to: $! James Gray - Original VMS_SHARE $! Michael Bednarek - Original Concept and implementation $! $!+ THIS PACKAGE DISTRIBUTED IN 6 PARTS, TO KEEP EACH PART $! BELOW 30 BLOCKS $! $! TO UNPACK THIS SHARE FILE, CONCATENATE ALL PARTS IN ORDER $! AND EXECUTE AS A COMMAND PROCEDURE ( @name ) $! $! THE FOLLOWING FILE(S) WILL BE CREATED AFTER UNPACKING: $! 1. CHESS.C;1 $! 2. CHESS.OPN;1 $! $set="set" $set symbol/scope=(nolocal,noglobal) $f=f$parse("SHARE_TEMP","SYS$SCRATCH:.TMP_"+f$getjpi("","PID")) $e="write sys$error ""%UNPACK"", " $w="write sys$output ""%UNPACK"", " $ if f$trnlnm("SHARE_LOG") then $ w = "!" $ ve=f$getsyi("version") $ if ve-f$extract(0,1,ve) .ges. "4.4" then $ goto START $ e "-E-OLDVER, Must run at least VMS 4.4" $ v=f$verify(v) $ exit 44 $UNPACK: SUBROUTINE ! P1=filename, P2=checksum $ if f$search(P1) .eqs. "" then $ goto file_absent $ e "-W-EXISTS, File ''P1' exists. Skipped." $ delete 'f'* $ exit $file_absent: $ if f$parse(P1) .nes. "" then $ goto dirok $ dn=f$parse(P1,,,"DIRECTORY") $ w "-I-CREDIR, Creating directory ''dn'." $ create/dir 'dn' $ if $status then $ goto dirok $ e "-E-CREDIRFAIL, Unable to create ''dn'. File skipped." $ delete 'f'* $ exit $dirok: $ w "-I-PROCESS, Processing file ''P1'." $ if .not. f$verify() then $ define/user sys$output nl: $ EDIT/TPU/NOSEC/NODIS/COM=SYS$INPUT 'f'/OUT='P1' PROCEDURE Unpacker ON_ERROR ENDON_ERROR;SET(FACILITY_NAME,"UNPACK");SET( SUCCESS,OFF);SET(INFORMATIONAL,OFF);f:=GET_INFO(COMMAND_LINE,"file_name");b:= CREATE_BUFFER(f,f);p:=SPAN(" ")@r&LINE_END;POSITION(BEGINNING_OF(b)); LOOP EXITIF SEARCH(p,FORWARD)=0;POSITION(r);ERASE(r);ENDLOOP;POSITION( BEGINNING_OF(b));g:=0;LOOP EXITIF MARK(NONE)=END_OF(b);x:=ERASE_CHARACTER(1); IF g=0 THEN IF x="X" THEN MOVE_VERTICAL(1);ENDIF;IF x="V" THEN APPEND_LINE; MOVE_HORIZONTAL(-CURRENT_OFFSET);MOVE_VERTICAL(1);ENDIF;IF x="+" THEN g:=1; ERASE_LINE;ENDIF;ELSE IF x="-" THEN IF INDEX(CURRENT_LINE,"+-+-+-+-+-+-+-+")= 1 THEN g:=0;ENDIF;ENDIF;ERASE_LINE;ENDIF;ENDLOOP;t:="0123456789ABCDEF"; POSITION(BEGINNING_OF(b));LOOP r:=SEARCH("`",FORWARD);EXITIF r=0;POSITION(r); ERASE(r);x1:=INDEX(t,ERASE_CHARACTER(1))-1;x2:=INDEX(t,ERASE_CHARACTER(1))-1; COPY_TEXT(ASCII(16*x1+x2));ENDLOOP;WRITE_FILE(b,GET_INFO(COMMAND_LINE, "output_file"));ENDPROCEDURE;Unpacker;QUIT; $ delete/nolog 'f'* $ CHECKSUM 'P1' $ IF CHECKSUM$CHECKSUM .eqs. P2 THEN $ EXIT $ e "-E-CHKSMFAIL, Checksum of ''P1' failed." $ ENDSUBROUTINE $START: $ create 'f' X/* X C source for CHESS Rev. 3-10-87 X X Written by John Stanback (hplabs!hpfcla!hpisla!hpltca!jhs) X X Patches for BSD Unix by Rich Salz (rs@mirror.TMC.COM) - 5/3/87 X X*/`20 X X#include X#include X X#define DEF_TIME 10 X#define neutral 0 X#define white 1 X#define black 2`20 X#define no_piece 0 X#define pawn 1 X#define knight 2 X#define bishop 3 X#define rook 4 X#define queen 5 X#define king 6 X#define px " PNBRQK" X#define qx " pnbrqk" X#define rx "12345678" X#define cx "abcdefgh" X#define check 0x0001 X#define capture 0x0002 X#define draw 0x0004 X#define promote 0x0010 X#define incheck 0x0020 X#define epmask 0x0040 X#define exact 0x0100 X#define pwnthrt 0x0200 X#define up 'i' X#define down 'k' X#define left 'j' X#define right 'l' X#define true 1 X#define false 0 X Xstruct leaf X `7B X short f,t,score,reply; X unsigned short flags; X `7D; X Xchar *alph`5B`5D = `7B 'a','b','c','d','e','f','g','h'`7D; Xchar mvstr1`5B5`5D,mvstr2`5B5`5D; Xstruct leaf Tree`5B2000`5D,*root; Xshort TrPnt`5B30`5D; Xshort row`5B64`5D,col`5B64`5D,locn`5B8`5D`5B8`5D,Index`5B64`5D,svalue`5B64`5 VD; Xshort PieceList`5B3`5D`5B16`5D,PieceCnt`5B3`5D; Xshort castld`5B3`5D,kingmoved`5B3`5D,mtl`5B3`5D,pmtl`5B3`5D,emtl`5B3`5D,hung V`5B3`5D; Xshort mate,post,xkillr,ykillr,opponent,computer,Sdepth; Xchar start`5B10`5D, end`5B10`5D; Xchar buff_char; Xint kb; Xshort aflag; Xshort h, v; Xshort allow; Xlong time0; Xint response_time,extra_time,timeout,et,et0; Xshort quit,reverse,bothsides,InChk,player; Xint NodeCnt,srate; Xshort atak`5B3`5D`5B64`5D,PawnCnt`5B3`5D`5B8`5D; Xshort ChkFlag`5B30`5D,CptrFlag`5B30`5D,PawnThreat`5B30`5D,PPscore`5B30`5D; Xshort BookSize,BookDepth; Xshort GameCnt,Game50,epsquare,lpost; Xunsigned short GameList`5B240`5D,Book`5B80`5D`5B24`5D; Xshort GameScore`5B240`5D,GamePc`5B240`5D,GameClr`5B240`5D; Xshort value`5B8`5D=`7B0,100,330,330,500,950,999`7D; Xshort otherside`5B3`5D=`7B0,2,1`7D; Xshort passed_pawn1`5B8`5D=`7B0,3,4,8,14,24,40,80`7D; Xshort passed_pawn2`5B8`5D=`7B0,2,3,4,6,9,13,80`7D; Xshort passed_pawn3`5B8`5D=`7B0,1,2,3,4,5,6,80`7D; Xshort map`5B64`5D= X `7B26,27,28,29,30,31,32,33,38,39,40,41,42,43,44,45, X 50,51,52,53,54,55,56,57,62,63,64,65,66,67,68,69, X 74,75,76,77,78,79,80,81,86,87,88,89,90,91,92,93, X 98,99,100,101,102,103,104,105,110,111,112,113,114,115,116,117`7D; Xshort unmap`5B144`5D= X `7B-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,- V1, X -1,-1,0,1,2,3,4,5,6,7,-1,-1,-1,-1,8,9,10,11,12,13,14,15,-1,-1, X -1,-1,16,17,18,19,20,21,22,23,-1,-1,-1,-1,24,25,26,27,28,29,30,31,-1,-1, X -1,-1,32,33,34,35,36,37,38,39,-1,-1,-1,-1,40,41,42,43,44,45,46,47,-1,-1, X -1,-1,48,49,50,51,52,53,54,55,-1,-1,-1,-1,56,57,58,59,60,61,62,63,-1,-1, X -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1` V7D; Xshort edge`5B64`5D= X `7B0,1,2,3,3,2,1,0,1,2,3,4,4,3,2,1,2,3,4,5,5,4,3,2,3,4,5,6,6,5,4,3, X 3,4,5,6,6,5,4,3,2,3,4,5,5,4,3,2,1,2,3,4,4,3,2,1,0,1,2,3,3,2,1,0`7D; Xshort pknight`5B64`5D= X `7B0,6,11,14,14,11,6,0,6,12,22,25,25,22,12,6, X 11,20,30,36,36,30,20,11,14,25,36,44,44,36,25,14, X 14,25,36,44,44,36,25,14,11,20,30,36,36,30,20,11, X 6,12,22,25,25,22,12,6,0,6,11,14,14,11,6,0`7D; Xshort pbishop`5B64`5D= X `7B14,14,14,14,14,14,14,14,14,18,18,18,18,18,18,14, X 14,18,22,22,22,22,18,14,14,18,22,22,22,22,18,14, X 14,18,22,22,22,22,18,14,14,18,22,22,22,22,18,14, X 14,18,18,18,18,18,18,14,14,14,14,14,14,14,14,14`7D; Xshort board`5B64`5D= X `7Brook,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,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`7D; Xshort color`5B64`5D= X `7Bwhite,white,white,white,white,white,white,white, X white,white,white,white,white,white,white,white, X 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, X black,black,black,black,black,black,black,black, X black,black,black,black,black,black,black,black`7D; Xshort sweep`5B7`5D= `7Bfalse,false,false,true,true,true,false`7D; Xshort Dstpwn`5B3`5D=`7B0,4,6`7D; Xshort Dstart`5B7`5D=`7B6,4,8,4,0,0,0`7D; Xshort Dstop`5B7`5D=`7B7,5,15,7,3,7,7`7D; Xshort Dir`5B16`5D=`7B1,12,-1,-12,11,13,-11,-13,10,-10,14,-14,23,-23,25,-25`7 VD; Xunsigned short PV,Swag1,Swag2,killr1`5B30`5D,killr2`5B30`5D,killr3`5B30`5D,Q Vkillr`5B30`5D; Xunsigned short Ckillr`5B3`5D,prvar`5B30`5D; X Xreadline(x, y, prompt, p) X int x, y; X char *prompt, *p; X`7B X int f, t; X char k; X char *q; X X/* v = h = 0; */ X standout(); X move(y-1,x-1); X printf( "%s", prompt); X standend(); X getyx(stdscr, y, x); X for (q = p; smg$read_keystroke(&kb,&k) != EOF;) `7B X`09*p = k; X`09switch (*p) `7B X`09 default: X`09`09if ( allow && strstr(prompt,"RETURN") == 0) return; X`09`09p++; X`09`09x++; X`09`09break; X`09 case up: X`09`09if ( !allow) `7B p++; break;`7D X`09`09if ( v < 7) v++;`09 X `09`09standout(); X `09`09if ( px`5Bboard`5Bh+(8*v)`5D`5D != ' ') DrawPiece(h+(8*v)); X`09`09else `7B X`09`09 gotoXY(5+(5*h),18-(2*v)); printw(" X"); X`09`09`7D X`09`09standend(); X`09`09DrawPiece(h+(8*(v-1))); X`09`09break; X`09 case down: X`09`09if ( !allow) `7B p++; break;`7D X`09`09if ( v > 0) v--; X `09`09standout(); X `09`09if ( px`5Bboard`5Bh+(8*v)`5D`5D != ' ') DrawPiece(h+(8*v)); X`09`09else `7B X`09`09 gotoXY(5+(5*h),18-(2*v)); printw(" X"); X`09`09`7D X`09`09standend(); X`09`09DrawPiece(h+(8*(v+1))); X`09`09break; X`09 case left: X`09`09if ( !allow) `7B p++; break;`7D X`09`09if ( h > 0) h--; X `09`09standout(); X `09`09if ( px`5Bboard`5Bh+(8*v)`5D`5D != ' ') DrawPiece(h+(8*v)); X`09`09else `7B X`09`09 gotoXY(5+(5*h),18-(2*v)); printw(" X"); X`09`09`7D X`09`09standend(); X`09`09DrawPiece((h+1)+(8*v)); X`09`09break; X `09 case right: X`09`09if ( !allow) `7B p++; break;`7D X`09`09if ( h < 7) h++; X `09`09standout(); X `09`09if ( px`5Bboard`5Bh+(8*v)`5D`5D != ' ') DrawPiece(h+(8*v)); X`09`09else `7B X`09`09 gotoXY(5+(5*h),18-(2*v)); printw(" X"); X`09`09`7D X`09`09standend(); X`09`09DrawPiece((h-1)+(8*v)); X`09 `09break; X`09 case 'c':`20 X`09`09if ( !allow) `7B p++; break;`7D X`09`09allow = false;`20 X`09 `09strcpy(p,"\0\0\0"); X`09`09gotoXY(1,1);`20 X`09`09printw("Enter command or to move piece.");`20 X`09`09break; X`09 case 18: X`09`09ClrScreen(); X`09`09PrintBoard(white,0,0,1); X`09`09break; X`09 case 2: X`09`09if ( GameCnt >= 0) `7B X `09f = GameList`5BGameCnt`5D>>8; t = GameList`5BGameCnt`5D & 0xFF; X `09board`5Bf`5D = board`5Bt`5D; color`5Bf`5D = color`5Bt`5D; X `09board`5Bt`5D = GamePc`5BGameCnt`5D; color`5Bt`5D = GameClr`5BGa VmeCnt`5D; X `09GameCnt--; X`09 PrintBoard(white,0,0,1); X `09InitializeStats(); X`09`09`7D X`09 `09break; X`09 case 'L' & 037: X`09`09touchwin(stdscr); X`09`09refresh(); X`09`09break; X`09 case '?': help(); break; X`09 case '\n': case '\r': X`09`09if ( allow) `7B X `09`09 if ( start`5B0`5D != '\0') sprintf( end,"%c%d",alph`5Bh`5D,v+1); X`09`09 else sprintf( start,"%c%d",alph`5Bh`5D,v+1); X`09`09 if ( start`5B0`5D != '\0' && end`5B0`5D != '\0') `7B X`09`09 sprintf( p, "%s%s",start,end); X `09`09 gotoXY(1,1); ClrEoln(); X`09`09 return; X`09`09 `7D X`09`09 else break; X`09`09`7D X`09`09if ( strcmp(p,"o-o-o") == 0) aflag = 1; X`09`09else if ( strcmp(p,"o-o") == 0) aflag = 0; X`09`09else aflag = 2; X`09`09move(y, x); X`09 *p = '\0'; gotoXY(1,1); ClrEoln(); X`09`09return; X`09 case '\b': X`09`09if (p > q) `7B X`09`09 p--; X`09`09 x--; X`09`09`7D X`09`09break; X`09 case 'U' & 037: case '\007': case '\033': X`09`09p = q; X`09`09x = 0; X`09`09break; X`09`7D X`09move(y, x); X`09ClrEoln();`20 X `7D X *p = '\0'; X`7D X Xmain() X`7B X smg$create_virtual_keyboard(&kb); X initscr(); X NewGame(); X while (!(quit)) X `7B X if (bothsides && !mate) select_move(opponent); else input_command(); X if (!quit && !mate) select_move(computer); X `7D X endwin(); X`7D X X XOpeningBook(side) Xshort side; X`7B Xshort i,j,r0,pnt; Xunsigned m,r; X srand(time(0)); X r0 = m = 0; X for (i = 0; i < BookSize; i++) X `7B X for (j = 0; j <= GameCnt; j++) X if (GameList`5Bj`5D != Book`5Bi`5D`5Bj`5D) break; X if (j > GameCnt) X if ((r=rand()) > r0) X `7B X r0 = r; m = Book`5Bi`5D`5BGameCnt+1`5D; X `7D X `7D X for (pnt = TrPnt`5B1`5D; pnt < TrPnt`5B2`5D; pnt++) X if ((Tree`5Bpnt`5D.f<<8) + Tree`5Bpnt`5D.t == m) Tree`5Bpnt`5D.score = 0 V; X sort(TrPnt`5B1`5D,TrPnt`5B2`5D-1); X if (Tree`5BTrPnt`5B1`5D`5D.score < 0) BookDepth = -1; X`7D X X Xselect_move(side) Xshort side; X X/* X Select a move by calling function search() at progressively deeper X ply until time is up or a mate or draw is reached. An alpha-beta`20 X window of -0, +75 points is set around the score returned from the X previous iteration.`20 X*/ X X`7B Xshort i,alpha,beta,tempb,tempc; X X timeout = false; player = side; X for (i = 0; i < 30; i++) X prvar`5Bi`5D = killr1`5Bi`5D = killr2`5Bi`5D = killr3`5Bi`5D = 0; X PPscore`5B0`5D = -5000; X alpha = -9999; beta = 9999; X NodeCnt = Sdepth = extra_time = 0; X ataks(white,atak`5Bwhite`5D); ataks(black,atak`5Bblack`5D); X TrPnt`5B1`5D = 0; root = &Tree`5B0`5D; X MoveList(side,1); X if (GameCnt < BookDepth) OpeningBook(side); else BookDepth = -1; X if (BookDepth > 0) timeout = true; X while (!timeout && Sdepth<30) X `7B X Sdepth++; X gotoXY(70,1); printw("%d ",Sdepth); ClrEoln(); X search(side,1,Sdepth,alpha,beta,prvar); X if (root->score < alpha) X search(side,1,Sdepth,-12000,alpha,prvar); X if (root->score > beta && !(root->flags & exact)) X `7B X gotoXY(70,1); printw("%d+",Sdepth); ClrEoln(); X search(side,1,Sdepth,beta,12000,prvar); X `7D X beta = root->score+75; X if (root->flags & exact) timeout = true; X `7D X if (root->score > -9999) X `7B X MakeMove(side,root,&tempb,&tempc); X algbrnot(root->f,root->t); X PrintBoard(side,root->f,root->t,0); X gotoXY(50,16); printw("My move is: %s",mvstr1); ClrEoln(); X `7D X ElapsedTime(1); X/* gotoXY(18,23); printw("Nodes= %d",NodeCnt); ClrEoln(); X gotoXY(18,24); printw("Nodes/Sec= %d",srate); ClrEoln(); */ X gotoXY(50,13); X if (root->flags & draw) printw("draw game!"); X if (root->score < -9000) printw("opponent will soon mate!"); X if (root->score > 9000) printw("computer will soon mate!"); X if (root->score == -9999) X `7B X gotoXY(50,13); X printw("opponent mates!!"); mate = true; X `7D X if (root->score == 9998) X `7B X gotoXY(50,13); X printw("computer mates!!"); mate = true; X `7D X ClrEoln(); X if (post) post_move(root); X if (root->f == 255 `7C`7C root->t == 255) Game50 = GameCnt; X else if (board`5Broot->t`5D == pawn `7C`7C (root->flags & capture))`20 X Game50 = GameCnt; X GameScore`5BGameCnt`5D = root->score; X if (GameCnt > 238) quit = true; X player = otherside`5Bside`5D; X`7D X X XVerifyMove(s,ok,aflag) Xchar s`5B`5D; Xshort *ok, aflag; X X/* X See if the opponents move is legal, if so, make it. X*/ X X`7B Xshort x,pnt,cnt,tempb,tempc; Xunsigned short nxtline`5B30`5D; Xstruct leaf *node,*xnode; X X *ok = false; cnt = 0; X MoveList(opponent,2); X pnt = TrPnt`5B2`5D; +-+-+-+-+-+-+-+- END OF PART 1 +-+-+-+-+-+-+-+-