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

📄 nondsp.c

📁 早期freebsd实现
💻 C
📖 第 1 页 / 共 2 页
字号:
/*  UNIX & MSDOS NON-DISPLAY, AND CHESSTOOL 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>#ifdef MSDOS#include <dos.h>#include <stdlib.h>#include <time.h>#else#include <sys/param.h>#include <sys/times.h>#include <sys/file.h>struct tms tmbuf1,tmbuf2;int TerminateSearch(),Die();#endif MSDOS#include "gnuchess.h"#ifdef NEWMOVE#include "move.h"#endif#define printz printf#define scanz scanfint mycnt1,mycnt2;Initialize(){  mycnt1 = mycnt2 = 0;#ifndef MSDOS#endif#ifdef CHESSTOOL  setlinebuf(stdout);/*  setvbuf(stdout,NULL,_IOLBF,BUFSIZ);*/  printf("Chess\n");  if (Level == 0 && !TCflag) Level = 15;#endif CHESSTOOL}ExitChess(){  ListGame();  exit(0);}#ifndef MSDOSDie(){char s[80];  printz("Abort? ");  scanz("%s",s);  if (strcmp(s,"yes") == 0) ExitChess();}TerminateSearch(){  timeout = true;  bothsides = false;}#endif MSDOSInputCommand()/*   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. */{int i;short ok,tmp;long cnt,rate,t1,t2;unsigned short mv;char s[80];  ok = quit = false;  player = opponent;  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))        {          SelectMove(computer,2);          VerifyMove(mvstr1,2,&mv);          if (Sdepth > 0) Sdepth--;        }      ft = time((long *)0) - time0;      epsquare = tmp;    }  #ifndef MSDOS#endif  while (!(ok || quit))    {      PromptForMove();      i = scanz("%s",s);      if (i == EOF || s[0] == 0) ExitChess();      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,"set") == 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,"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,"rcptr") == 0) rcptr = !rcptr;      if (strcmp(s,"hint") == 0) GiveHint();      if (strcmp(s,"zero") == 0) ZeroTTable();      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,"undo") == 0 && GameCnt >= 0) Undo();      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);          printz("cnt= %ld  rate= %ld\n",cnt,rate);        }    }      ElapsedTime(1);  if (force)    {      computer = opponent; opponent = otherside[computer];    }#ifndef MSDOS  (void) times(&tmbuf1);#ifdef CHESSTOOL  printf("%d. %s\n",++mycnt2,s);#endif CHESSTOOL#endif MSDOS}help(){  ClrScreen();  printz("CHESS command summary\n");  printz("g1f3      move from g1 to f3\n");  printz("nf3       move knight to f3\n");  printz("o-o       castle king side\n");  printz("o-o-o     castle queen side\n");  printz("set       edit board\n");  printz("switch    sides with computer\n");  printz("white     computer plays white\n");  printz("black     computer plays black\n");  printz("reverse   board display\n");  printz("both      computer match\n");  printz("random    randomize play\n");  printz("undo      undo last move\n");  printz("time      change level\n");  printz("depth     set search depth\n");  printz("post      principle variation\n");  printz("hint      suggest a move\n");  printz("bd        redraw board\n");  printz("clock     set time control\n");  printz("force     enter game moves\n");  printz("list      game to chess.lst\n");  printz("save      game to file\n");  printz("get       game from file\n");  printz("new       start new game\n");  printz("quit      exit CHESS\n");  printz("Computer: ");  if (computer == white) printz("WHITE\n"); else printz("BLACK\n");  printz("Opponent: ");  if (opponent == white) printz("WHITE\n"); else printz("BLACK\n");  printz("Response time: %ld",Level," sec.\n");  printz("Easy mode: ");  if (easy) printz("ON\n"); else printz("OFF\n");  printz("Depth: %d\n",MaxSearchDepth);  printz("Random: ");   if (dither) printz("ON\n"); else printz("OFF\n");  printz("Transposition table: ");  if (hashflag) printz("ON\n"); else printz("OFF\n");  UpdateDisplay(0,0,1,0);}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);  printz(".   exit to main\n");  printz("#   clear board\n");  printz("enter piece & location: \n");    a = white;  do  {    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; }      }  }  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);}ShowDepth(ch)char ch;{}ShowResults(score,bstline,ch)short score;unsigned short bstline[];char ch;{#ifndef CHESSTOOLregister int i;  printz("%2d%c  %5d %4ld %7ld   ",Sdepth,ch,score,et,NodeCnt);  for (i = 1; bstline[i] > 0; i++)    {      algbr((short)(bstline[i] >> 8),(short)(bstline[i] & 0xFF),false);      if (i == 9 || i == 17) printz("\n                          ");      printz("%5s ",mvstr1);    }  printz("\n");#endif}SearchStartStuff(side)short side;{#ifndef MSDOS#endif#ifndef CHESSTOOL  printz("\nMove# %d    Target= %ld    Clock: %ld\n",          TCmoves-TimeControl.moves[side]+1,          ResponseTime,TimeControl.clock[side]);#endif}OutputMove(){#ifdef CHESSTOOL  printz("%d. ... %s\n",++mycnt1,mvstr1);  if (root->flags & draw)    {      printz("Draw\n");      ListGame();      exit(0);    }  if (root->score == -9999)    {      if (opponent == white) printz("White\n"); else printz("Black\n");      ListGame();      exit(0);    }  if (root->score == 9998)    {      if (computer == white) printz("White\n"); else printz("Black\n");      ListGame();      exit(0);    }

⌨️ 快捷键说明

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