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

📄 uxdsp.c

📁 早期freebsd实现
💻 C
📖 第 1 页 / 共 2 页
字号:
/*  ALPHA interface for CHESS     Revision: 4-25-88     Copyright (C) 1986, 1987, 1988 Free Software Foundation, Inc.  Copyright (c) 1988  John Stanback  This file is part of CHESS.  CHESS is distributed in the hope that it will be useful,  but WITHOUT ANY WARRANTY.  No author or distributor  accepts responsibility to anyone for the consequences of using it  or for whether it serves any particular purpose or works at all,  unless he says so in writing.  Refer to the CHESS General Public  License for full details.  Everyone is granted permission to copy, modify and redistribute  CHESS, but only under the conditions described in the  CHESS General Public License.   A copy of this license is  supposed to have been given to you along with CHESS so you  can know your rights and responsibilities.  It should be in a  file named COPYING.  Among other things, the copyright notice  and this notice must be preserved on all copies.*/#include <stdio.h>#include <ctype.h>#include <sys/param.h>#include <sys/times.h>#include <sys/file.h>#include <curses.h>#include <signal.h>#include "gnuchess.h"#ifdef NEWMOVE#include "move.h"#endif#include "pathnames.h"struct tms tmbuf1,tmbuf2;void TerminateSearch(),Die();#define scanz fflush(stdout),scanw#define printz printwInitialize(){  signal(SIGINT,Die); signal(SIGQUIT,Die);  initscr();  crmode();}ExitChess(){  nocrmode();  endwin();  exit(0);}voidDie(){char s[80];  signal(SIGINT,SIG_IGN);  signal(SIGQUIT,SIG_IGN);  ShowMessage("Abort? ");  scanz("%s",s);  if (strcmp(s,"yes") == 0) ExitChess();  signal(SIGINT,Die); signal(SIGQUIT,Die);}voidTerminateSearch(){  signal(SIGINT,SIG_IGN);  signal(SIGQUIT,SIG_IGN);  timeout = true;  bothsides = false;  signal(SIGINT,Die); signal(SIGQUIT,Die);}InputCommand()/*   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. */{short ok,i,tmp;long cnt,rate,t1,t2;unsigned short mv;char s[80];  ok = quit = false;  player = opponent;  ShowSidetomove();  ft = 0;  if (hint > 0 && !easy && Book == NULL)    {      fflush(stdout);      time0 = time((long *)0);      algbr(hint>>8,hint & 0xFF,false);      strcpy(s,mvstr1);      tmp = epsquare;      if (VerifyMove(s,1,&mv))        {          PromptForMove();          SelectMove(computer,2);          VerifyMove(mvstr1,2,&mv);          if (Sdepth > 0) Sdepth--;        }      ft = time((time_t *)0) - time0;      epsquare = tmp;    }    signal(SIGINT,Die); signal(SIGQUIT,Die);  while (!(ok || quit))    {      PromptForMove();      scanz("%s",s);      player = opponent;      ok = VerifyMove(s,0,&mv);      if (ok && mv != hint)        {          Sdepth = 0;          ft = 0;        }              if (strcmp(s,"bd") == 0)        {          ClrScreen();          UpdateDisplay(0,0,1,0);        }      if (strcmp(s,"quit") == 0) quit = true;      if (strcmp(s,"post") == 0) post = !post;      if (strcmp(s,"edit") == 0) EditBoard();      if (strcmp(s,"go") == 0) ok = true;      if (strcmp(s,"help") == 0) help();      if (strcmp(s,"force") == 0) force = !force;      if (strcmp(s,"book") == 0) Book = NULL;      if (strcmp(s,"undo") == 0 && GameCnt >= 0) Undo();      if (strcmp(s,"new") == 0) NewGame();      if (strcmp(s,"list") == 0) ListGame();      if (strcmp(s,"level") == 0) SelectLevel();      if (strcmp(s,"hash") == 0) hashflag = !hashflag;      if (strcmp(s,"beep") == 0) beep = !beep;      if (strcmp(s,"Awindow") == 0) ChangeAlphaWindow();      if (strcmp(s,"Bwindow") == 0) ChangeBetaWindow();      if (strcmp(s,"hint") == 0) GiveHint();      if (strcmp(s,"both") == 0)        {          bothsides = !bothsides;          Sdepth = 0;          SelectMove(opponent,1);          ok = true;        }      if (strcmp(s,"reverse") == 0)        {          reverse = !reverse;          ClrScreen();          UpdateDisplay(0,0,1,0);        }      if (strcmp(s,"switch") == 0)        {          computer = otherside[computer];          opponent = otherside[opponent];          force = false;          Sdepth = 0;          ok = true;        }      if (strcmp(s,"white") == 0)          {          computer = white; opponent = black;          ok = true; force = false;          Sdepth = 0;        }      if (strcmp(s,"black") == 0)        {          computer = black; opponent = white;          ok = true; force = false;          Sdepth = 0;        }      if (strcmp(s,"remove") == 0 && GameCnt >= 1)         {          Undo(); Undo();        }      if (strcmp(s,"get") == 0) GetGame();      if (strcmp(s,"save") == 0) SaveGame();      if (strcmp(s,"depth") == 0) ChangeSearchDepth();      if (strcmp(s,"random") == 0) dither = 6;      if (strcmp(s,"easy") == 0) easy = !easy;      if (strcmp(s,"contempt") == 0) SetContempt();      if (strcmp(s,"xwndw") == 0) ChangeXwindow();      if (strcmp(s,"test") == 0)        {          t1 = time(0);          cnt = 0;          for (i = 0; i < 10000; i++)            {              MoveList(opponent,2);              cnt += TrPnt[3] - TrPnt[2];            }          t2 = time(0);          rate = cnt / (t2-t1);          gotoXY(50,24);          printz("cnt= %ld  rate= %ld",cnt,rate);          ClrEoln();        }      if (strcmp(s,"p") == 0) ShowPostnValues();      if (strcmp(s,"debug") == 0) DoDebug();    }      ClearMessage();  ElapsedTime(1);  if (force)    {      computer = opponent; opponent = otherside[computer];    }  (void) times(&tmbuf1);  signal(SIGINT,TerminateSearch); signal(SIGQUIT,TerminateSearch);}EditBoard()/*    Set up a board position. Pieces are entered by typing the piece    followed by the location. For example, Nf3 will place a knight on    square f3. */{short a,r,c,sq;char s[80];  ClrScreen();  UpdateDisplay(0,0,1,0);  gotoXY(50,2); printz(".   Exit to main");  gotoXY(50,3); printz("#   Clear board");  gotoXY(49,5); printz("Enter piece & location: ");  a = white;  do  {    gotoXY(73,5); ClrEoln(); scanz("%s",s);    if (s[0] == '#')      {        for (sq = 0; sq < 64; sq++)          {            board[sq] = no_piece; color[sq] = neutral;          }        UpdateDisplay(0,0,1,0);      }    if (s[0] == 'c' || s[0] == 'C') a = otherside[a];    c = s[1]-'a'; r = s[2]-'1';    if ((c >= 0) && (c < 8) && (r >= 0) && (r < 8))      {        sq = locn[r][c];        color[sq] = a;        if (s[0] == 'p') board[sq] = pawn;        else if (s[0] == 'n') board[sq] = knight;        else if (s[0] == 'b') board[sq] = bishop;        else if (s[0] == 'r') board[sq] = rook;        else if (s[0] == 'q') board[sq] = queen;        else if (s[0] == 'k') board[sq] = king;        else { board[sq] = no_piece; color[sq] = neutral; }        DrawPiece(sq);      }  }  while (s[0] != '.');  if (board[4] != king) kingmoved[white] = 10;  if (board[60] != king) kingmoved[black] = 10;  GameCnt = -1; Game50 = 0; Sdepth = 0;  InitializeStats();  ClrScreen();  UpdateDisplay(0,0,1,0);}help(){  ClrScreen();  gotoXY(28,1); printz("CHESS command summary");  gotoXY(1,3); printz("g1f3      move from g1 to f3");  gotoXY(1,4); printz("nf3       move knight to f3");  gotoXY(1,5); printz("o-o       castle king side");  gotoXY(1,6); printz("o-o-o     castle queen side");  gotoXY(1,7); printz("edit      edit board");  gotoXY(1,8); printz("switch    sides with computer");  gotoXY(1,9); printz("white     computer plays white");  gotoXY(1,10); printz("black     computer plays black");  gotoXY(1,11); printz("reverse   board display");  gotoXY(1,12); printz("both      computer match");  gotoXY(1,13); printz("random    randomize play");  gotoXY(1,14); printz("undo      undo last move");  gotoXY(42,3); printz("level     change level");  gotoXY(42,4); printz("depth     set search depth");  gotoXY(42,5); printz("post      principle variation");  gotoXY(42,6); printz("hint      suggest a move");  gotoXY(42,7); printz("bd        redraw board");  gotoXY(42,8); printz("force     enter game moves");  gotoXY(42,9); printz("list      game to chess.lst");  gotoXY(42,10); printz("save      game to file");  gotoXY(42,11); printz("get       game from file");  gotoXY(42,12); printz("new       start new game");  gotoXY(42,13); printz("quit      exit CHESS");  gotoXY(10,21); printz("Computer: ");  if (computer == white) printz("WHITE"); else printz("BLACK");  gotoXY(10,22); printz("Opponent: ");  if (opponent == white) printz("WHITE"); else printz("BLACK");  gotoXY(10,23); printz("Level: %ld",Level," sec.");  gotoXY(10,24); printz("Easy mode: ");  if (easy) printz("ON"); else printz("OFF");  gotoXY(40,21); printz("Depth: %d",MaxSearchDepth);  gotoXY(40,22); printz("Random: ");   if (dither) printz("ON"); else printz("OFF");  gotoXY(40,23); printz("Transposition table: ");  if (hashflag) printz("ON"); else printz("OFF");  refresh();  while (getchar() != 27);  ClrScreen();  UpdateDisplay(0,0,1,0);}ShowDepth(ch)char ch;{  gotoXY(50,4); printz("Depth= %d%c ",Sdepth,ch); ClrEoln();}ShowResults(score,bstline,ch)short score;unsigned short bstline[];char ch;{short d,e,ply;  if (post && player == computer)    {      e = lpost;      gotoXY(50,5); printz("Score= %d",score); ClrEoln();      d = 8; gotoXY(50,d); ClrEoln();      for (ply = 1; bstline[ply] > 0; ply++)        {          algbr(bstline[ply] >> 8,bstline[ply] & 0xFF,false);          if (ply == 5 || ply == 9 || ply == 13 || ply == 17)            {              gotoXY(50,++d); ClrEoln();            }          printz("%5s ",mvstr1);        }      ClrEoln();      lpost = d;      while (++d <= e)        {          gotoXY(50,d); ClrEoln();        }    }}SearchStartStuff(side)short side;{short i;  signal(SIGINT,TerminateSearch); signal(SIGQUIT,TerminateSearch);  if (player == computer)    for (i = 5; i < 14; i++)      {        gotoXY(50,i); ClrEoln();      }}OutputMove(){  if (root->flags & epmask) UpdateDisplay(0,0,1,0);  else UpdateDisplay(root->f,root->t,0,root->flags & cstlmask);  gotoXY(50,17); printz("My move is: %s",mvstr1);  if (beep) putchar(7);  ClrEoln();    gotoXY(50,24);  if (root->flags & draw) printz("Draw game!");  else if (root->score == -9999) printz("opponent mates!");  else if (root->score == 9998) printz("computer mates!");  else if (root->score < -9000) printz("opponent will soon mate!");  else if (root->score > 9000)  printz("computer will soon mate!");  ClrEoln();    if (post)    {      gotoXY(50,22); printz("Nodes=   %6ld",NodeCnt); ClrEoln();      gotoXY(50,23); printz("Nodes/Sec= %4ld",evrate); ClrEoln();    }}ElapsedTime(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. */short iop;{  et = time((time_t *)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((time_t *)0); et0 = 0;        }      (void) times(&tmbuf2);      cputimer = 100*(tmbuf2.tms_utime - tmbuf1.tms_utime) / HZ;      if (cputimer > 0) evrate = (100*NodeCnt)/(cputimer+100*ft);      else evrate = 0;      ETnodes = NodeCnt + 50;      UpdateClocks();    }}UpdateClocks(){short m,s;  m = et/60; s = (et - 60*m);  if (TCflag)    {      m = (TimeControl.clock[player] - et) / 60;      s = TimeControl.clock[player] - et - 60*m;    }  if (m < 0) m = 0;  if (s < 0) s = 0;  if (player == white)    if (reverse) gotoXY(20,2); else gotoXY(20,23);  else    if (reverse) gotoXY(20,23); else gotoXY(20,2);  printz("%d:%2d   ",m,s);  if (post)    {      gotoXY(50,22); printz("Nodes=   %6ld",NodeCnt);      gotoXY(50,23); printz("Nodes/Sec= %4ld",evrate);    }  refresh();}SetTimeControl(){  if (TCflag)    {      TimeControl.moves[white] = TimeControl.moves[black] = TCmoves;      TimeControl.clock[white] = TimeControl.clock[black] = 60*(long)TCminutes;

⌨️ 快捷键说明

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