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

📄 dspcom.c

📁 GNU国际象棋C++源代码Windows版的
💻 C
📖 第 1 页 / 共 3 页
字号:
  gettimeofday(&tv,NULL);
  t2 = (tv.tv_sec*100+(tv.tv_usec/10000));
#else
  t2 = time (0);
#endif
  cnt = j;
  if (t2 - t1)
    et = (t2 - t1);
  else
    et = 1;
  rate = (et) ? ((cnt*100) / et) : 0;
  /*printz ("Nodes= %ld Nodes/sec= %ld\n", cnt, rate);*/
  ShowNodeCnt (cnt);
}

void
InputCommand (void)

/*
 * Process the users command. If easy mode is OFF (the computer is thinking
 * on opponents time) and the program is out of book, then make the 'hint'
 * move on the board and call SelectMove() to find a response. The user
 * terminates the search by entering ^C (quit siqnal) before entering a
 * command. If the opponent does not make the hint move, then set Sdepth to
 * zero.
 */

{
#ifdef QUIETBACKGROUND
  SHORT have_shown_prompt = false;
#endif
  SHORT tmp;
  UTSHORT mv;
  CHAR s[80], sx[80];
  CHAR *p, *q;

#if defined CHESSTOOL
  SHORT normal = false;
#endif

  ok = flag.quit = flag.bothsides = false;
  if (command>0 && !(command & 0x8000))origplayer=computer;
  else origplayer=opponent;
  command&=0x7FFF;
  ElapsedTime(1);
  player = opponent;
/* if transposition table is filling start it over */
 ZeroTTable(1); /* clear ageing table entries */
/* if we have a move for our opponent, and we are thinking on his time, and not in force mode */
  if (hint > 0 && !flag.easy && !flag.force && !command)
/* if the hint is a promotion don't do anything, we don't know what to promote to. */
    if ((board[hint >> 8] != pawn) || ((row (hint & 0x3f) != 0) && (row (hint & 0x3f) != 7)))
      {
   ft = time0;
/* create the hint move as string so we can do it */
   algbr ((SHORT) hint >> 8, (SHORT) hint & 0x3f, false);
   strcpy (s, mvstr[0]);
   tmp = epsquare;
#ifdef DEBUG12
#include "debug12.h"
#endif
   SaveBoard();
/* do the hint move */
   if (VerifyMove (s, 1, &mv))
     {
#ifdef QUIETBACKGROUND
       ShowSidetoMove ();
       have_shown_prompt = true;
#endif /* QUIETBACKGROUND */
/* would love to put null move in here */
/* after we make the hint move make a 2 ply search with both plys our moves */
/* think on opponents time */
       SelectMove (computer, 2);
/* undo the hint and carry on */
       VerifyMove (s, 2, &mv);
     }
   epsquare = tmp;
   time0 = ft;
      }
  while (!(ok || flag.quit))
    {
#if defined CHESSTOOL
      normal = false;
#endif
      player = opponent;
#ifdef QUIETBACKGROUND
      if (!have_shown_prompt)
   {
#endif /* QUIETBACKGROUND */
     ShowSidetoMove ();
#ifdef QUIETBACKGROUND
   }
      have_shown_prompt = false;
#endif /* QUIETBACKGROUND */
      while (!command)
       {
         CheckMessage();
         ElapsedTime(0);
       }
      if (flag.quit)Exit(0);
      strcpy(sx,move);
      sscanf (sx, "%s", s);
      if (command>100)
      {
       short cmnd;
       cmnd=command;
       command=0;
       switch (cmnd)
       {
        case IDM_NEW:
          origplayer=white;
          NewGame();
          UpdateDisplay(0,0,1,0,0);
          break;
        case IDM_GET:
          if (!GetGame())
           {
            player=origplayer;
            if (player==computer)ok=true;
           }
          else origplayer=opponent;
          break;
        case IDM_SAVE:
          SaveGame();
          break;
        case IDM_LIST:
          ListGame();
          player=origplayer;
          if (player==computer)ok=true;
          break;
        case IDM_QUIT:
          flag.quit=true;
          break;
        case IDM_EDIT:
          EditBoard();
          origplayer=opponent;
          hint=0;
          break;
        case IDM_REVIEW:
          Replay();
          player=origplayer;
          if (player==computer)ok=true;
          break;
        case IDM_REMOVE:
          Undo();
        case IDM_UNDO:
          Undo();
          player=origplayer;
          if (player==computer) ok = true;
          UpdateDisplay (0, 0, 1, 0, 0);
          break;
        case IDM_FORCE:
          flag.force = !flag.force;
          flag.bothsides = false;
          if (!flag.force && forcing)
           {
            Sdepth=0;
            ok=true;
            computer^=1;
            opponent^=1;
           }
          else
           {
            if (origplayer==opponent) forcing=0;
            else
             {
              forcing=1;
              computer^=1;
              opponent^=1;
             }
           }
          break;
        case IDM_COMPILE:
          lpfnDlgProc = MakeProcInstance ( CompileBookDlgProc, hInst);
          DialogBox ( hInst, MAKEINTRESOURCE(COMPILEBOOK), hWnd,
                lpfnDlgProc);
          FreeProcInstance ( lpfnDlgProc);
          break;
        case IDM_BOTH:
         flag.bothsides = true;
         if (flag.force && forcing)
          {
           computer^=1;
           opponent^=1;
          }
         flag.force=false;
         Sdepth = 0;
         ElapsedTime (1);
         SaveBoard();
         SelectMove (opponent, 1);
         ok = true;
         break;

        case IDM_SWITCHDM:
          player=origplayer=computer;
        case IDM_SWITCH:
          computer = computer ^ 1;
          opponent = opponent ^ 1;
          xwndw = (computer == white) ? WXwindow : BXwindow;
          goto changeside;
        case IDM_WHITE:
        case IDM_BLACK:
         {
          SHORT color=(cmnd-IDM_BLACK)^1;
          if (computer==color^(flag.force && forcing))continue;
          if (flag.force && forcing)
           {
            computer = color^1;
            opponent = color;
           }
          else
           {
            computer = color;
            opponent = color^1;
           }
          xwndw = computer==white ? WXwindow : BXwindow;
         }
changeside:
          if (!flag.force)
           {
            Sdepth = 0;
            player=origplayer;
            if (player==computer) ok=true;
            ShowPlayers ();
           }
          else
           {
            computer^=forcing;
            ShowPlayers();
            computer^=forcing;
            computer^=1;
            opponent^=1;
            forcing^=1;
           }
          if (computer^(flag.force & forcing)==flag.reverse)
           {
            flag.reverse=!(computer^(flag.force & forcing));
            InvalidateRect(hWnd,0,true);
            UpdateWindow(hWnd);
           }
          hint=0;
          break;
        case IDM_WTM:
        case IDM_BTM:
          player = origplayer = (cmnd==IDM_WTM)? white : black;
          if (player==computer)ok = true;
          if (flag.force)
           {
            computer = opponent;
            opponent = computer ^ 1;
            forcing ^= 1;
           }
          InitializeStats(); /*May crash or make illegal move without this.*/
       }
      }
   else
   {
/* It must be a move */
/* preprocess move;
   remove x or +
   change promotion from h1=Q to h1q
*/
   p=s; q=sx;
   while (*p != '\0'){
   if(*p == 'x' || *p == '+') p++;
   else if(*p == '='){ p++; *q = tolower(*p); p++; q++;}
      else {*q++ = *p++; }
   }
   *q = '\0';

   ok = VerifyMove (sx, 0, &mv);
   command=0;
   if (flag.force && ok)
    {
      hint=0;
      computer = opponent;
      opponent = computer ^ 1;
      forcing ^= 1;
    }
   }
    }

  /* guess is correct ?*/
  Sdepth = (hint == mv) ? Sdepth-1 : 0;
  if (Tree[0].score > 9000) Sdepth = 0;

}

