⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 nondsp.c

📁 早期freebsd实现
💻 C
📖 第 1 页 / 共 2 页
字号:
#else  printz("Nodes= %ld  Eval= %ld  Hash= %ld  Rate= %ld  ",          NodeCnt,EvalNodes,HashCnt,evrate);  printz("CPU= %.2ld:%.2ld.%.2ld\n\n",          cputimer/6000,(cputimer % 6000)/100,cputimer % 100);            if (root->flags & epmask) UpdateDisplay(0,0,1,0);  else UpdateDisplay(root->f,root->t,0,root->flags & cstlmask);  printz("My move is: %s\n\n",mvstr1);  if (beep) printz("%c",7);    if (root->flags & draw) printz("Draw game!\n");  else if (root->score == -9999) printz("opponent mates!\n");  else if (root->score == 9998) printz("computer mates!\n");  else if (root->score < -9000) printz("opponent will soon mate!\n");  else if (root->score > 9000)  printz("computer will soon mate!\n");#endif CHESSTOOL}ElapsedTime(iop)short iop;/*    Determine the time that has passed since the search was started. If    the elapsed time exceeds the target (ResponseTime+ExtraTime) then set    timeout to true which will terminate the search. */{  et = time((long *)0) - time0;  if (et < 0) et = 0;  ETnodes += 50;  if (et > et0 || iop == 1)    {      if (et > ResponseTime+ExtraTime && Sdepth > 1) timeout = true;      et0 = et;      if (iop == 1)        {          time0 = time((long *)0); et0 = 0;        }#ifdef MSDOS      cputimer = 100*et;      if (et > 0) evrate = NodeCnt/(et+ft); else evrate = 0;      if (kbhit() && Sdepth > 1)        {          timeout = true;          bothsides = false;        }#else      (void) times(&tmbuf2);      cputimer = 100*(tmbuf2.tms_utime - tmbuf1.tms_utime) / HZ;      if (cputimer > 0) evrate = (100*NodeCnt)/(cputimer+100*ft);      else evrate = 0;#endif MSDOS      ETnodes = NodeCnt + 50;    }}SetTimeControl(){  if (TCflag)    {      TimeControl.moves[white] = TimeControl.moves[black] = TCmoves;      TimeControl.clock[white] = TimeControl.clock[black] = 60*(long)TCminutes;    }  else    {      TimeControl.moves[white] = TimeControl.moves[black] = 0;      TimeControl.clock[white] = TimeControl.clock[black] = 0;      Level = 60*(long)TCminutes;    }  et = 0;  ElapsedTime(1);}ClrScreen(){#ifndef CHESSTOOL  printz("\n");#endif}UpdateDisplay(f,t,flag,iscastle)short f,t,flag,iscastle;{#ifndef CHESSTOOLshort r,c,l;  if (flag)    {      printz("\n");      for (r = 7; r >= 0; r--)        {          for (c = 0; c <= 7; c++)            {              if (reverse) l = locn[7-r][7-c]; else l = locn[r][c];              if (color[l] == neutral) printz(" -");              else if (color[l] == white) printz(" %c",qxx[board[l]]);              else printz(" %c",pxx[board[l]]);            }          printz("\n");        }      printz("\n");    }#endif CHESSTOOL}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;char buffr[2048];struct BookEntry *entry;unsigned short mv,*mp,tmp[100];  if ((fd = fopen("gnuchess.book","r")) != NULL)    {/*      setvbuf(fd,buffr,_IOFBF,2048);*/      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);    }}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;  printz("Enter 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;  printz("Enter 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;{#ifndef CHESSTOOL  printz("%s\n");#endif CHESSTOOL}ShowSidetomove(){}PromptForMove(){#ifndef CHESSTOOL  printz("\nYour move is? ");#endif CHESSTOOL}ShowCurrentMove(pnt,f,t)short pnt,f,t;{}ChangeAlphaWindow(){  printz("window: ");  scanz("%hd",&Awindow);}ChangeBetaWindow(){  printz("window: ");  scanz("%hd",&Bwindow);}GiveHint(){  algbr((short)(hint>>8),(short)(hint & 0xFF),false);  printz("try %s\n",mvstr1);}SelectLevel(){  OperatorTime = 30000;  printz("Enter #moves #minutes: ");  scanz("%hd %hd",&TCmoves,&TCminutes);  printz("Operator time= ");  scanz("%hd",&OperatorTime);  TCflag = (TCmoves > 1);  SetTimeControl();}ChangeSearchDepth(){  printz("depth= ");  scanz("%hd",&MaxSearchDepth);}SetContempt(){  printz("contempt= ");  scanz("%hd",&contempt);}ChangeXwindow(){  printz("xwndw= ");  scanz("%hd",&xwndw);}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -