📄 init.c
字号:
PCENTER = PCENTERS;
#else
PCRASH = PCRASHS + (dither?(rand() % PCRASHV):0);
PCENTER = PCENTERS + (dither?(rand() % PCENTERV):0);
#endif
ShowPlayers();
SetWindowText(hComputerMove,"");
return;
}
void
InitConst (CHAR *lang)
{
FILE *constfile;
CHAR s[512];
CHAR sl[5];
int len, entry;
CHAR *p, *q;
flag.illegal=flag.mate=flag.quit=flag.bothsides=flag.onemove=flag.force=false;
flag.autolist=flag.back=flag.musttimeout=false;
flag.searching=flag.editing=flag.replay=false;
constfile = fopen (LANGFILE, "r");
if (!constfile)
{
constfile = fopen("\\gnuchess\\bin\\gnuchess.lan", "r");
}
if (!constfile)
{
ShowMessage("NO LANGFILE (file gnuchess.lan not found)");
exit (1);
}
while (fgets (s, sizeof (s), constfile))
{
if (s[0] == '!') continue;
len = strlen (s);
for (q = &s[len]; q > &s[8]; q--) if (*q == '}') break;
if (q == &s[8])
{
ShowMessage ("Error in gnuchess.lan");
exit (1);
}
*q = '\0';
if (s[3] != ':' || s[7] != ':' || s[8] != '{')
{
sprintf (msg,"Langfile format error %s", s);
ShowMessage(msg);
exit (1);
}
s[3] = s[7] = '\0';
if (lang == NULL)
{
lang = sl;
strcpy (sl, &s[4]);
}
if (strcmp (&s[4], lang))
continue;
entry = atoi (s);
if (entry < 0 || entry >= CPSIZE)
{
ShowMessage ("Langfile number error");
exit (1);
}
for (q = p = &s[9]; *p; p++)
{
if (*p != '\\')
{
*q++ = *p;
}
else if (*(p + 1) == 'n')
{
*q++ = '\n';
p++;
}
}
*q = '\0';
if (entry < 0 || entry > 255)
{
sprintf (msg,"Langfile error %d", entry);
ShowMessage (msg);
exit (1);
}
CP[entry] = (CHAR *) malloc ((unsigned) strlen (&s[9]) + 1);
if (CP[entry] == NULL)
{
ShowMessage ("Insufficient memory");
exit (1);
}
strcpy (CP[entry], &s[9]);
}
fclose (constfile);
}
void GetMetrics(void)
{
HDC hDC;
HANDLE hOld,hSysFont;
TEXTMETRIC tm;
SIZE size;
RECT rc;
GetWindowRect(GetDesktopWindow(),&rc);
hDC=GetDC(hWnd);
hFont=CreateFont ( (rc.right-rc.left)/50, 0, 0, 0, FW_NORMAL, 0, 0, 0,
ANSI_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS,
DEFAULT_QUALITY, FIXED_PITCH | FF_SWISS, "Helv" );
hSysFont=GetStockObject(SYSTEM_FONT);
hOld=SelectObject(hDC,hFont);
GetTextMetrics(hDC,&tm);
LineSpace=tm.tmHeight;
CharWidth=tm.tmAveCharWidth;
SelectObject(hDC,hSysFont);
GetTextMetrics(hDC,&tm);
SLineSpace=tm.tmHeight;
GetTextExtentPoint(hDC,CP[74],17,&size);
CompColorExt=size.cx+25;
GetTextExtentPoint(hDC,"It is White's move",18,&size);
WhoseTurnExt=size.cx+25;
GetTextExtentPoint(hDC,"My move is a7a8q",16,&size);
CompMoveExt=size.cx+4;
SelectObject(hDC,hOld);
ReleaseDC(hWnd,hDC);
}
void InitScreen(void)
{
SHORT x,y,marginF,marginB,lengthF,lengthB;
if (squarebd)
switch (boardsize)
{
case SMALL:
sqwidthF=sqwidthB=sqdepth=bmsize=40;
break;
case MEDIUM:
sqwidthF=sqwidthB=sqdepth=bmsize=60;
break;
case LARGE:
sqwidthF=sqwidthB=sqdepth=bmsize=80;
}
else
switch (boardsize)
{
case SMALL:
sqwidthF=60;
sqwidthB=42;
sqdepth=40;
bmsize=40;
break;
case MEDIUM:
sqwidthF=90;
sqwidthB=63;
sqdepth=60;
bmsize=60;
break;
case LARGE:
sqwidthF=120;
sqwidthB=84;
sqdepth=80;
bmsize=80;
}
deltaX=(sqwidthF-sqwidthB)*8;
for (y=0;y<8;y++)
{
marginF=deltaX*y/16;
marginB=deltaX*(y+1)/16;
lengthF=sqwidthF*8-(marginF<<1);
lengthB=sqwidthF*8-(marginB<<1);
marginF+=LEFTMARGIN;
marginB+=LEFTMARGIN;
for (x=0;x<8;x++)
{
squares[x][y][0].x=marginF+lengthF*x/8;
squares[x][y][0].y=(8-y)*sqdepth+BACKMARGIN;
squares[x][y][1].x=marginF+lengthF*(x+1)/8;
squares[x][y][1].y=(8-y)*sqdepth+BACKMARGIN;
squares[x][y][2].x=marginB+lengthB*(x+1)/8;
squares[x][y][2].y=(7-y)*sqdepth+BACKMARGIN;
squares[x][y][3].x=marginB+lengthB*x/8;
squares[x][y][3].y=(7-y)*sqdepth+BACKMARGIN;
pieceloc[x+(y<<3)].x=lengthF/16-bmsize/2+squares[x][y][0].x;
pieceloc[x+(y<<3)].y=squares[x][y][2].y;
}
}
boardpg[0]=squares[0][0][0];
boardpg[1]=squares[7][0][1];
boardpg[2]=squares[7][7][2];
boardpg[3]=squares[0][7][3];
}
void CreateStatics(void)
{
SHORT CompMoveXpos,YPos;
YPos=BACKMARGIN+sqdepth*8+LineSpace+BRD_EDGE;
hComputerColor = CreateWindow (lpStatic, NULL,
WS_CHILD | SS_LEFT | WS_VISIBLE,
LEFTMARGIN, YPos, CompColorExt, SLineSpace,
hWnd, (HMENU)0, hInst, NULL);
hWhoseTurn = CreateWindow (lpStatic, NULL,
WS_CHILD | SS_LEFT | WS_VISIBLE,
LEFTMARGIN+CompColorExt, YPos, WhoseTurnExt, SLineSpace,
hWnd, (HMENU)1, hInst, NULL);
hInCheck = CreateWindow (lpStatic, NULL,
WS_CHILD | SS_LEFT | WS_VISIBLE,
LEFTMARGIN+CompColorExt+WhoseTurnExt,
YPos, 120, SLineSpace,
hWnd, (HMENU)2, hInst, NULL);
hComputerMove = CreateWindow (lpStatic, NULL,
WS_CHILD | SS_CENTER | WS_VISIBLE,
CompMoveXpos=LEFTMARGIN+sqwidthB*8+deltaX/2+(20>>squarebd),
65,CompMoveExt, SLineSpace, hWnd, (HMENU)3, hInst, NULL);
hClockBlack = CreateWindow ( lpStatic, NULL,
WS_CHILD | SS_CENTER | WS_VISIBLE,
CompMoveXpos+(CompMoveExt-60)/2, 30,
60, SLineSpace, hWnd, (HMENU)4, hInst, NULL);
hClockWhite = CreateWindow ( lpStatic, NULL,
WS_CHILD | SS_CENTER | WS_VISIBLE,
CompMoveXpos+(CompMoveExt-60)/2, 120,
60, SLineSpace, hWnd, (HMENU)5, hInst, NULL);
hBlack = CreateWindow ( lpStatic, CP[41],
WS_CHILD | SS_CENTER | WS_VISIBLE,
CompMoveXpos+(CompMoveExt-60)/2, 10,
60, SLineSpace, hWnd, (HMENU)6, hInst, NULL);
hWhite = CreateWindow ( lpStatic, CP[40],
WS_CHILD | SS_CENTER | WS_VISIBLE,
CompMoveXpos+(CompMoveExt-60)/2, 100,
60, SLineSpace, hWnd, (HMENU)7, hInst, NULL);
hDepth = CreateWindow ( lpStatic, NULL,
WS_CHILD | SS_CENTER | WS_VISIBLE,
CompMoveXpos+(CompMoveExt-80)/2, 150,
80, SLineSpace, hWnd, (HMENU)1010, hInst, NULL);
}
void MoveStatics(void)
{
SHORT CompMoveXpos;
MoveWindow(hComputerColor,LEFTMARGIN, BACKMARGIN+sqdepth*8+20,
CompColorExt, SLineSpace, false);
MoveWindow(hWhoseTurn,LEFTMARGIN+CompColorExt, BACKMARGIN+sqdepth*8+20,
WhoseTurnExt, SLineSpace, false);
MoveWindow(hInCheck,LEFTMARGIN+CompColorExt+WhoseTurnExt,
BACKMARGIN+sqdepth*8+20,120, SLineSpace, false);
MoveWindow(hComputerMove,CompMoveXpos=LEFTMARGIN+sqwidthB*8+deltaX/2+
(20>>squarebd), 65, CompMoveExt, SLineSpace, false);
MoveWindow(hClockBlack,CompMoveXpos+(CompMoveExt-60)/2, 30,
60, SLineSpace, false);
MoveWindow(hClockWhite,CompMoveXpos+(CompMoveExt-60)/2, 120,
60, SLineSpace, false);
MoveWindow(hBlack,CompMoveXpos+(CompMoveExt-60)/2, 10,
60, SLineSpace, false);
MoveWindow(hWhite,CompMoveXpos+(CompMoveExt-60)/2, 100,
60, SLineSpace, false);
MoveWindow(hDepth,CompMoveXpos+(CompMoveExt-80)/2, 150,
80, SLineSpace, false);
}
BOOL LoadSettings(void)
{
SHORT i;
boardsize=GetPrivateProfileInt(BrdSection,szboardsize,SMALL,IniFile);
squarebd=GetPrivateProfileInt(BrdSection,szsquarebd,0,IniFile);
WinPosX=GetPrivateProfileInt(BrdSection,szwinposX,0,IniFile);
WinPosY=GetPrivateProfileInt(BrdSection,szwinposY,0,IniFile);
WinSizeX=GetPrivateProfileInt(BrdSection,szwinsizeX,0,IniFile);
WinSizeY=GetPrivateProfileInt(BrdSection,szwinsizeY,0,IniFile);
GetPrivateProfileString(BrdSection,szbkgrnd,sznull,msg,sizeof(msg),IniFile);
clrBackGround = msg[0] ? strtoul(msg,0,16) : BROWN;
GetPrivateProfileString(BrdSection,szblacksq,sznull,msg,sizeof(msg),IniFile);
clrBlackSquare = msg[0] ? strtoul(msg,0,16) : DARKGREEN;
GetPrivateProfileString(BrdSection,szwhitesq,sznull,msg,sizeof(msg),IniFile);
clrWhiteSquare = msg[0] ? strtoul(msg,0,16) : PALEGRAY;
GetPrivateProfileString(BrdSection,szblackpc,sznull,msg,sizeof(msg),IniFile);
clrBlackPiece = msg[0] ? strtoul(msg,0,16) : DARKRED;
GetPrivateProfileString(BrdSection,szwhitepc,sznull,msg,sizeof(msg),IniFile);
clrWhitePiece = msg[0] ? strtoul(msg,0,16) : CWHITE;
GetPrivateProfileString(BrdSection,sztext,sznull,msg,sizeof(msg),IniFile);
clrText = msg[0] ? strtoul(msg,0,16) : CBLACK;
GetPrivateProfileString(BrdSection,szedge,sznull,msg,sizeof(msg),IniFile);
clrEdge = msg[0] ? strtoul(msg,0,16) : CBLACK;
for (i=0;i<16;i++)
{
szcustcols[2]=(char)i+'0';
GetPrivateProfileString(BrdSection,szcustcols,sznull,msg,sizeof(msg),IniFile);
if (msg[0]) CustCols[i]=strtoul(msg,0,16);
else CustCols[i]=CCdefs[i];
}
flag.beep=GetPrivateProfileInt(OptSection,szbeep,1,IniFile);
flag.coords=GetPrivateProfileInt(OptSection,szcoords,1,IniFile);
flag.post=GetPrivateProfileInt(OptSection,szstats,0,IniFile);
flag.usebook=GetPrivateProfileInt(OptSection,szbook,1,IniFile);
flag.hash=GetPrivateProfileInt(OptSection,szhash,1,IniFile);
HashDepth=GetPrivateProfileInt(OptSection,szhdepth,HASHDEPTH,IniFile);
HashMoveLimit=GetPrivateProfileInt(OptSection,szmvlim,HASHMOVELIMIT,IniFile);
WAwindow=GetPrivateProfileInt(OptSection,szWA,WAWNDW,IniFile);
WBwindow=GetPrivateProfileInt(OptSection,szWB,WBWNDW,IniFile);
WXwindow=GetPrivateProfileInt(OptSection,szWX,WXWNDW,IniFile);
BAwindow=GetPrivateProfileInt(OptSection,szBA,BAWNDW,IniFile);
BBwindow=GetPrivateProfileInt(OptSection,szBB,BBWNDW,IniFile);
BXwindow=GetPrivateProfileInt(OptSection,szBX,BXWNDW,IniFile);
contempt=GetPrivateProfileInt(OptSection,szcontempt,0,IniFile);
flag.material=GetPrivateProfileInt(OptSection,szmaterial,1,IniFile);
flag.rcptr=GetPrivateProfileInt(OptSection,szrcptr,1,IniFile);
flag.threat=GetPrivateProfileInt(OptSection,szthreat,1,IniFile);
flag.pvs=GetPrivateProfileInt(OptSection,szpvs,1,IniFile);
flag.neweval=GetPrivateProfileInt(OptSection,szne,1,IniFile);
flag.gamein=GetPrivateProfileInt(OptSection,szgamein,0,IniFile);
XCmoves[0]=GetPrivateProfileInt(skillsectn,szXCmv0,0,IniFile);
XCminutes[0]=GetPrivateProfileInt(skillsectn,szXCmin0,0,IniFile);
XCmoves[1]=GetPrivateProfileInt(skillsectn,szXCmv1,0,IniFile);
XCminutes[1]=GetPrivateProfileInt(skillsectn,szXCmin1,0,IniFile);
XCmoves[2]=GetPrivateProfileInt(skillsectn,szXCmv2,0,IniFile);
XCminutes[2]=GetPrivateProfileInt(skillsectn,szXCmin2,0,IniFile);
XC=0;
for (i=0;i<3;i++)
{
if (XCmoves[i] && XCminutes[i])XC++;
else break;
}
GetPrivateProfileString(skillsectn,szMRT,"3000",msg,sizeof(msg),IniFile);
MaxResponseTime=strtol(msg,0,10);
dither=GetPrivateProfileInt(skillsectn,szdither,0,IniFile);
flag.easy=GetPrivateProfileInt(skillsectn,szeasy,1,IniFile);
MaxSearchDepth=GetPrivateProfileInt(skillsectn,szmaxdepth,MAXDEPTH,IniFile);
return GetPrivateProfileInt(BrdSection,szmaximized,0,IniFile);
}
void SaveSettings(void)
{
RECT rect;
SHORT i;
sprintf(msg,shortfs,boardsize);
WritePrivateProfileString(BrdSection,szboardsize,msg,IniFile);
sprintf(msg,shortfs,squarebd);
WritePrivateProfileString(BrdSection,szsquarebd,msg,IniFile);
if (wr.right)
{
sprintf(msg,shortfs,wr.left);
WritePrivateProfileString(BrdSection,szwinposX,msg,IniFile);
sprintf(msg,shortfs,wr.top);
WritePrivateProfileString(BrdSection,szwinposY,msg,IniFile);
sprintf(msg,shortfs,wr.right-wr.left);
WritePrivateProfileString(BrdSection,szwinsizeX,msg,IniFile);
sprintf(msg,shortfs,wr.bottom-wr.top);
WritePrivateProfileString(BrdSection,szwinsizeY,msg,IniFile);
}
sprintf(msg,shortfs,maximized);
WritePrivateProfileString(BrdSection,szmaximized,msg,IniFile);
sprintf(msg,hexuint,clrBackGround);
WritePrivateProfileString(BrdSection,szbkgrnd,msg,IniFile);
sprintf(msg,hexuint,clrBlackSquare);
WritePrivateProfileString(BrdSection,szblacksq,msg,IniFile);
sprintf(msg,hexuint,clrWhiteSquare);
WritePrivateProfileString(BrdSection,szwhitesq,msg,IniFile);
sprintf(msg,hexuint,clrBlackPiece);
WritePrivateProfileString(BrdSection,szblackpc,msg,IniFile);
sprintf(msg,hexuint,clrWhitePiece);
WritePrivateProfileString(BrdSection,szwhitepc,msg,IniFile);
sprintf(msg,hexuint,clrText);
WritePrivateProfileString(BrdSection,sztext,msg,IniFile);
sprintf(msg,hexuint,clrEdge);
WritePrivateProfileString(BrdSection,szedge,msg,IniFile);
for (i=0;i<16;i++)
{
sprintf(msg,hexuint,CustCols[i]);
sprintf(szcustcols+2,shortfs,i);
WritePrivateProfileString(BrdSection,szcustcols,msg,IniFile);
}
sprintf(msg,shortfs,flag.beep);
WritePrivateProfileString(OptSection,szbeep,msg,IniFile);
sprintf(msg,shortfs,flag.coords);
WritePrivateProfileString(OptSection,szcoords,msg,IniFile);
sprintf(msg,shortfs,flag.post);
WritePrivateProfileString(OptSection,szstats,msg,IniFile);
sprintf(msg,shortfs,flag.usebook);
WritePrivateProfileString(OptSection,szbook,msg,IniFile);
sprintf(msg,shortfs,flag.hash);
WritePrivateProfileString(OptSection,szhash,msg,IniFile);
sprintf(msg,shortfs,HashDepth);
WritePrivateProfileString(OptSection,szhdepth,msg,IniFile);
sprintf(msg,shortfs,HashMoveLimit);
WritePrivateProfileString(OptSection,szmvlim,msg,IniFile);
sprintf(msg,shortfs,WAwindow);
WritePrivateProfileString(OptSection,szWA,msg,IniFile);
sprintf(msg,shortfs,WBwindow);
WritePrivateProfileString(OptSection,szWB,msg,IniFile);
sprintf(msg,shortfs,WXwindow);
WritePrivateProfileString(OptSection,szWX,msg,IniFile);
sprintf(msg,shortfs,BAwindow);
WritePrivateProfileString(OptSection,szBA,msg,IniFile);
sprintf(msg,shortfs,BBwindow);
WritePrivateProfileString(OptSection,szBB,msg,IniFile);
sprintf(msg,shortfs,BXwindow);
WritePrivateProfileString(OptSection,szBX,msg,IniFile);
sprintf(msg,shortfs,contempt);
WritePrivateProfileString(OptSection,szcontempt,msg,IniFile);
sprintf(msg,shortfs,flag.material);
WritePrivateProfileString(OptSection,szmaterial,msg,IniFile);
sprintf(msg,shortfs,flag.rcptr);
WritePrivateProfileString(OptSection,szrcptr,msg,IniFile);
sprintf(msg,shortfs,flag.threat);
WritePrivateProfileString(OptSection,szthreat,msg,IniFile);
sprintf(msg,shortfs,flag.pvs);
WritePrivateProfileString(OptSection,szpvs,msg,IniFile);
sprintf(msg,shortfs,flag.neweval);
WritePrivateProfileString(OptSection,szne,msg,IniFile);
sprintf(msg,shortfs,flag.gamein);
WritePrivateProfileString(OptSection,szgamein,msg,IniFile);
sprintf(msg,shortfs,XCmoves[0]);
WritePrivateProfileString(skillsectn,szXCmv0,msg,IniFile);
sprintf(msg,shortfs,XCminutes[0]);
WritePrivateProfileString(skillsectn,szXCmin0,msg,IniFile);
sprintf(msg,shortfs,XCmoves[1]);
WritePrivateProfileString(skillsectn,szXCmv1,msg,IniFile);
sprintf(msg,shortfs,XCminutes[1]);
WritePrivateProfileString(skillsectn,szXCmin1,msg,IniFile);
sprintf(msg,shortfs,XCmoves[2]);
WritePrivateProfileString(skillsectn,szXCmv2,msg,IniFile);
sprintf(msg,shortfs,XCminutes[2]);
WritePrivateProfileString(skillsectn,szXCmin2,msg,IniFile);
sprintf(msg,"%ld",MaxResponseTime);
WritePrivateProfileString(skillsectn,szMRT,msg,IniFile);
sprintf(msg,shortfs,dither);
WritePrivateProfileString(skillsectn,szdither,msg,IniFile);
sprintf(msg,shortfs,flag.easy);
WritePrivateProfileString(skillsectn,szeasy,msg,IniFile);
sprintf(msg,shortfs,MaxSearchDepth);
WritePrivateProfileString(skillsectn,szmaxdepth,msg,IniFile);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -