📄 uxdsp.c
字号:
} else { TimeControl.moves[white] = TimeControl.moves[black] = 0; TimeControl.clock[white] = TimeControl.clock[black] = 0; Level = 60*(long)TCminutes; } et = 0; ElapsedTime(1);}gotoXY(x,y)short x,y;{ move(y-1,x-1);}ClrScreen(){ clear(); refresh();}ClrEoln(){ clrtoeol(); refresh();}DrawPiece(sq)short sq;{short r,c; char x; if (reverse) r = 7-row[sq]; else r = row[sq]; if (reverse) c = 7-column[sq]; else c = column[sq]; if (color[sq] == black) x = '*'; else x = ' '; gotoXY(5+5*c,5+2*(7-r)); printz("%c%c ",x,pxx[board[sq]]);}UpdateDisplay(f,t,flag,iscastle)short f,t,flag,iscastle;{short i,l,z,m = 0, j; if (flag) { gotoXY(56,2); printz("CHESS"); i = 3; gotoXY(3,++i); printz("|----|----|----|----|----|----|----|----|"); while (i<19) { gotoXY(1,++i); if (reverse) z = (i/2)-1; else z = 10-(i/2); printz("%d ", z); for (j = 0; j < 8; j++) { printz("|"); if (j % 2 == m) printz("#"); else printz(" "); printz(" "); } printz("|"); m = (m + 1) % 2; gotoXY(3,++i); if (i < 19) printz("+----+----+----+----+----+----+----+----+"); } printz("|----|----|----|----|----|----|----|----|"); gotoXY(3,21); if (reverse) printz(" h g f e d c b a"); else printz(" a b c d e f g h"); if (reverse) gotoXY(5,23); else gotoXY(5,2); if (computer == black) printz("Computer"); else printz("Human "); if (reverse) gotoXY(5,2); else gotoXY(5,23); if (computer == white) printz("Computer"); else printz("Human "); for (l = 0; l < 64; l++) DrawPiece(l); } else { DrawPiece(f); DrawPiece(t); if (iscastle) if (t > f) { DrawPiece(f+3); DrawPiece(t-1); } else { DrawPiece(f-4); DrawPiece(t+1); } } refresh();}GetOpenings()/* Read in the Opening Book file and parse the algebraic notation for a move into an unsigned integer format indicating the from and to square. Create a linked list of opening lines of play, with entry->next pointing to the next line and entry->move pointing to a chunk of memory containing the moves. More Opening lines of up to 256 half moves may be added to gnuchess.book. */{FILE *fd;int c,i,j,side;struct BookEntry *entry;unsigned short mv,*mp,tmp[100]; if ((fd = fopen(_PATH_CHESSBOOK,"r")) != NULL) { Book = NULL; i = 0; side = white; while ((c = parse(fd,&mv,side)) >= 0) if (c == 1) { tmp[++i] = mv; side = otherside[side]; } else if (c == 0 && i > 0) { entry = (struct BookEntry *)malloc(sizeof(struct BookEntry)); mp = (unsigned short *)malloc((i+1)*sizeof(unsigned short)); entry->mv = mp; entry->next = Book; Book = entry; for (j = 1; j <= i; j++) *(mp++) = tmp[j]; *mp = 0; i = 0; side = white; } fclose(fd); } else { fprintf(stderr, "\nchess: can't read %s.\n", _PATH_CHESSBOOK); exit(1); }}int parse(fd,mv,side)FILE *fd;unsigned short *mv;short side;{int c,i,r1,r2,c1,c2;char s[100]; while ((c = getc(fd)) == ' '); i = 0; s[0] = c; while (c != ' ' && c != '\n' && c != EOF) s[++i] = c = getc(fd); s[++i] = '\0'; if (c == EOF) return(-1); if (s[0] == '!' || i < 3) { while (c != '\n' && c != EOF) c = getc(fd); return(0); } if (s[4] == 'o') if (side == black) *mv = 0x3C3A; else *mv = 0x0402; else if (s[0] == 'o') if (side == black) *mv = 0x3C3E; else *mv = 0x0406; else { c1 = s[0] - 'a'; r1 = s[1] - '1'; c2 = s[2] - 'a'; r2 = s[3] - '1'; *mv = (locn[r1][c1]<<8) + locn[r2][c2]; } return(1);}GetGame(){FILE *fd;char fname[40];int c;short sq;unsigned short m; ShowMessage("File name: "); scanz("%s",fname); if (fname[0] == '\0') strcpy(fname,"chess.000"); if ((fd = fopen(fname,"r")) != NULL) { fscanf(fd,"%hd%hd%hd",&computer,&opponent,&Game50); fscanf(fd,"%hd%hd%hd%hd", &castld[white],&castld[black], &kingmoved[white],&kingmoved[black]); fscanf(fd,"%hd%hd",&TCflag,&OperatorTime); fscanf(fd,"%ld%ld%hd%hd", &TimeControl.clock[white],&TimeControl.clock[black], &TimeControl.moves[white],&TimeControl.moves[black]); for (sq = 0; sq < 64; sq++) { fscanf(fd,"%hd",&m); board[sq] = (m >> 8); color[sq] = (m & 0xFF); if (color[sq] == 0) color[sq] = neutral; else --color[sq]; } GameCnt = -1; c = '?'; while (c != EOF) { ++GameCnt; c = fscanf(fd,"%hd%hd%hd%ld%hd%hd%hd",&GameList[GameCnt].gmove, &GameList[GameCnt].score,&GameList[GameCnt].depth, &GameList[GameCnt].nodes,&GameList[GameCnt].time, &GameList[GameCnt].piece,&GameList[GameCnt].color); if (GameList[GameCnt].color == 0) GameList[GameCnt].color = neutral; else --GameList[GameCnt].color; } GameCnt--; if (TimeControl.clock[white] > 0) TCflag = true; computer--; opponent--; } fclose(fd); InitializeStats(); UpdateDisplay(0,0,1,0); Sdepth = 0;}SaveGame(){FILE *fd;char fname[40];short sq,i,c; ShowMessage("File name: "); scanz("%s",fname); if (fname[0] == '\0' || access(fname,W_OK) == -1) strcpy(fname,"chess.000"); fd = fopen(fname,"w"); fprintf(fd,"%d %d %d\n",computer+1,opponent+1,Game50); fprintf(fd,"%d %d %d %d\n", castld[white],castld[black],kingmoved[white],kingmoved[black]); fprintf(fd,"%d %d\n",TCflag,OperatorTime); fprintf(fd,"%ld %ld %d %d\n", TimeControl.clock[white],TimeControl.clock[black], TimeControl.moves[white],TimeControl.moves[black]); for (sq = 0; sq < 64; sq++) { if (color[sq] == neutral) c = 0; else c = color[sq]+1; fprintf(fd,"%d\n",256*board[sq] + c); } for (i = 0; i <= GameCnt; i++) { if (GameList[i].color == neutral) c = 0; else c = GameList[i].color + 1; fprintf(fd,"%d %d %d %ld %d %d %d\n", GameList[i].gmove,GameList[i].score,GameList[i].depth, GameList[i].nodes,GameList[i].time, GameList[i].piece,c); } fclose(fd);}ListGame(){FILE *fd;short i,f,t; fd = fopen("chess.lst","w"); fprintf(fd,"\n"); fprintf(fd," score depth nodes time "); fprintf(fd," score depth nodes time\n"); for (i = 0; i <= GameCnt; i++) { f = GameList[i].gmove>>8; t = (GameList[i].gmove & 0xFF); algbr(f,t,false); if ((i % 2) == 0) fprintf(fd,"\n"); else fprintf(fd," "); fprintf(fd,"%5s %5d %2d %6ld %5d",mvstr1, GameList[i].score,GameList[i].depth, GameList[i].nodes,GameList[i].time); } fprintf(fd,"\n\n"); fclose(fd);} Undo()/* Undo the most recent half-move.*/{short f,t; f = GameList[GameCnt].gmove>>8; t = GameList[GameCnt].gmove & 0xFF; if (board[t] == king && distance(t,f) > 1) castle(GameList[GameCnt].color,f,t,2); else { board[f] = board[t]; color[f] = color[t]; board[t] = GameList[GameCnt].piece; color[t] = GameList[GameCnt].color; if (board[f] == king) --kingmoved[color[f]]; } if (TCflag) ++TimeControl.moves[color[f]]; GameCnt--; mate = false; Sdepth = 0; UpdateDisplay(0,0,1,0); InitializeStats();}ShowMessage(s)char *s;{ gotoXY(50,24); printz("%s",s); ClrEoln();}ClearMessage(){ gotoXY(50,24); ClrEoln();}ShowSidetomove(){ gotoXY(50,14); if (player == white) printz("%2d: WHITE",1+(GameCnt+1)/2); else printz("%2d: BLACK",1+(GameCnt+1)/2); ClrEoln();}PromptForMove(){ gotoXY(50,19); printz("Your move is? "); ClrEoln();}ShowCurrentMove(pnt,f,t)short pnt,f,t;{ algbr(f,t,false); gotoXY(50,7); printz("(%2d) %4s",pnt,mvstr1);}ChangeAlphaWindow(){ ShowMessage("window: "); scanz("%hd",&Awindow);}ChangeBetaWindow(){ ShowMessage("window: "); scanz("%hd",&Bwindow);}GiveHint(){char s[40]; algbr((short)(hint>>8),(short)(hint & 0xFF),false); strcpy(s,"try "); strcat(s,mvstr1); ShowMessage(s);}ChangeSearchDepth(){ ShowMessage("depth= "); scanz("%hd",&MaxSearchDepth);}SetContempt(){ ShowMessage("contempt= "); scanz("%hd",&contempt);}ChangeXwindow(){ ShowMessage("xwndw= "); scanz("%hd",&xwndw);}SelectLevel(){ ClrScreen(); gotoXY(32,2); printz("CHESS"); gotoXY(20,4); printz(" 1. 60 moves in 5 minutes"); gotoXY(20,5); printz(" 2. 60 moves in 15 minutes"); gotoXY(20,6); printz(" 3. 60 moves in 30 minutes"); gotoXY(20,7); printz(" 4. 40 moves in 30 minutes"); gotoXY(20,8); printz(" 5. 40 moves in 60 minutes"); gotoXY(20,9); printz(" 6. 40 moves in 120 minutes"); gotoXY(20,10); printz(" 7. 40 moves in 240 minutes"); gotoXY(20,11); printz(" 8. 1 move in 15 minutes"); gotoXY(20,12); printz(" 9. 1 move in 60 minutes"); gotoXY(20,13); printz("10. 1 move in 600 minutes"); OperatorTime = 0; TCmoves = 60; TCminutes = 5; gotoXY(20,17); printz("Enter Level: "); refresh(); scanz("%ld",&Level); switch (Level) { case 1 : TCmoves = 60; TCminutes = 5; break; case 2 : TCmoves = 60; TCminutes = 15; break; case 3 : TCmoves = 60; TCminutes = 30; break; case 4 : TCmoves = 40; TCminutes = 30; break; case 5 : TCmoves = 40; TCminutes = 60; break; case 6 : TCmoves = 40; TCminutes = 120; break; case 7 : TCmoves = 40; TCminutes = 240; break; case 8 : TCmoves = 1; TCminutes = 15; break; case 9 : TCmoves = 1; TCminutes = 60; break; case 10 : TCmoves = 1; TCminutes = 600; break; } TCflag = (TCmoves > 1); SetTimeControl(); ClrScreen(); UpdateDisplay(0,0,1,0);}ShowPostnValues(){short i,r,c; ExaminePosition(); for (i = 0; i < 64; i++) { if (reverse) r = 7-row[i]; else r = row[i]; if (reverse) c = 7-column[i]; else c = column[i]; gotoXY(4+5*c,5+2*(7-r)); c1 = color[i]; c2 = otherside[c1]; PC1 = PawnCnt[c1]; PC2 = PawnCnt[c2]; atk1 = atak[c1]; atk2 = atak[c2]; if (color[i] == neutral) printz(" "); else printz("%3d ",SqValue(i,opponent)); } ScorePosition(opponent,&i); gotoXY(50,24); printz("Score= %d",i); ClrEoln();}DoDebug(){short k,p,i,r,c,tp,tc;char s[40]; ExaminePosition(); ShowMessage("Enter piece: "); scanz("%s",s); if (s[0] == 'w') k = white; else k = black; if (s[1] == 'p') p = pawn; else if (s[1] == 'n') p = knight; else if (s[1] == 'b') p = bishop; else if (s[1] == 'r') p = rook; else if (s[1] == 'q') p = queen; else if (s[1] == 'k') p = king; else p = no_piece; for (i = 0; i < 64; i++) { if (reverse) r = 7-row[i]; else r = row[i]; if (reverse) c = 7-column[i]; else c = column[i]; gotoXY(4+5*c,5+2*(7-r)); tp = board[i]; tc = color[i]; board[i] = p; color[i] = k; c1 = k; c2 = otherside[c1]; PC1 = PawnCnt[c1]; PC2 = PawnCnt[c2]; atk1 = atak[c1]; atk2 = atak[c2]; printz("%3d ",SqValue(i,opponent)); board[i] = tp; color[i] = tc; } ScorePosition(opponent,&i); gotoXY(50,24); printz("Score= %d",i); ClrEoln();}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -