📄 dspcom.c
字号:
/*
* dspcom.c - C source for GNU CHESS
*
* Copyright (c) 1988,1989,1990 John Stanback
* Copyright (c) 1992 Free Software Foundation
* Modified by Conor McCarthy for the Windows environment
*
* This file is part of GNU CHESS.
*
* GNU Chess is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
*
* GNU Chess is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with GNU Chess; see the file COPYING. If not, write to
* the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#ifdef WIN386
#define INCLUDE_COMMDLG_H
#endif
#include "gnuchess.h"
#ifndef WIN386
#include <commdlg.h>
#endif
#include "ataks.h"
#include "ttable.h" /* calls ZeroTTable(), probably belongs in main.c*/
#ifdef HAVE_GETTIMEOFDAY
#include <sys/time.h>
#endif
CHAR mvstr[5][7];
#if defined(Think_C) && defined(Window_Events)
#include "doevents.h"
#endif
extern SHORT Mwpawn[64], Mbpawn[64], Mknight[2][64], Mbishop[2][64];
extern CHAR *version, *patchlevel;
extern void LOpeningBook();
#ifdef ECO
extern void EOpeningBook();
SHORT ecomove;
#endif
CHAR *InPtr;
extern SHORT ok;
char filter[]="Chess files (*.chs)\0*.chs\0All files (*.*)\0*.*\0";
int Znodes;
SHORT origplayer,forcing;
void SaveSettings(void);
extern BOOL CALLBACK (*lpfnDlgProc)(HWND, UINT, WPARAM, LPARAM);
BOOL CALLBACK CompileBookDlgProc (HWND, UINT, WPARAM, LPARAM);
#include <ctype.h>
#include <dos.h>
#include <stdlib.h>
#include <string.h>
void Replay(void);
void
algbr (SHORT f, SHORT t, SHORT flag)
/*
* Generate move strings in different formats.
*/
{
int m3p;
if (f != t)
{
/* algebraic notation */
mvstr[0][0] = cxx[column (f)];
mvstr[0][1] = rxx[row (f)];
mvstr[0][2] = cxx[column (t)];
mvstr[0][3] = rxx[row (t)];
mvstr[4][0] = mvstr[0][4] = mvstr[3][0] = '\0';
if (((mvstr[1][0] = pxx[board[f]]) == CP[2][1]) || (flag & promote))
{
if (mvstr[0][0] == mvstr[0][2]) /* pawn did not eat */
{
mvstr[2][0] = mvstr[1][0] = mvstr[0][2]; /* to column */
mvstr[2][1] = mvstr[1][1] = mvstr[0][3]; /* to row */
m3p = 2;
}
else
/* pawn ate */
{
mvstr[2][0] = mvstr[1][0] = mvstr[0][0]; /* column */
mvstr[2][1] = mvstr[1][1] = mvstr[0][2]; /* to column */
mvstr[2][2] = mvstr[0][3];
m3p = 3; /* to row */
}
if (flag & promote)
{
mvstr[0][4] = mvstr[1][2] = mvstr[2][m3p] = qxx[flag & pmask];
mvstr[0][5] = mvstr[1][3] = mvstr[2][m3p + 1] = mvstr[3][0] = '\0';
#ifdef CHESSTOOL
mvstr[3][0] = mvstr[0][0]; /* Allow e7e8 for chesstool */
mvstr[3][1] = mvstr[0][1];
mvstr[3][2] = mvstr[0][2];
mvstr[3][3] = mvstr[0][3];
mvstr[3][4] = '\0';
#endif
} else mvstr[2][m3p] = mvstr[1][2] = '\0';
}
else
/* not a pawn */
{
mvstr[2][0] = mvstr[1][0];
mvstr[2][1] = mvstr[0][1];
mvstr[2][2] = mvstr[1][1] = mvstr[0][2]; /* to column */
mvstr[2][3] = mvstr[1][2] = mvstr[0][3]; /* to row */
mvstr[2][4] = mvstr[1][3] = '\0';
strcpy (mvstr[3], mvstr[2]);
mvstr[3][1] = mvstr[0][0];
mvstr[4][0] = mvstr[1][0]; strcpy(&mvstr[4][1],mvstr[0]);
if (flag & cstlmask)
{
if (t > f)
{
strcpy (mvstr[1], mvstr[0]);
strcpy (mvstr[0], CP[3]);
strcpy (mvstr[2], CP[5]);
}
else
{
strcpy (mvstr[1], mvstr[0]);
strcpy (mvstr[0], CP[4]);
strcpy (mvstr[2], CP[6]);
}
}
}
}
else
mvstr[0][0] = mvstr[1][0] = mvstr[2][0] = mvstr[3][0] = mvstr[4][0] = '\0';
}
int
VerifyMove (CHAR *s, SHORT iop, UTSHORT *mv)
/*
* Compare the string 's' to the list of legal moves available for the
* opponent. If a match is found, make the move on the board.
*/
{
static SHORT pnt, tempb, tempc, tempsf, tempst, cnt;
static struct leaf xnode;
struct leaf *node;
*mv = 0;
if (iop == 2)
{
UnmakeMove (opponent, &xnode, &tempb, &tempc, &tempsf, &tempst);
return (false);
}
cnt = 0;
VMoveList (opponent, 2);
pnt = TrPnt[2];
while (pnt < TrPnt[3])
{
node = &Tree[pnt++];
algbr (node->f, node->t, (SHORT) node->flags);
if (strcmp (s, mvstr[0]) == 0 || strcmp (s, mvstr[1]) == 0 ||
strcmp (s, mvstr[2]) == 0 || strcmp (s, mvstr[3]) == 0
|| strcmp (s, mvstr[4]) == 0)
{
cnt++;
xnode = *node;
}
}
if (cnt == 1)
{
MakeMove (opponent, &xnode, &tempb, &tempc, &tempsf, &tempst);
if (SqAtakd (PieceList[opponent][0], computer))
{
UnmakeMove (opponent, &xnode, &tempb, &tempc, &tempsf, &tempst);
#ifdef DEBUG8
if (1)
{
FILE *D;
int r, c, l;
extern UTSHORT PrVar[];
D = fopen ("DEBUG", "a+");
pnt = TrPnt[2];
fprintf (D, "resp = %ld\n", ResponseTime);
fprintf (D, "iop = %d\n", iop);
fprintf (D, "matches = %d\n", cnt);
algbr (hint >> 8, hint & 0xff, (SHORT) 0);
fprintf (D, "hint %s\n", mvstr[0]);
fprintf (D, "inout move is %s\n", s);
for (r = 1; PrVar[r]; r++)
{
algbr (PrVar[r] >> 8, PrVar[r] & 0xff, (SHORT) 0);
fprintf (D, " %s", mvstr[0]);
}
fprintf (D, "\n");
fprintf (D, "legal move are \n");
while (pnt < TrPnt[3])
{
node = &Tree[pnt++];
algbr (node->f, node->t, (SHORT) node->flags);
fprintf (D, "%s %s %s %s %s\n", mvstr[0], mvstr[1], mvstr[2], mvstr[3],mvstr[4]);
}
fprintf (D, "\n current board is\n");
for (r = 7; r >= 0; r--)
{
for (c = 0; c <= 7; c++)
{
l = locn (r, c);
if (color[l] == neutral)
fprintf (D, " -");
else if (color[l] == white)
fprintf (D, " %c", qxx[board[l]]);
else
fprintf (D, " %c", pxx[board[l]]);
}
fprintf (D, "\n");
}
fprintf (D, "\n");
fclose (D);
}
#endif
/* Illegal move in check */
ShowMessage (CP[27]);
return (false);
}
else
{
if (iop == 1)
return (true);
UpdateDisplay (xnode.f, xnode.t, 0, (SHORT) xnode.flags, 0);
if ((board[xnode.t] == pawn)
|| (xnode.flags & capture)
|| (xnode.flags & cstlmask))
{
Game50 = GameCnt;
ZeroRPT ();
}
GameList[GameCnt].depth = GameList[GameCnt].score = 0;
GameList[GameCnt].nodes = 0;
ElapsedTime (1);
GameList[GameCnt].time = (SHORT) (et+50)/100;
if (TCflag)
{
TimeControl.clock[opponent] -= (et-TCadd);
timeopp[oppptr] = et;
--TimeControl.moves[opponent];
}
*mv = (xnode.f << 8) | xnode.t;
algbr (xnode.f, xnode.t, false);
return (true);
}
}
#ifdef DEBUG8
if (1)
{
FILE *D;
int r, c, l;
extern UTSHORT PrVar[];
D = fopen ("DEBUG", "a+");
pnt = TrPnt[2];
fprintf (D, "resp = %ld\n", ResponseTime);
fprintf (D, "iop = %d\n", iop);
fprintf (D, "matches = %d\n", cnt);
algbr (hint >> 8, hint & 0xff, (SHORT) 0);
fprintf (D, "hint %s\n", mvstr[0]);
fprintf (D, "inout move is %s\n", s);
for (r = 1; PrVar[r]; r++)
{
algbr (PrVar[r] >> 8, PrVar[r] & 0xff, (SHORT) 0);
fprintf (D, " %s", mvstr[0]);
}
fprintf (D, "\n");
fprintf (D, "legal move are \n");
while (pnt < TrPnt[3])
{
node = &Tree[pnt++];
algbr (node->f, node->t, (SHORT) node->flags);
fprintf (D, "%s %s %s %s %s\n", mvstr[0], mvstr[1], mvstr[2], mvstr[3],mvstr[4]);
}
fprintf (D, "\n current board is\n");
for (r = 7; r >= 0; r--)
{
for (c = 0; c <= 7; c++)
{
l = locn (r, c);
if (color[l] == neutral)
fprintf (D, " -");
else if (color[l] == white)
fprintf (D, " %c", qxx[board[l]]);
else
fprintf (D, " %c", pxx[board[l]]);
}
fprintf (D, "\n");
}
fprintf (D, "\n");
fclose (D);
}
#endif
/* Illegal move */
ShowMessage (CP[26]);
if (cnt > 1)
ShowMessage (CP[10]);
return (false);
}
int
parser (CHAR *f, int side)
{
int c1, r1, c2, r2;
if (f[4] == 'o')
if (side == black)
return 0x3C3A;
else
return 0x0402;
else if (f[0] == 'o')
if (side == black)
return 0x3C3E;
else
return 0x0406;
else
{
c1 = f[0] - 'a';
r1 = f[1] - '1';
c2 = f[2] - 'a';
r2 = f[3] - '1';
return (locn (r1, c1) << 8) | locn (r2, c2);
}
/*NOTREACHED*/
}
SHORT
GetGame (void)
{
FILE *fd;
CHAR fname[256], *p;
int c, i, j;
int eps = -1;
int side;
SHORT sq;
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="Open Game";
#ifdef WIN32
ofn.Flags=OFN_FILEMUSTEXIST|OFN_HIDEREADONLY|OFN_EXPLORER;
#else
ofn.Flags=OFN_FILEMUSTEXIST|OFN_HIDEREADONLY;
#endif
ofn.lStructSize=sizeof(ofn);
if (!GetOpenFileName(&ofn))return false;
if (fname[0] == '\0')
strcpy (fname, CP[44]); /* chess.000 */
if ((fd = fopen (fname, "r")) != NULL)
{
NewGame ();
fgets (fname, 256, fd);
computer = opponent = white;
InPtr = fname;
skip ();
if (*InPtr == 'c')
computer = black;
else
opponent = black;
skip ();
skip ();
skip ();
Game50 = atoi (InPtr);
skip();
skip();
eps = atoi(InPtr);
fgets (fname, 256, fd);
InPtr = &fname[14];
castld[white] = ((*InPtr == CP[53][0]) ? true : false);
skip ();
skip ();
castld[black] = ((*InPtr == CP[53][0]) ? true : false);
fgets (fname, 256, fd);
InPtr = &fname[11];
skipb ();
TCflag = atoi (InPtr);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -