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

📄 dspcom.c

📁 GNU国际象棋C++源代码Windows版的
💻 C
📖 第 1 页 / 共 3 页
字号:
      skip ();
      InPtr += 14;
      skipb ();
      OperatorTime = atoi (InPtr);
      fgets (fname, 256, fd);
      InPtr = &fname[11];
      skipb ();
      TimeControl.clock[white] = atol (InPtr);
      skip ();
      skip ();
      TimeControl.moves[white] = atoi (InPtr);
      fgets (fname, 256, fd);
      InPtr = &fname[11];
      skipb ();
      TimeControl.clock[black] = atol (InPtr);
      skip ();
      skip ();
      TimeControl.moves[black] = atoi (InPtr);
      fgets (fname, 256, fd);
      for (i = 7; i > -1; i--)
   {
     fgets (fname, 256, fd);
     p = &fname[2];
     InPtr = &fname[11];
     skipb ();
     for (j = 0; j < 8; j++)
       {
         sq = i * 8 + j;
         if (*p == '.')
      {
        board[sq] = no_piece;
        color[sq] = neutral;
      }
         else
      {
        for (c = 0; c < 8; c++)
          {
            if (*p == pxx[c])
         {
           board[sq] = c;
           color[sq] = black;
         }
          }
        for (c = 0; c < 8; c++)
          {
            if (*p == qxx[c])
         {
           board[sq] = c;
           color[sq] = white;
         }
          }
      }
         p++;
         Mvboard[sq] = atoi (InPtr);
         skip ();
       }
   }
      GameCnt = 0;
      flag.regularstart = true;
      Book = BOOKFAIL;
      fgets (fname, 256, fd);
      fgets (fname, 256, fd);
      fgets (fname, 256, fd);
      side = black;
      while (fgets (fname, 256, fd))
   {
     struct GameRec *g;

     ++GameCnt;
     InPtr = fname;
     skipb ();
     g = &GameList[GameCnt];
     side = side ^ 1;
     g->gmove = parser (InPtr, side);
     skip ();
     g->score = atoi (InPtr);
     skip ();
     g->depth = atoi (InPtr);
     skip ();
     g->nodes = atol (InPtr);
     skip ();
     g->time = atol (InPtr);
     skip ();
     g->flags = c = atoi (InPtr);
     skip ();
#ifdef HAVE_STRTOUL
     g->hashkey = strtoul (InPtr, (CHAR **) NULL, 16);
     skip ();
     g->hashbd = strtoul (InPtr, (CHAR **) NULL, 16);
#else
     g->hashkey = strtol (InPtr, (CHAR **) NULL, 16);
     skip ();
     g->hashbd = strtol (InPtr, (CHAR **) NULL, 16);
#endif
     skip ();
     g->epssq = atoi(InPtr);
     g->piece = no_piece;
     g->color = neutral;
     if (c & (capture | cstlmask))
       {
         if (c & capture)
      {
        skip ();
        for (c = 0; c < 8; c++)
          if (pxx[c] == *InPtr)
            break;
        g->piece = c;
      }
         skip ();
         g->color = ((*InPtr == CP[41][0]) ? black : white);
       }
   }
/*      if (TimeControl.clock[white] > 0)
   TCflag = true; */
      if (TCflag == false && !MaxResponseTime)
         MaxResponseTime = 3000;
      fclose (fd);
      ZeroRPT ();
      InitializeStats ();
      epsquare = eps;
      UpdateDisplay (0, 0, 1, 0, 0);
      ShowPlayers();
      Sdepth = 0;
      hint = 0;
      return true;
    }
   else
    {
     ShowMessage("Could not open file");
     return false;
    }
}

void
SaveGame (void)
{
  FILE *fd;
  CHAR fname[256];
  SHORT sq, i, c, f, t;
  CHAR p;
  OPENFILENAME ofn;

  fname[0]='\0';
  memset(&ofn,0,sizeof(ofn));
  ofn.hwndOwner=hWnd;
  ofn.lpstrFilter=filter;
  ofn.nFilterIndex=1;
  ofn.lpstrFile=fname;
  ofn.nMaxFile=256;
  ofn.lpstrTitle="Save Game";
#ifdef WIN32
  ofn.Flags=OFN_FILEMUSTEXIST|OFN_HIDEREADONLY|OFN_EXPLORER;
#else
  ofn.Flags=OFN_FILEMUSTEXIST|OFN_HIDEREADONLY;
#endif
  ofn.lStructSize=sizeof(ofn);
  ofn.lpstrDefExt="chs";
  if (!GetSaveFileName(&ofn))return;
  if (fname[0] == '\0')
/* chess.000 */
    strcpy (fname, CP[44]);
  if ((fd = fopen (fname, "w")) != NULL)
    {
      CHAR *b, *w;

      b = w = CP[24];
      if (computer == black)
   b = CP[45];
      if (computer == white)
   w = CP[45];
      fprintf (fd, CP[13], b, w, Game50,epsquare);
      fprintf (fd, CP[14], castld[white] ? CP[53] : CP[54], castld[black] ? CP[53] : CP[54]);
      fprintf (fd, CP[37], TCflag, OperatorTime);
      fprintf (fd, CP[39],
          TimeControl.clock[white], TimeControl.moves[white],
          TimeControl.clock[black], TimeControl.moves[black]);
      for (i = 7; i > -1; i--)
   {
     fprintf (fd, "%1d ", i + 1);
     for (c = 0; c < 8; c++)
       {
         sq = i * 8 + c;
         switch (color[sq])
      {
      case black:
        p = pxx[board[sq]];
        break;
      case white:
        p = qxx[board[sq]];
        break;
      default:
        p = '.';
      }
         fprintf (fd, "%c", p);
       }
     for (f = i * 8; f < i * 8 + 8; f++)
       fprintf (fd, " %d", Mvboard[f]);
     fprintf (fd, "\n");
   }
      fprintf (fd, "  %s\n", cxx);
      fprintf (fd, CP[43]);
      for (i = 1; i <= GameCnt; i++)
   {
     struct GameRec *g = &GameList[i];

     f = g->gmove >> 8;
     t = (g->gmove & 0xFF);
     algbr (f, t, g->flags);
     fprintf (fd, "%s %5d %5d %7ld %6ld %5d  %#08lx %#08lx %d %c   %s\n",
         mvstr[0], g->score, g->depth,
         g->nodes, g->time, g->flags, g->hashkey, g->hashbd,g->epssq,
      pxx[g->piece], (((int)(g->color) == 2) ? (CHAR *)"     " : ColorStr[g->color]));
   }
      fclose (fd);
/* Game saved */
      ShowMessage (CP[23]);
    }
  else
    /*ShowMessage ("Could not open file");*/
    ShowMessage (CP[17]);
}