#ifdef HAVE_GETTIMEOFDAY
void
ElapsedTime (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. iop = 0 calculate et bump ETnodes
 * iop = 1 calculate et set timeout if time exceeded, calculate et
 */

{ long old_et;
  struct timeval tv;

  old_et=et;
  gettimeofday(&tv,NULL);
  et = (tv.tv_sec*100+(tv.tv_usec/10000)) - time0;
  ETnodes = NodeCnt + Znodes;
  if (et < 0)
    et = 0;
  if (iop == 1)
    {
      if (et > ResponseTime + ExtraTime && Sdepth > MINDEPTH)
   flag.timeout = true;
      ETnodes = NodeCnt + Znodes;
      gettimeofday(&tv,NULL);
      time0 = tv.tv_sec*100+tv.tv_usec/10000;
    }
#if !defined NONDSP
#ifdef QUIETBACKGROUND
  if (!background)
#endif /* QUIETBACKGROUND */
    if(et/100>old_et/100 && !flag.mate)UpdateClocks ();
#endif
#if defined(Think_C) && defined(Window_Events)
        check_events();
#endif

}
#else
void
ElapsedTime (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. iop = 0 calculate et bump ETnodes
 * iop = 1 calculate et set timeout if time exceeded, calculate et
 */
{ long old_et;

  old_et=et;
  et = (GetTickCount() - time0)/10;
  ETnodes = NodeCnt + Znodes;
  if (et < 0)
    et = -et;
  if (iop == 1)
    {
      if (et > ResponseTime + ExtraTime && Sdepth > MINDEPTH)
   flag.timeout = true;
      ETnodes = NodeCnt + Znodes;
      time0 = GetTickCount();
    }
#ifdef QUIETBACKGROUND
  if (!background)
#endif /* QUIETBACKGROUND */
    if (et/100>old_et/100 && !flag.mate)UpdateClocks ();
#if defined(Think_C) && defined(Window_Events)
        check_events();
#endif
}
#endif


static SHORT Nmoves[] = NMOVEINIT;
void
SetTimeControl (void)
{
     flag.gamein = TCflag = false;
      TimeControl.moves[white] = TimeControl.moves[black] = 0;
if (XC){
                  if (XCmore < XC)
                    {
                      TCmoves = XCmoves[XCmore];
                      TCminutes = XCminutes[XCmore];
                      TCseconds = XCseconds[XCmore];
            TCadd = XCadd[XCmore];
                      XCmore++;
                    }
      if((TCminutes+TCseconds) == 0){TCflag = false;} else {
      TCflag = true;
      if(TCmoves == 0)
   {int i; i = (TCminutes*60+TCseconds + 40 * (TCadd/100))/60; 
      if(i > NMOVELIMIT) i = NMOVELIMIT; 
      TCmoves = Nmoves[i]; flag.gamein = true;}
   else flag.gamein = false;
      TimeControl.moves[white] = TimeControl.moves[black] = TCmoves;
      TimeControl.clock[white] += 6000L * TCminutes + TCseconds * 100;
      TimeControl.clock[black] += 6000L * TCminutes + TCseconds * 100;
    }
  }
  flag.onemove = (TCmoves == 1);
  et = 0;
  ElapsedTime (1);
}

⌨️ 快捷键说明

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