home *** CD-ROM | disk | FTP | other *** search
/ Más de 2,500 Juegos / CD1.iso / ZIPDAT / 0153 / 0153.ZIP / SRC / INIT.C < prev    next >
Encoding:
C/C++ Source or Header  |  1997-04-08  |  28.2 KB  |  880 lines

  1. /*
  2.  * init.c - C source for GNU CHESS for Windows
  3.  *
  4.  * Copyright (c) 1988,1989,1990 John Stanback
  5.  * Copyright (c) 1992 Free Software Foundation
  6.  * Additions for the Windows version Copyright (c) 1996 Conor McCarthy
  7.  *
  8.  * This file is part of GNU CHESS.
  9.  *
  10.  * GNU Chess is free software; you can redistribute it and/or modify
  11.  * it under the terms of the GNU General Public License as published by
  12.  * the Free Software Foundation; either version 2, or (at your option)
  13.  * any later version.
  14.  *
  15.  * GNU Chess is distributed in the hope that it will be useful,
  16.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  18.  * GNU General Public License for more details.
  19.  *
  20.  * You should have received a copy of the GNU General Public License
  21.  * along with GNU Chess; see the file COPYING.  If not, write to
  22.  * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
  23.  */
  24. #include "gnuchess.h"
  25. #include "ttable.h"
  26. #ifdef HAVE_GETTIMEOFDAY
  27. #include <sys/time.h>
  28. #endif
  29. extern SHORT CompColorExt,WhoseTurnExt,CompMoveExt;
  30. extern SHORT notime;
  31. extern SHORT selected;
  32. extern DWORD CustCols[16];
  33. SHORT WinSizeX,WinSizeY,WinPosX,WinPosY;
  34. RECT wr;
  35. SHORT maximized;
  36. char lpStatic[]="STATIC";
  37.  
  38. char IniFile[]="gnuchess.ini";
  39.  
  40. char hexuint[]="%06X";
  41. char shortfs[]="%hd";
  42.  
  43. char BrdSection[]="board";
  44. char OptSection[]="options";
  45. char skillsectn[]="skill";
  46.  
  47. char szboardsize[]="boardsize";
  48. char szsquarebd[]="squarebd";
  49. char szwinsizeX[]="winsizeX";
  50. char szwinsizeY[]="winsizeY";
  51. char szwinposX[]="winposX";
  52. char szwinposY[]="winposY";
  53. char szmaximized[]="maximized";
  54. char szbkgrnd[]="background";
  55. char szwhitesq[]="whitesquare";
  56. char szblacksq[]="blacksquare";
  57. char szwhitepc[]="whitepiece";
  58. char szblackpc[]="blackpiece";
  59. char sztext[]="text";
  60. char szedge[]="edge";
  61. char szcustcols[]="cc00";
  62. char szbeep[]="beep";
  63. char szcoords[]="coords";
  64. char szstats[]="stats";
  65. char szbook[]="book";
  66. char szhash[]="hash";
  67. char szhdepth[]="hashdepth";
  68. char szmvlim[]="movelimit";
  69. char szWA[]="WAwindow";
  70. char szWB[]="WBwindow";
  71. char szWX[]="WXwindow";
  72. char szBA[]="BAwindow";
  73. char szBB[]="BBwindow";
  74. char szBX[]="BXwindow";
  75. char szcontempt[]="contempt";
  76. char szmaterial[]="material";
  77. char szrcptr[]="recapture";
  78. char szthreat[]="threat";
  79. char szpvs[]="pvs";
  80. char szne[]="neweval";
  81. char szgamein[]="gamein";
  82. char szXCmv0[]="XCmoves0";
  83. char szXCmin0[]="XCminutes0";
  84. char szXCmv1[]="XCmoves1";
  85. char szXCmin1[]="XCminutes1";
  86. char szXCmv2[]="XCmoves2";
  87. char szXCmin2[]="XCminutes2";
  88. char szXC[]="XC";
  89. char szMRT[]="MaxResponseTime";
  90. char szdither[]="dither";
  91. char szeasy[]="easy";
  92. char szmaxdepth[]="maxdepth";
  93. char sznull[]="";
  94. DWORD CCdefs[16]={CBLACK,BLUE,GREEN,CYAN,RED,PINK,YELLOW,PALEGRAY,DARKGRAY,
  95.       DARKBLUE,DARKGREEN,DARKCYAN,DARKRED,DARKPINK,BROWN,CWHITE};
  96.  
  97. /* .... MOVE GENERATION VARIABLES AND INITIALIZATIONS .... */
  98.  
  99.  
  100. SHORT distdata[64][64], taxidata[64][64];
  101.  
  102. #ifdef KILLT
  103. /* put moves to the center first */
  104. void
  105. Initialize_killt (void)
  106. {
  107.   register UTSHORT f, t, s;
  108.   register SHORT d;
  109.   for (f = 0; f < 64; f++)
  110.     for (t = 0; t < 64; t++)
  111.       {
  112.    d = taxidata[f][0x1b];
  113.    if (taxidata[f][0x1c] < d)
  114.      d = taxidata[f][0x1c];
  115.    if (taxidata[f][0x23] < d)
  116.      d = taxidata[f][0x23];
  117.    if (taxidata[f][0x24] < d)
  118.      d = taxidata[f][0x24];
  119.    s = d;
  120.    d = taxidata[t][0x1b];
  121.    if (taxidata[t][0x1c] < d)
  122.      d = taxidata[t][0x1c];
  123.    if (taxidata[t][0x23] < d)
  124.      d = taxidata[t][0x23];
  125.    if (taxidata[t][0x24] < d)
  126.      d = taxidata[t][0x24];
  127.    s -= d;
  128.    killt[(f << 8) | t] = s;
  129.    killt[(f << 8) | t | 0x80] = s;
  130.       }
  131. }
  132. #endif
  133. void
  134. Initialize_dist (void)
  135. {
  136.   register SHORT a, b, d, di;
  137.  
  138.   for (a = 0; a < 64; a++)
  139.     for (b = 0; b < 64; b++)
  140.       {
  141.    d = abs (column (a) - column (b));
  142.    di = abs (row (a) - row (b));
  143.    taxidata[a][b] = d + di;
  144.    distdata[a][b] = (d > di ? d : di);
  145.       }
  146. #ifdef KILLT
  147.   Initialize_killt ();
  148. #endif
  149. }
  150.  
  151. const SHORT Stboard[64] =
  152. {rook, knight, bishop, queen, king, bishop, knight, rook,
  153.  pawn, pawn, pawn, pawn, pawn, pawn, pawn, pawn,
  154.  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  155.  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  156.  pawn, pawn, pawn, pawn, pawn, pawn, pawn, pawn,
  157.  rook, knight, bishop, queen, king, bishop, knight, rook};
  158. const SHORT Stcolor[64] =
  159. {white, white, white, white, white, white, white, white,
  160.  white, white, white, white, white, white, white, white,
  161.  neutral, neutral, neutral, neutral, neutral, neutral, neutral, neutral,
  162.  neutral, neutral, neutral, neutral, neutral, neutral, neutral, neutral,
  163.  neutral, neutral, neutral, neutral, neutral, neutral, neutral, neutral,
  164.  neutral, neutral, neutral, neutral, neutral, neutral, neutral, neutral,
  165.  black, black, black, black, black, black, black, black,
  166.  black, black, black, black, black, black, black, black};
  167. SHORT board[64], color[64];
  168.  
  169. /* given epsquare, from where can a pawn be taken? */
  170. const SHORT epmove1[64] =
  171. {0, 1, 2, 3, 4, 5, 6, 7,
  172.  8, 9, 10, 11, 12, 13, 14, 15,
  173.  16, 24, 25, 26, 27, 28, 29, 30,
  174.  24, 25, 26, 27, 28, 29, 30, 31,
  175.  32, 33, 34, 35, 36, 37, 38, 39,
  176.  40, 32, 33, 34, 35, 36, 37, 38,
  177.  48, 49, 50, 51, 52, 53, 54, 55,
  178.  56, 57, 58, 59, 60, 61, 62, 63};
  179. const SHORT epmove2[64] =
  180. {0, 1, 2, 3, 4, 5, 6, 7,
  181.  8, 9, 10, 11, 12, 13, 14, 15,
  182.  25, 26, 27, 28, 29, 30, 31, 23,
  183.  24, 25, 26, 27, 28, 29, 30, 31,
  184.  32, 33, 34, 35, 36, 37, 38, 39,
  185.  33, 34, 35, 36, 37, 38, 39, 47,
  186.  48, 49, 50, 51, 52, 53, 54, 55,
  187.  56, 57, 58, 59, 60, 61, 62, 63};
  188.  
  189.  
  190. /*
  191.  * nextpos[piece][from-square] , nextdir[piece][from-square] gives vector of
  192.  * positions reachable from from-square in ppos with piece such that the
  193.  * sequence ppos = nextpos[piece][from-square]; pdir =
  194.  * nextdir[piece][from-square]; u = ppos[sq]; do { u = ppos[u]; if(color[u]
  195.  * != neutral) u = pdir[u]; } while (sq != u); will generate the sequence of
  196.  * all squares reachable from sq.
  197.  *
  198.  * If the path is blocked u = pdir[sq] will generate the continuation of the
  199.  * sequence in other directions.
  200.  */
  201.  
  202. UCHAR nextpos[8][64][64];
  203. UCHAR nextdir[8][64][64];
  204.  
  205. /*
  206.  * ptype is used to separate white and black pawns, like this; ptyp =
  207.  * ptype[side][piece] piece can be used directly in nextpos/nextdir when
  208.  * generating moves for pieces that are not black pawns.
  209.  */
  210. const SHORT ptype[2][8] =
  211. { { no_piece, pawn, knight, bishop, rook, queen, king, no_piece },
  212.   { no_piece, bpawn, knight, bishop, rook, queen, king, no_piece } };
  213.  
  214. /* data used to generate nextpos/nextdir */
  215. static const SHORT direc[8][8] =
  216. {
  217.    { 0, 0, 0, 0, 0, 0, 0, 0 },
  218.    { 10, 9, 11, 0, 0, 0, 0, 0 },
  219.    { 8, -8, 12, -12, 19, -19, 21, -21 },
  220.    { 9, 11, -9, -11, 0, 0, 0, 0 },
  221.    { 1, 10, -1, -10, 0, 0, 0, 0 },
  222.    { 1, 10, -1, -10, 9, 11, -9, -11 },
  223.    { 1, 10, -1, -10, 9, 11, -9, -11 },
  224.    { -10, -9, -11, 0, 0, 0, 0, 0 } };
  225. static const SHORT max_steps[8] =
  226. {0, 2, 1, 7, 7, 7, 1, 2};
  227. static const SHORT nunmap[120] =
  228. {
  229.   -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
  230.   -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
  231.   -1, 0, 1, 2, 3, 4, 5, 6, 7, -1,
  232.   -1, 8, 9, 10, 11, 12, 13, 14, 15, -1,
  233.   -1, 16, 17, 18, 19, 20, 21, 22, 23, -1,
  234.   -1, 24, 25, 26, 27, 28, 29, 30, 31, -1,
  235.   -1, 32, 33, 34, 35, 36, 37, 38, 39, -1,
  236.   -1, 40, 41, 42, 43, 44, 45, 46, 47, -1,
  237.   -1, 48, 49, 50, 51, 52, 53, 54, 55, -1,
  238.   -1, 56, 57, 58, 59, 60, 61, 62, 63, -1,
  239.   -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
  240.   -1, -1, -1, -1, -1, -1, -1, -1, -1, -1};
  241.  
  242. int InitFlag = false;
  243. void
  244. Initialize_moves (void)
  245.  
  246. /*
  247.  * This procedure pre-calculates all moves for every piece from every square.
  248.  * This data is stored in nextpos/nextdir and used later in the move
  249.  * generation routines.
  250.  */
  251.  
  252. {
  253.   SHORT ptyp, po, p0, d, di, s, delta;
  254.   UCHAR *ppos, *pdir;
  255.   SHORT dest[8][8];
  256.   SHORT steps[8];
  257.   SHORT sorted[8];
  258.  
  259.   for (ptyp = 0; ptyp < 8; ptyp++)
  260.     for (po = 0; po < 64; po++)
  261.       for (p0 = 0; p0 < 64; p0++)
  262.    {
  263.      nextpos[ptyp][po][p0] = (UCHAR) po;
  264.      nextdir[ptyp][po][p0] = (UCHAR) po;
  265.    }
  266.   for (ptyp = 1; ptyp < 8; ptyp++)
  267.     for (po = 21; po < 99; po++)
  268.       if (nunmap[po] >= 0)
  269.    {
  270.      ppos = nextpos[ptyp][nunmap[po]];
  271.      pdir = nextdir[ptyp][nunmap[po]];
  272.      /* dest is a function of direction and steps */
  273.      for (d = 0; d < 8; d++)
  274.        {
  275.          dest[d][0] = nunmap[po];
  276.          delta = direc[ptyp][d];
  277.          if (delta != 0)
  278.       {
  279.         p0 = po;
  280.         for (s = 0; s < max_steps[ptyp]; s++)
  281.           {
  282.             p0 = p0 + delta;
  283.  
  284.             /*
  285.              * break if (off board) or (pawns only move two
  286.              * steps from home square)
  287.              */
  288.             if ((nunmap[p0] < 0) || (((ptyp == pawn) || (ptyp == bpawn))
  289.                       && ((s > 0) && ((d > 0) || (Stboard[nunmap[po]] != pawn)))))
  290.          break;
  291.             else
  292.          dest[d][s] = nunmap[p0];
  293.           }
  294.       }
  295.          else
  296.       s = 0;
  297.  
  298.          /*
  299.           * sort dest in number of steps order currently no sort
  300.           * is done due to compability with the move generation
  301.           * order in old gnu chess
  302.           */
  303.          steps[d] = s;
  304.          for (di = d; s > 0 && di > 0; di--)
  305.       if (steps[sorted[di - 1]] == 0)  /* should be: < s */
  306.         sorted[di] = sorted[di - 1];
  307.       else
  308.         break;
  309.          sorted[di] = d;
  310.        }
  311.  
  312.      /*
  313.       * update nextpos/nextdir, pawns have two threads (capture
  314.       * and no capture)
  315.       */
  316.      p0 = nunmap[po];
  317.      if (ptyp == pawn || ptyp == bpawn)
  318.        {
  319.          for (s = 0; s < steps[0]; s++)
  320.       {
  321.         ppos[p0] = (UCHAR) dest[0][s];
  322.         p0 = dest[0][s];
  323.       }
  324.          p0 = nunmap[po];
  325.          for (d = 1; d < 3; d++)
  326.       {
  327.         pdir[p0] = (UCHAR) dest[d][0];
  328.         p0 = dest[d][0];
  329.       }
  330.        }
  331.      else
  332.        {
  333.          pdir[p0] = (UCHAR) dest[sorted[0]][0];
  334.          for (d = 0; d < 8; d++)
  335.       for (s = 0; s < steps[sorted[d]]; s++)
  336.         {
  337.           ppos[p0] = (UCHAR) dest[sorted[d]][s];
  338.           p0 = dest[sorted[d]][s];
  339.           if (d < 7)
  340.             pdir[p0] = (UCHAR) dest[sorted[d + 1]][0];
  341.  
  342.           /*
  343.            * else is already initialized
  344.            */
  345.         }
  346.        }
  347.    }
  348. }
  349.  
  350. void
  351. NewGame (void)
  352.  
  353. /*
  354.  * Reset the board and other variables to start a new game.
  355.  */
  356.  
  357. {
  358.   SHORT l;
  359. #ifdef HAVE_GETTIMEOFDAY
  360.   struct timeval tv;
  361. #endif
  362. #ifdef CLIENT
  363.   if(GameCnt >0)ListGame();
  364.   fflush(stdout);
  365. #endif
  366.   compptr = oppptr = 0;
  367.   stage = stage2 = -1;     /* the game is not yet started */
  368.   notime = true;
  369.   if (flag.reverse)InvalidateRect(hWnd,0,true);
  370. flag.illegal=flag.mate=flag.quit=flag.bothsides=flag.onemove=false;
  371. flag.force=flag.back=flag.musttimeout=flag.reverse=false;
  372.  
  373. #ifdef DEBUG
  374.  flag.nott = flag.noft = flag.nocache = false;
  375. #endif
  376.  
  377.   computer = black;
  378.   opponent = white;
  379.   GenCnt = NodeCnt = et0 = epsquare =  XCmore = 0;
  380.   xwndw = BXwindow;
  381.   if (!MaxSearchDepth)
  382.     MaxSearchDepth = MAXDEPTH - 1;
  383.   GameCnt = 0;
  384.   Game50 = 1;
  385.   hint = 0x0C14;
  386.   selected=0;
  387.   ZeroRPT ();
  388.   Developed[white] = Developed[black] = false;
  389.   castld[white] = castld[black] = false;
  390.   PawnThreat[0] = CptrFlag[0] = false;
  391.   Pscore[0] = Tscore[0] = 12000;
  392.   for (l = 0; l < TREE; l++)
  393.     Tree[l].f = Tree[l].t = 0;
  394.   if (!InitFlag)
  395.    InitHashCode((unsigned int)1);
  396.   for (l = 0; l < 64; l++)
  397.     {
  398.       board[l] = Stboard[l];
  399.       color[l] = Stcolor[l];
  400.       Mvboard[l] = 0;
  401.     }
  402.   InitializeStats ();
  403. #ifdef HAVE_GETTIMEOFDAY
  404.   gettimeofday(&tv, NULL);
  405.   time0 = tv.tv_sec*100+tv.tv_usec/10000;
  406. #else
  407.   time0 = GetTickCount();
  408. #endif
  409.   ElapsedTime (1);
  410.   flag.regularstart = true;
  411.   Book = flag.usebook ? BOOKFAIL : 0;
  412.   TimeControl.clock[white] = TimeControl.clock[black] = 0;
  413.   SetTimeControl();
  414.   player^=1;
  415.   UpdateClocks();
  416.   player^=1;
  417.   UpdateClocks();
  418.  
  419.   if (!InitFlag)
  420.     {
  421.       GetOpenings ();
  422. #ifdef CACHE
  423.    etab[0] = (struct etable *)malloc(ETABLE*sizeof(struct etable));
  424.    etab[1] = (struct etable *)malloc(ETABLE*sizeof(struct etable));
  425.    if(etab[0] == NULL || etab[1] == NULL){ ShowMessage(CP[70]);Exit(1);}
  426. #endif
  427. #if ttblsz
  428.       Initialize_ttable();
  429. #endif
  430.       InitFlag = true;
  431.     }
  432. #if ttblsz
  433.    ZeroTTable(0);
  434. #endif /* ttblsz */
  435. #ifdef CACHE
  436.    memset ((CHAR *) etab[0], 0, ETABLE*sizeof(struct etable));
  437.    memset ((CHAR *) etab[1], 0, ETABLE*sizeof(struct etable));
  438. #endif
  439. #ifdef NODITHER
  440.   PCRASH = PCRASHS;
  441.   PCENTER = PCENTERS;
  442. #else
  443.   PCRASH = PCRASHS + (dither?(rand() % PCRASHV):0);
  444.   PCENTER = PCENTERS + (dither?(rand() % PCENTERV):0);
  445. #endif
  446.   ShowPlayers();
  447.   SetWindowText(hComputerMove,"");
  448.   return;
  449. }
  450.  
  451. void
  452. InitConst (CHAR *lang)
  453. {
  454.   FILE *constfile;
  455.   CHAR s[512];
  456.   CHAR sl[5];
  457.   int len, entry;
  458.   CHAR *p, *q;
  459. flag.illegal=flag.mate=flag.quit=flag.bothsides=flag.onemove=flag.force=false;
  460. flag.autolist=flag.back=flag.musttimeout=false;
  461. flag.searching=flag.editing=flag.replay=false;
  462.  
  463.   constfile = fopen (LANGFILE, "r");
  464.   if (!constfile)
  465.     {
  466.    constfile = fopen("\\gnuchess\\bin\\gnuchess.lan", "r");
  467.     }
  468.   if (!constfile)
  469.     {
  470.       ShowMessage("NO LANGFILE (file gnuchess.lan not found)");
  471.       exit (1);
  472.     }
  473.   while (fgets (s, sizeof (s), constfile))
  474.     {
  475.       if (s[0] == '!') continue;
  476.       len = strlen (s);
  477.       for (q = &s[len]; q > &s[8]; q--) if (*q == '}') break;
  478.       if (q == &s[8])
  479.    {
  480.      ShowMessage ("Error in gnuchess.lan");
  481.      exit (1);
  482.    }
  483.       *q = '\0';
  484.       if (s[3] != ':' || s[7] != ':' || s[8] != '{')
  485.    {
  486.      sprintf (msg,"Langfile format error %s", s);
  487.      ShowMessage(msg);
  488.      exit (1);
  489.    }
  490.       s[3] = s[7] = '\0';
  491.       if (lang == NULL)
  492.    {
  493.      lang = sl;
  494.      strcpy (sl, &s[4]);
  495.    }
  496.       if (strcmp (&s[4], lang))
  497.    continue;
  498.       entry = atoi (s);
  499.       if (entry < 0 || entry >= CPSIZE)
  500.    {
  501.      ShowMessage ("Langfile number error");
  502.      exit (1);
  503.    }
  504.       for (q = p = &s[9]; *p; p++)
  505.    {
  506.      if (*p != '\\')
  507.        {
  508.          *q++ = *p;
  509.        }
  510.      else if (*(p + 1) == 'n')
  511.        {
  512.          *q++ = '\n';
  513.          p++;
  514.        }
  515.    }
  516.       *q = '\0';
  517.       if (entry < 0 || entry > 255)
  518.    {
  519.      sprintf (msg,"Langfile error %d", entry);
  520.      ShowMessage (msg);
  521.      exit (1);
  522.    }
  523.       CP[entry] = (CHAR *) malloc ((unsigned) strlen (&s[9]) + 1);
  524.       if (CP[entry] == NULL)
  525.    {
  526.      ShowMessage ("Insufficient memory");
  527.      exit (1);
  528.    }
  529.       strcpy (CP[entry], &s[9]);
  530.  
  531.     }
  532.   fclose (constfile);
  533. }
  534.  
  535. void GetMetrics(void)
  536. {
  537.    HDC hDC;
  538.    HANDLE hOld,hSysFont;
  539.    TEXTMETRIC tm;
  540.    SIZE size;
  541.    RECT rc;
  542.    GetWindowRect(GetDesktopWindow(),&rc);
  543.    hDC=GetDC(hWnd);
  544.    hFont=CreateFont ( (rc.right-rc.left)/50, 0, 0, 0, FW_NORMAL, 0, 0, 0,
  545.                 ANSI_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS,
  546.                 DEFAULT_QUALITY, FIXED_PITCH | FF_SWISS, "Helv" );
  547.    hSysFont=GetStockObject(SYSTEM_FONT);
  548.    hOld=SelectObject(hDC,hFont);
  549.    GetTextMetrics(hDC,&tm);
  550.    LineSpace=tm.tmHeight;
  551.    CharWidth=tm.tmAveCharWidth;
  552.    SelectObject(hDC,hSysFont);
  553.    GetTextMetrics(hDC,&tm);
  554.    SLineSpace=tm.tmHeight;
  555.    GetTextExtentPoint(hDC,CP[74],17,&size);
  556.    CompColorExt=size.cx+25;
  557.    GetTextExtentPoint(hDC,"It is White's move",18,&size);
  558.    WhoseTurnExt=size.cx+25;
  559.    GetTextExtentPoint(hDC,"My move is a7a8q",16,&size);
  560.    CompMoveExt=size.cx+4;
  561.    SelectObject(hDC,hOld);
  562.    ReleaseDC(hWnd,hDC);
  563. }
  564.  
  565.  
  566. void InitScreen(void)
  567. {
  568.   SHORT x,y,marginF,marginB,lengthF,lengthB;
  569.  
  570.   if (squarebd)
  571.   switch (boardsize)
  572.    {
  573.    case SMALL:
  574.      sqwidthF=sqwidthB=sqdepth=bmsize=40;
  575.      break;
  576.    case MEDIUM:
  577.      sqwidthF=sqwidthB=sqdepth=bmsize=60;
  578.      break;
  579.    case LARGE:
  580.      sqwidthF=sqwidthB=sqdepth=bmsize=80;
  581.    }
  582.   else
  583.   switch (boardsize)
  584.    {
  585.    case SMALL:
  586.      sqwidthF=60;
  587.      sqwidthB=42;
  588.      sqdepth=40;
  589.      bmsize=40;
  590.      break;
  591.    case MEDIUM:
  592.      sqwidthF=90;
  593.      sqwidthB=63;
  594.      sqdepth=60;
  595.      bmsize=60;
  596.      break;
  597.    case LARGE:
  598.      sqwidthF=120;
  599.      sqwidthB=84;
  600.      sqdepth=80;
  601.      bmsize=80;
  602.    }
  603.   deltaX=(sqwidthF-sqwidthB)*8;
  604.   for (y=0;y<8;y++)
  605.    {
  606.      marginF=deltaX*y/16;
  607.      marginB=deltaX*(y+1)/16;
  608.      lengthF=sqwidthF*8-(marginF<<1);
  609.      lengthB=sqwidthF*8-(marginB<<1);
  610.      marginF+=LEFTMARGIN;
  611.      marginB+=LEFTMARGIN;
  612.      for (x=0;x<8;x++)
  613.      {
  614.       squares[x][y][0].x=marginF+lengthF*x/8;
  615.       squares[x][y][0].y=(8-y)*sqdepth+BACKMARGIN;
  616.       squares[x][y][1].x=marginF+lengthF*(x+1)/8;
  617.       squares[x][y][1].y=(8-y)*sqdepth+BACKMARGIN;
  618.       squares[x][y][2].x=marginB+lengthB*(x+1)/8;
  619.       squares[x][y][2].y=(7-y)*sqdepth+BACKMARGIN;
  620.       squares[x][y][3].x=marginB+lengthB*x/8;
  621.       squares[x][y][3].y=(7-y)*sqdepth+BACKMARGIN;
  622.       pieceloc[x+(y<<3)].x=lengthF/16-bmsize/2+squares[x][y][0].x;
  623.       pieceloc[x+(y<<3)].y=squares[x][y][2].y;
  624.      }
  625.    }
  626.   boardpg[0]=squares[0][0][0];
  627.   boardpg[1]=squares[7][0][1];
  628.   boardpg[2]=squares[7][7][2];
  629.   boardpg[3]=squares[0][7][3];
  630. }
  631.  
  632. void CreateStatics(void)
  633.  {
  634.   SHORT CompMoveXpos,YPos;
  635.   YPos=BACKMARGIN+sqdepth*8+LineSpace+BRD_EDGE;
  636.   hComputerColor = CreateWindow (lpStatic, NULL,
  637.                    WS_CHILD | SS_LEFT | WS_VISIBLE,
  638.                    LEFTMARGIN, YPos, CompColorExt, SLineSpace,
  639.                    hWnd, (HMENU)0, hInst, NULL);
  640.  
  641.   hWhoseTurn = CreateWindow (lpStatic, NULL,
  642.                    WS_CHILD | SS_LEFT | WS_VISIBLE,
  643.                    LEFTMARGIN+CompColorExt, YPos, WhoseTurnExt, SLineSpace,
  644.                    hWnd, (HMENU)1, hInst, NULL);
  645.  
  646.   hInCheck  = CreateWindow (lpStatic, NULL,
  647.                    WS_CHILD | SS_LEFT | WS_VISIBLE,
  648.                    LEFTMARGIN+CompColorExt+WhoseTurnExt,
  649.                    YPos, 120, SLineSpace,
  650.                    hWnd, (HMENU)2, hInst, NULL);
  651.  
  652.   hComputerMove = CreateWindow (lpStatic, NULL,
  653.                    WS_CHILD | SS_CENTER | WS_VISIBLE,
  654.                    CompMoveXpos=LEFTMARGIN+sqwidthB*8+deltaX/2+(20>>squarebd),
  655.                    65,CompMoveExt, SLineSpace, hWnd, (HMENU)3, hInst, NULL);
  656.  
  657.   hClockBlack  =  CreateWindow ( lpStatic, NULL,
  658.                    WS_CHILD | SS_CENTER | WS_VISIBLE,
  659.                    CompMoveXpos+(CompMoveExt-60)/2, 30,
  660.                    60, SLineSpace, hWnd, (HMENU)4, hInst, NULL);
  661.  
  662.   hClockWhite  =  CreateWindow ( lpStatic, NULL,
  663.                    WS_CHILD | SS_CENTER | WS_VISIBLE,
  664.                    CompMoveXpos+(CompMoveExt-60)/2, 120,
  665.                    60, SLineSpace, hWnd, (HMENU)5, hInst, NULL);
  666.  
  667.   hBlack       = CreateWindow ( lpStatic, CP[41],
  668.                    WS_CHILD | SS_CENTER | WS_VISIBLE,
  669.                    CompMoveXpos+(CompMoveExt-60)/2, 10,
  670.                    60, SLineSpace, hWnd, (HMENU)6, hInst, NULL);
  671.  
  672.   hWhite       = CreateWindow ( lpStatic, CP[40],
  673.                    WS_CHILD | SS_CENTER | WS_VISIBLE,
  674.                    CompMoveXpos+(CompMoveExt-60)/2, 100,
  675.                    60, SLineSpace, hWnd, (HMENU)7, hInst, NULL);
  676.   hDepth       = CreateWindow ( lpStatic, NULL,
  677.                    WS_CHILD | SS_CENTER | WS_VISIBLE,
  678.                    CompMoveXpos+(CompMoveExt-80)/2, 150,
  679.                    80, SLineSpace, hWnd, (HMENU)1010, hInst, NULL);
  680. }
  681.  
  682. void MoveStatics(void)
  683. {
  684.   SHORT CompMoveXpos;
  685.  
  686.   MoveWindow(hComputerColor,LEFTMARGIN, BACKMARGIN+sqdepth*8+20,
  687.      CompColorExt, SLineSpace, false);
  688.   MoveWindow(hWhoseTurn,LEFTMARGIN+CompColorExt, BACKMARGIN+sqdepth*8+20,
  689.      WhoseTurnExt, SLineSpace, false);
  690.   MoveWindow(hInCheck,LEFTMARGIN+CompColorExt+WhoseTurnExt,
  691.      BACKMARGIN+sqdepth*8+20,120, SLineSpace, false);
  692.   MoveWindow(hComputerMove,CompMoveXpos=LEFTMARGIN+sqwidthB*8+deltaX/2+
  693.     (20>>squarebd), 65, CompMoveExt, SLineSpace, false);
  694.   MoveWindow(hClockBlack,CompMoveXpos+(CompMoveExt-60)/2, 30,
  695.      60, SLineSpace, false);
  696.   MoveWindow(hClockWhite,CompMoveXpos+(CompMoveExt-60)/2, 120,
  697.      60, SLineSpace, false);
  698.   MoveWindow(hBlack,CompMoveXpos+(CompMoveExt-60)/2, 10,
  699.      60, SLineSpace, false);
  700.   MoveWindow(hWhite,CompMoveXpos+(CompMoveExt-60)/2, 100,
  701.      60, SLineSpace, false);
  702.   MoveWindow(hDepth,CompMoveXpos+(CompMoveExt-80)/2, 150,
  703.      80, SLineSpace, false);
  704. }
  705.  
  706. BOOL LoadSettings(void)
  707. {
  708.  SHORT i;
  709.  
  710.  boardsize=GetPrivateProfileInt(BrdSection,szboardsize,SMALL,IniFile);
  711.  squarebd=GetPrivateProfileInt(BrdSection,szsquarebd,0,IniFile);
  712.  WinPosX=GetPrivateProfileInt(BrdSection,szwinposX,0,IniFile);
  713.  WinPosY=GetPrivateProfileInt(BrdSection,szwinposY,0,IniFile);
  714.  WinSizeX=GetPrivateProfileInt(BrdSection,szwinsizeX,0,IniFile);
  715.  WinSizeY=GetPrivateProfileInt(BrdSection,szwinsizeY,0,IniFile);
  716.  GetPrivateProfileString(BrdSection,szbkgrnd,sznull,msg,sizeof(msg),IniFile);
  717.  clrBackGround = msg[0] ? strtoul(msg,0,16) : BROWN;
  718.  GetPrivateProfileString(BrdSection,szblacksq,sznull,msg,sizeof(msg),IniFile);
  719.  clrBlackSquare = msg[0] ? strtoul(msg,0,16) : DARKGREEN;
  720.  GetPrivateProfileString(BrdSection,szwhitesq,sznull,msg,sizeof(msg),IniFile);
  721.  clrWhiteSquare = msg[0] ? strtoul(msg,0,16) : PALEGRAY;
  722.  GetPrivateProfileString(BrdSection,szblackpc,sznull,msg,sizeof(msg),IniFile);
  723.  clrBlackPiece = msg[0] ? strtoul(msg,0,16) : DARKRED;
  724.  GetPrivateProfileString(BrdSection,szwhitepc,sznull,msg,sizeof(msg),IniFile);
  725.  clrWhitePiece = msg[0] ? strtoul(msg,0,16) : CWHITE;
  726.  GetPrivateProfileString(BrdSection,sztext,sznull,msg,sizeof(msg),IniFile);
  727.  clrText = msg[0] ? strtoul(msg,0,16) : CBLACK;
  728.  GetPrivateProfileString(BrdSection,szedge,sznull,msg,sizeof(msg),IniFile);
  729.  clrEdge = msg[0] ? strtoul(msg,0,16) : CBLACK;
  730.  for (i=0;i<16;i++)
  731.   {
  732.    szcustcols[2]=(char)i+'0';
  733.    GetPrivateProfileString(BrdSection,szcustcols,sznull,msg,sizeof(msg),IniFile);
  734.    if (msg[0]) CustCols[i]=strtoul(msg,0,16);
  735.    else CustCols[i]=CCdefs[i];
  736.   }
  737.  flag.beep=GetPrivateProfileInt(OptSection,szbeep,1,IniFile);
  738.  flag.coords=GetPrivateProfileInt(OptSection,szcoords,1,IniFile);
  739.  flag.post=GetPrivateProfileInt(OptSection,szstats,0,IniFile);
  740.  flag.usebook=GetPrivateProfileInt(OptSection,szbook,1,IniFile);
  741.  flag.hash=GetPrivateProfileInt(OptSection,szhash,1,IniFile);
  742.  HashDepth=GetPrivateProfileInt(OptSection,szhdepth,HASHDEPTH,IniFile);
  743.  HashMoveLimit=GetPrivateProfileInt(OptSection,szmvlim,HASHMOVELIMIT,IniFile);
  744.  WAwindow=GetPrivateProfileInt(OptSection,szWA,WAWNDW,IniFile);
  745.  WBwindow=GetPrivateProfileInt(OptSection,szWB,WBWNDW,IniFile);
  746.  WXwindow=GetPrivateProfileInt(OptSection,szWX,WXWNDW,IniFile);
  747.  BAwindow=GetPrivateProfileInt(OptSection,szBA,BAWNDW,IniFile);
  748.  BBwindow=GetPrivateProfileInt(OptSection,szBB,BBWNDW,IniFile);
  749.  BXwindow=GetPrivateProfileInt(OptSection,szBX,BXWNDW,IniFile);
  750.  contempt=GetPrivateProfileInt(OptSection,szcontempt,0,IniFile);
  751.  flag.material=GetPrivateProfileInt(OptSection,szmaterial,1,IniFile);
  752.  flag.rcptr=GetPrivateProfileInt(OptSection,szrcptr,1,IniFile);
  753.  flag.threat=GetPrivateProfileInt(OptSection,szthreat,1,IniFile);
  754.  flag.pvs=GetPrivateProfileInt(OptSection,szpvs,1,IniFile);
  755.  flag.neweval=GetPrivateProfileInt(OptSection,szne,1,IniFile);
  756.  flag.gamein=GetPrivateProfileInt(OptSection,szgamein,0,IniFile);
  757.  XCmoves[0]=GetPrivateProfileInt(skillsectn,szXCmv0,0,IniFile);
  758.  XCminutes[0]=GetPrivateProfileInt(skillsectn,szXCmin0,0,IniFile);
  759.  XCmoves[1]=GetPrivateProfileInt(skillsectn,szXCmv1,0,IniFile);
  760.  XCminutes[1]=GetPrivateProfileInt(skillsectn,szXCmin1,0,IniFile);
  761.  XCmoves[2]=GetPrivateProfileInt(skillsectn,szXCmv2,0,IniFile);
  762.  XCminutes[2]=GetPrivateProfileInt(skillsectn,szXCmin2,0,IniFile);
  763.  XC=0;
  764.  for (i=0;i<3;i++)
  765.   {
  766.    if (XCmoves[i] && XCminutes[i])XC++;
  767.    else break;
  768.   }
  769.  GetPrivateProfileString(skillsectn,szMRT,"3000",msg,sizeof(msg),IniFile);
  770.  MaxResponseTime=strtol(msg,0,10);
  771.  dither=GetPrivateProfileInt(skillsectn,szdither,0,IniFile);
  772.  flag.easy=GetPrivateProfileInt(skillsectn,szeasy,1,IniFile);
  773.  MaxSearchDepth=GetPrivateProfileInt(skillsectn,szmaxdepth,MAXDEPTH,IniFile);
  774.  return GetPrivateProfileInt(BrdSection,szmaximized,0,IniFile);
  775. }
  776.  
  777. void SaveSettings(void)
  778. {
  779.  RECT rect;
  780.  SHORT i;
  781.  
  782.  sprintf(msg,shortfs,boardsize);
  783.  WritePrivateProfileString(BrdSection,szboardsize,msg,IniFile);
  784.  sprintf(msg,shortfs,squarebd);
  785.  WritePrivateProfileString(BrdSection,szsquarebd,msg,IniFile);
  786.  if (wr.right)
  787.   {
  788.    sprintf(msg,shortfs,wr.left);
  789.    WritePrivateProfileString(BrdSection,szwinposX,msg,IniFile);
  790.    sprintf(msg,shortfs,wr.top);
  791.    WritePrivateProfileString(BrdSection,szwinposY,msg,IniFile);
  792.    sprintf(msg,shortfs,wr.right-wr.left);
  793.    WritePrivateProfileString(BrdSection,szwinsizeX,msg,IniFile);
  794.    sprintf(msg,shortfs,wr.bottom-wr.top);
  795.    WritePrivateProfileString(BrdSection,szwinsizeY,msg,IniFile);
  796.   }
  797.  sprintf(msg,shortfs,maximized);
  798.  WritePrivateProfileString(BrdSection,szmaximized,msg,IniFile);
  799.  sprintf(msg,hexuint,clrBackGround);
  800.  WritePrivateProfileString(BrdSection,szbkgrnd,msg,IniFile);
  801.  sprintf(msg,hexuint,clrBlackSquare);
  802.  WritePrivateProfileString(BrdSection,szblacksq,msg,IniFile);
  803.  sprintf(msg,hexuint,clrWhiteSquare);
  804.  WritePrivateProfileString(BrdSection,szwhitesq,msg,IniFile);
  805.  sprintf(msg,hexuint,clrBlackPiece);
  806.  WritePrivateProfileString(BrdSection,szblackpc,msg,IniFile);
  807.  sprintf(msg,hexuint,clrWhitePiece);
  808.  WritePrivateProfileString(BrdSection,szwhitepc,msg,IniFile);
  809.  sprintf(msg,hexuint,clrText);
  810.  WritePrivateProfileString(BrdSection,sztext,msg,IniFile);
  811.  sprintf(msg,hexuint,clrEdge);
  812.  WritePrivateProfileString(BrdSection,szedge,msg,IniFile);
  813.  for (i=0;i<16;i++)
  814.   {
  815.    sprintf(msg,hexuint,CustCols[i]);
  816.    sprintf(szcustcols+2,shortfs,i);
  817.    WritePrivateProfileString(BrdSection,szcustcols,msg,IniFile);
  818.   }
  819.  sprintf(msg,shortfs,flag.beep);
  820.  WritePrivateProfileString(OptSection,szbeep,msg,IniFile);
  821.  sprintf(msg,shortfs,flag.coords);
  822.  WritePrivateProfileString(OptSection,szcoords,msg,IniFile);
  823.  sprintf(msg,shortfs,flag.post);
  824.  WritePrivateProfileString(OptSection,szstats,msg,IniFile);
  825.  sprintf(msg,shortfs,flag.usebook);
  826.  WritePrivateProfileString(OptSection,szbook,msg,IniFile);
  827.  sprintf(msg,shortfs,flag.hash);
  828.  WritePrivateProfileString(OptSection,szhash,msg,IniFile);
  829.  sprintf(msg,shortfs,HashDepth);
  830.  WritePrivateProfileString(OptSection,szhdepth,msg,IniFile);
  831.  sprintf(msg,shortfs,HashMoveLimit);
  832.  WritePrivateProfileString(OptSection,szmvlim,msg,IniFile);
  833.  sprintf(msg,shortfs,WAwindow);
  834.  WritePrivateProfileString(OptSection,szWA,msg,IniFile);
  835.  sprintf(msg,shortfs,WBwindow);
  836.  WritePrivateProfileString(OptSection,szWB,msg,IniFile);
  837.  sprintf(msg,shortfs,WXwindow);
  838.  WritePrivateProfileString(OptSection,szWX,msg,IniFile);
  839.  sprintf(msg,shortfs,BAwindow);
  840.  WritePrivateProfileString(OptSection,szBA,msg,IniFile);
  841.  sprintf(msg,shortfs,BBwindow);
  842.  WritePrivateProfileString(OptSection,szBB,msg,IniFile);
  843.  sprintf(msg,shortfs,BXwindow);
  844.  WritePrivateProfileString(OptSection,szBX,msg,IniFile);
  845.  sprintf(msg,shortfs,contempt);
  846.  WritePrivateProfileString(OptSection,szcontempt,msg,IniFile);
  847.  sprintf(msg,shortfs,flag.material);
  848.  WritePrivateProfileString(OptSection,szmaterial,msg,IniFile);
  849.  sprintf(msg,shortfs,flag.rcptr);
  850.  WritePrivateProfileString(OptSection,szrcptr,msg,IniFile);
  851.  sprintf(msg,shortfs,flag.threat);
  852.  WritePrivateProfileString(OptSection,szthreat,msg,IniFile);
  853.  sprintf(msg,shortfs,flag.pvs);
  854.  WritePrivateProfileString(OptSection,szpvs,msg,IniFile);
  855.  sprintf(msg,shortfs,flag.neweval);
  856.  WritePrivateProfileString(OptSection,szne,msg,IniFile);
  857.  sprintf(msg,shortfs,flag.gamein);
  858.  WritePrivateProfileString(OptSection,szgamein,msg,IniFile);
  859.  sprintf(msg,shortfs,XCmoves[0]);
  860.  WritePrivateProfileString(skillsectn,szXCmv0,msg,IniFile);
  861.  sprintf(msg,shortfs,XCminutes[0]);
  862.  WritePrivateProfileString(skillsectn,szXCmin0,msg,IniFile);
  863.  sprintf(msg,shortfs,XCmoves[1]);
  864.  WritePrivateProfileString(skillsectn,szXCmv1,msg,IniFile);
  865.  sprintf(msg,shortfs,XCminutes[1]);
  866.  WritePrivateProfileString(skillsectn,szXCmin1,msg,IniFile);
  867.  sprintf(msg,shortfs,XCmoves[2]);
  868.  WritePrivateProfileString(skillsectn,szXCmv2,msg,IniFile);
  869.  sprintf(msg,shortfs,XCminutes[2]);
  870.  WritePrivateProfileString(skillsectn,szXCmin2,msg,IniFile);
  871.  sprintf(msg,"%ld",MaxResponseTime);
  872.  WritePrivateProfileString(skillsectn,szMRT,msg,IniFile);
  873.  sprintf(msg,shortfs,dither);
  874.  WritePrivateProfileString(skillsectn,szdither,msg,IniFile);
  875.  sprintf(msg,shortfs,flag.easy);
  876.  WritePrivateProfileString(skillsectn,szeasy,msg,IniFile);
  877.  sprintf(msg,shortfs,MaxSearchDepth);
  878.  WritePrivateProfileString(skillsectn,szmaxdepth,msg,IniFile);
  879. }
  880.