void
ListGame (void)
{
  FILE *fd;
  SHORT i, f, t;
  CHAR fname[256];
  OPENFILENAME ofn;

  fname[0]='\0';
  memset(&ofn,0,sizeof(ofn));
  ofn.hwndOwner=hWnd;
  ofn.lpstrFilter="List files (*.lst)\0*.lst\0";
  ofn.nFilterIndex=1;
  ofn.lpstrFile=fname;
  ofn.nMaxFile=256;
  ofn.lpstrTitle="List Game In...";
#ifdef WIN32
  ofn.Flags=OFN_HIDEREADONLY|OFN_EXPLORER;
#else
  ofn.Flags=OFN_HIDEREADONLY;
#endif
  ofn.lStructSize=sizeof(ofn);
  if (!GetSaveFileName(&ofn))return;
  fd = fopen (fname, "w");
  if (!fd)
    {
      sprintf (msg,CP[55], fname);
      ShowMessage(msg);
      return;
    }
  /*fprintf (fd, "gnuchess game %d\n", u);*/
  fprintf (fd, CP[48], patchlevel);
  fprintf (fd, CP[8]);
  fprintf (fd, CP[9]);
  for (i = 1; i <= GameCnt; i++)
    {
      f = GameList[i].gmove >> 8;
      t = (GameList[i].gmove & 0xFF);
      algbr (f, t, GameList[i].flags);
      if(GameList[i].flags & book)
          fprintf (fd, "%6s  %5d    Book%7ld %5ld", mvstr[0],
          GameList[i].score, 
          GameList[i].nodes, GameList[i].time);
      else
          fprintf (fd, "%6s  %5d     %2d %7ld %5ld", mvstr[0],
          GameList[i].score, GameList[i].depth,
          GameList[i].nodes, GameList[i].time);
      if ((i % 2) == 0)
   {
#ifdef DEBUG40
   if(computer == black){
     int p;
   for(p=0;GameList[i-1].d1[p] && p < 7;p++){
      algbr((GameList[i-1].d1[p]>>8) & 0xff,GameList[i-1].d1[p] & 0xff,0);
           fprintf(fd," %s",mvstr[0]);
   }
   fprintf(fd,"\n");
   } else {
   int p;
   for(p=0;GameList[i].d1[p] && p < 7;p++){
      algbr(GameList[i].d1[p]>>8 & 0xff,GameList[i].d1[p] & 0xff,0);
           fprintf(fd," %s",mvstr[0]);
   }
   fprintf(fd,"\n");
   }
#else
   fprintf(fd,"\n");
#endif
    }
   }
  fprintf (fd, "\n\n");
  if (GameList[GameCnt].flags & draw)
    {
      fprintf (fd, CP[20], DRAW);
    }
  else if (GameList[GameCnt].score == -9999)
    {
      fprintf (fd, "%s\n", ColorStr[player ]);
    }
  else if (GameList[GameCnt].score == 9998)
    {
      fprintf (fd, "%s\n", ColorStr[player ^ 1]);
    }
  fclose (fd);
}

void
Undo (void)

/*
 * 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)
    (void) castle (GameList[GameCnt].color, f, t, 2);
  else
    {
      /* Check for promotion: */
      if (GameList[GameCnt].flags & promote)
   {
     board[t] = pawn;
   }
      board[f] = board[t];
      color[f] = color[t];
      board[t] = GameList[GameCnt].piece;
      color[t] = GameList[GameCnt].color;
      if (color[t] != neutral)
   Mvboard[t]--;
      Mvboard[f]--;
    }
  if (GameList[GameCnt].flags & epmask)
    EnPassant (otherside[color[f]], f, t, 2);
  else
    InitializeStats ();
  epsquare = GameList[GameCnt].epssq;
  if (TCflag && (TCmoves>1))
    ++TimeControl.moves[color[f]];
  hashkey = GameList[GameCnt].hashkey;
  hashbd = GameList[GameCnt].hashbd;
  GameCnt--;
  flag.mate = false;
  hint = 0;
  Sdepth = 0;
  origplayer ^= 1;
  ShowSidetoMove ();
/*
  if (flag.regularstart)
*/
  if (flag.usebook) Book = BOOKFAIL;
}

SHORT
 TestSpeed (void (*f) (SHORT side, SHORT ply))
{
  unsigned i;
  long cnt, rate=0, t1, t2;

  t1 = GetTickCount();
  for (i = 0; i < 5000; i++)
    {
      f (opponent, 2);
    }
  t2 = GetTickCount();
  cnt = 5000L * (TrPnt[3] - TrPnt[2]);
  if (t2!=t1)rate = cnt*1000/(t2-t1);
  sprintf(msg,"Nodes= %u, Nodes/Sec= %u", cnt, rate);
  MessageBox(0,msg,"",0);
  return(TrPnt[3] - TrPnt[2]);
}

void
 TestPSpeed (SHORT (*f) (SHORT side), unsigned j)
{
  SHORT i;
  long cnt, rate, t1, t2;
#ifdef HAVE_GETTIMEOFDAY
struct timeval tv;
#endif

#ifdef HAVE_GETTIMEOFDAY
  gettimeofday(&tv,NULL);
  t1 = (tv.tv_sec*100+(tv.tv_usec/10000));
#else
  t1 = time (0);
#endif
  for (i = 0; i < j; i++)
    {
      (void) f (opponent);
    }
#ifdef HAVE_GETTIMEOFDAY

⌨️ 快捷键说明

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