home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Source Code 1993 July / THE_SOURCE_CODE_CD_ROM.iso / gnu / gnushogi-1.1 / src / init.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-04-19  |  16.7 KB  |  655 lines

  1. /*
  2.  * init.c - C source for GNU SHOGI
  3.  *
  4.  * Copyright (c) 1993 Matthias Mutz
  5.  *
  6.  * GNU SHOGI is based on GNU CHESS
  7.  *
  8.  * Copyright (c) 1988,1989,1990 John Stanback
  9.  * Copyright (c) 1992 Free Software Foundation
  10.  *
  11.  * This file is part of GNU SHOGI.
  12.  *
  13.  * GNU Shogi is free software; you can redistribute it and/or modify
  14.  * it under the terms of the GNU General Public License as published by
  15.  * the Free Software Foundation; either version 1, or (at your option)
  16.  * any later version.
  17.  *
  18.  * GNU Shogi is distributed in the hope that it will be useful,
  19.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  20.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  21.  * GNU General Public License for more details.
  22.  *
  23.  * You should have received a copy of the GNU General Public License
  24.  * along with GNU Shogi; see the file COPYING.  If not, write to
  25.  * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
  26.  */
  27.  
  28. #include "gnushogi.h"
  29.  
  30. #if defined HASGETTIMEOFDAY && !defined THINK_C
  31. #include <sys/time.h>
  32. #endif
  33.  
  34. extern unsigned int TTadd;
  35.  
  36. /* .... MOVE GENERATION VARIABLES AND INITIALIZATIONS .... */
  37.  
  38.  
  39. #if !defined K32SEGMENTS
  40. #include "init_data1.c"
  41. #include "init_data2.c"
  42. #include "init_data3.c"
  43. #include "init_data4.c"
  44. #include "init_data1b.c"
  45. #include "init_data2b.c"
  46. #include "init_data3b.c"
  47. #include "init_data4b.c"
  48. #endif
  49.  
  50.  
  51. #ifdef USE_PATTERN
  52. #include "pattern.h"
  53. #endif
  54.  
  55.  
  56. #ifdef THINK_C                
  57. #define abs(a) (((a)<0)?-(a):(a))
  58. #endif
  59. #define max(a,b) (((a)<(b))?(b):(a))
  60. #define odd(a) ((a) & 1)
  61.  
  62.  
  63.  
  64. const small_short piece_of_ptype[NO_PTYPE_PIECES] =
  65. { pawn, lance, knight, silver, gold, bishop, rook, pbishop, prook, king,
  66.     pawn, lance, knight, silver, gold };
  67.  
  68.  
  69. const small_short side_of_ptype[NO_PTYPE_PIECES] =
  70. { black, black, black, black, black, black, black, black, black, black,
  71.     white, white, white, white, white };
  72.  
  73.  
  74.  
  75. short
  76. ptype_distance (short ptyp, short f, short t)
  77.  
  78. /*
  79.  * Determine the minimum number of moves for a piece from
  80.  * square "f" to square "t". If the piece cannot reach "t",
  81.  * the count is set to CANNOT_REACH.
  82.  */
  83.  
  84. #define csquare(sq) ((side == black) ? sq : (NO_SQUARES-1-sq))
  85. #define crow(sq) row(csquare(sq))
  86. #define ccol(sq) column(csquare(sq))
  87.  
  88. {
  89.   short side, piece;
  90.   short colf, colt, rowf, rowt, dcol, drow;
  91.  
  92.   if ( f == t )
  93.     return (0);
  94.  
  95.   piece = piece_of_ptype[ptyp];
  96.   side  = side_of_ptype[ptyp];
  97.  
  98.   dcol = (colt = ccol(t)) - (colf = ccol(f));
  99.   drow = (rowt = crow(t)) - (rowf = crow(f));
  100.  
  101.   switch ( piece ) {
  102.  
  103.     case pawn:
  104.     if ( (dcol != 0) || (drow != 1) )
  105.       return (CANNOT_REACH);
  106.     else
  107.       return (1);
  108.  
  109.     case lance:
  110.     if ( (dcol != 0) || (drow < 1) )
  111.       return (CANNOT_REACH);
  112.     else
  113.       return (drow);
  114.  
  115.     case knight:
  116.     if ( odd(drow) || (odd(drow / 2) != odd(dcol)) )
  117.       return (CANNOT_REACH);
  118.     else if ( (drow == 0) || ((drow / 2) < abs(dcol)) )
  119.       return (CANNOT_REACH);
  120.     else
  121.       return (drow / 2);
  122.  
  123.     case silver:
  124.     if ( odd(drow) == odd(dcol) )
  125.       return max(abs(drow),abs(dcol));
  126.     else if ( drow > 0 )
  127.       if ( abs(dcol) <= drow )
  128.         return (drow);
  129.       else
  130.         return (max(abs(drow),abs(dcol))+1);
  131.     else if ( dcol == 0 )
  132.       return (2-drow);
  133.     else
  134.       return (max(abs(drow),abs(dcol))+1);
  135.  
  136.     case gold:
  137.     case ppawn:
  138.     case pknight:
  139.     case plance:
  140.     case psilver:
  141.     if ( abs(dcol) == 0 )
  142.       return (abs(drow));
  143.     else if ( drow >= 0 )
  144.       return max(drow,abs(dcol));
  145.     else
  146.       return (abs(dcol)-drow);
  147.  
  148.     case bishop:
  149.     if ( odd(dcol) != odd(drow) )
  150.       return (CANNOT_REACH);
  151.     else
  152.       return ((abs(dcol) == abs(drow)) ? 1 : 2);
  153.  
  154.     case pbishop:
  155.     if ( odd(dcol) != odd(drow) )
  156.       if ( (abs(dcol) <= 1) && (abs(drow) <= 1) )
  157.         return (1);
  158.       else if ( abs(abs(dcol) - abs(drow)) == 1 )
  159.         return (2);
  160.       else
  161.         return (3);
  162.     else
  163.       return ((abs(dcol) == abs(drow)) ? 1 : 2);
  164.  
  165.     case rook:
  166.     if ( (dcol == 0) || (drow == 0) )
  167.       return (1);
  168.     else
  169.       return (2);
  170.  
  171.     case prook:
  172.     if ( (dcol == 0) || (drow == 0) )
  173.       return (1);
  174.     else if ( (abs(dcol) == 1) && (abs(drow) == 1) )
  175.       return (1);
  176.     else
  177.       return (2);
  178.  
  179.     case king:
  180.     return max(abs(drow),abs(dcol));
  181.  
  182.     default:
  183.     /* should never occur */
  184.     return (CANNOT_REACH);
  185.  
  186.   }
  187.  
  188. }
  189.  
  190.  
  191. #ifndef SAVE_PTYPE_DISTDATA
  192. distdata_array *ptype_distdata[NO_PTYPE_PIECES];
  193. #endif
  194.  
  195.  
  196. void
  197. Initialize_dist (void)
  198. {
  199.   register short a, b, d, di, ptyp;
  200. #ifndef SAVE_DISTDATA
  201.   for (a = 0; a < NO_SQUARES; a++)
  202.     for (b = 0; b < NO_SQUARES; b++)
  203.       {
  204.     d = abs (column (a) - column (b));
  205.     di = abs (row (a) - row (b));
  206.     distdata[a][b] = (small_short)((d > di) ? d : di);
  207.       }
  208. #endif
  209. #ifndef SAVE_PTYPE_DISTDATA
  210.   for (ptyp = 0; ptyp < NO_PTYPE_PIECES; ptyp++)
  211.     {
  212.       if ( (ptype_distdata[ptyp] = (distdata_array *) malloc (sizeof(next_array))) == NULL )
  213.         {
  214.           ShowMessage("cannot allocate ptype_distdata space...");
  215.           exit(1);
  216.         }
  217.       for (a = 0; a < NO_SQUARES; a++)
  218.         for (b = 0; b < NO_SQUARES; b++)
  219.           (*ptype_distdata[ptyp])[a][b] = ptype_distance(ptyp,a,b);
  220.     }
  221. #endif
  222. }
  223.  
  224.  
  225. /*
  226.  * nextpos[piece][from-square] , nextdir[piece][from-square] gives vector of
  227.  * positions reachable from from-square in ppos with piece such that the
  228.  * sequence    ppos = nextpos[piece][from-square]; pdir =
  229.  * nextdir[piece][from-square]; u = ppos[sq]; do { u = ppos[u]; if(color[u]
  230.  * != neutral) u = pdir[u]; } while (sq != u); will generate the sequence of
  231.  * all squares reachable from sq.
  232.  *
  233.  * If the path is blocked u = pdir[sq] will generate the continuation of the
  234.  * sequence in other directions.
  235.  */
  236.  
  237.  
  238. extern next_array pawn_nextdir, lance_nextdir, knight_nextdir;
  239. extern next_array silver_nextdir, gold_nextdir, bishop_nextdir;
  240. extern next_array rook_nextdir, pbishop_nextdir, prook_nextdir;
  241. extern next_array king_nextdir, wpawn_nextdir, wlance_nextdir;
  242. extern next_array wknight_nextdir, wsilver_nextdir, wgold_nextdir;
  243.  
  244. extern next_array pawn_nextpos, lance_nextpos, knight_nextpos;
  245. extern next_array silver_nextpos, gold_nextpos, bishop_nextpos;
  246. extern next_array rook_nextpos, pbishop_nextpos, prook_nextpos;
  247. extern next_array king_nextpos, wpawn_nextpos, wlance_nextpos;
  248. extern next_array wknight_nextpos, wsilver_nextpos, wgold_nextpos;
  249.  
  250.  
  251.  
  252. next_array *nextdir[NO_PTYPE_PIECES] = 
  253. { &pawn_nextdir, &lance_nextdir, &knight_nextdir, 
  254.   &silver_nextdir, &gold_nextdir, &bishop_nextdir, &rook_nextdir,
  255.   &pbishop_nextdir, &prook_nextdir,
  256.   &king_nextdir, &wpawn_nextdir, &wlance_nextdir, &wknight_nextdir,
  257.   &wsilver_nextdir, &wgold_nextdir };
  258.  
  259. next_array *nextpos[NO_PTYPE_PIECES] = 
  260. { &pawn_nextpos, &lance_nextpos, &knight_nextpos, 
  261.   &silver_nextpos, &gold_nextpos, &bishop_nextpos, &rook_nextpos,
  262.   &pbishop_nextpos, &prook_nextpos,
  263.   &king_nextpos, &wpawn_nextpos, &wlance_nextpos, &wknight_nextpos,
  264.   &wsilver_nextpos, &wgold_nextpos };
  265.  
  266. /*
  267.  * ptype is used to separate black and white pawns, like this; ptyp =
  268.  * ptype[side][piece] piece can be used directly in nextpos/nextdir when
  269.  * generating moves for pieces that are not white pawns.
  270.  */
  271.  
  272. const small_short ptype[2][NO_PIECES] =
  273. { ptype_no_piece, ptype_pawn, ptype_lance, ptype_knight, 
  274.     ptype_silver, ptype_gold, ptype_bishop, ptype_rook,
  275.     ptype_gold, ptype_gold, ptype_gold, ptype_gold, 
  276.     ptype_pbishop, ptype_prook, ptype_king,
  277.   ptype_no_piece, ptype_wpawn, ptype_wlance, ptype_wknight, 
  278.     ptype_wsilver, ptype_wgold, ptype_bishop, ptype_rook,
  279.     ptype_wgold, ptype_wgold, ptype_wgold, ptype_wgold, 
  280.     ptype_pbishop, ptype_prook, ptype_king};
  281.  
  282. const small_short promoted[NO_PIECES] =
  283. { no_piece, ppawn, plance, pknight, psilver, gold, pbishop, prook,
  284.     ppawn, plance, pknight, psilver, pbishop, prook, king };
  285.     
  286. const small_short unpromoted[NO_PIECES] =
  287. { no_piece, pawn, lance, knight, silver, gold, bishop, rook,
  288.     pawn, lance, knight, silver, bishop, rook, king };
  289.     
  290. const small_short is_promoted[NO_PIECES] =
  291. { false, false, false, false, false, false, false, false,
  292.     true, true, true, true, true, true, false };
  293.  
  294. /* data used to generate nextpos/nextdir */
  295. static const small_short direc[NO_PTYPE_PIECES][8] =
  296. {
  297.    11,  0,  0,  0,  0,  0,  0,  0 ,   /*  0 ptype_pawn */
  298.    11,  0,  0,  0,  0,  0,  0,  0 ,   /*  1 ptype_lance */
  299.    21, 23,  0,  0,  0,  0,  0,  0 ,   /*  2 ptype_knight */
  300.    10, 11, 12,-12,-10,  0,  0,  0 ,   /*  3 ptype_silver */
  301.    10, 11, 12, -1,  1,-11,  0,  0 ,   /*  4 ptype_gold */
  302.    10, 12,-12,-10,  0,  0,  0,  0 ,   /*  5 ptype_bishop */
  303.    11, -1,  1,-11,  0,  0,  0,  0 ,   /*  6 ptype_rook */
  304.    10, 11, 12, -1,  1,-12,-11,-10 ,   /*  7 ptype_pbishop */
  305.    10, 11, 12, -1,  1,-12,-11,-10 ,   /*  8 ptype_prook */
  306.    10, 11, 12, -1,  1,-12,-11,-10 ,   /*  9 ptype_king */
  307.   -11,  0,  0,  0,  0,  0,  0,  0 ,   /* 10 ptype_wpawn */
  308.   -11,  0,  0,  0,  0,  0,  0,  0 ,   /* 11 ptype_wlance */
  309.   -21,-23,  0,  0,  0,  0,  0,  0 ,   /* 12 ptype_wknight */
  310.   -10,-11,-12, 12, 10,  0,  0,  0 ,   /* 13 ptype_wsilver */
  311.   -10,-11,-12,  1, -1, 11,  0,  0 };  /* 14 ptype_wgold */
  312.  
  313.  
  314. small_short diagonal(short d) 
  315. { return(abs(d) == 10 || abs(d) == 12);
  316. }
  317.  
  318.    
  319. static const small_short max_steps[NO_PTYPE_PIECES] = 
  320. {1, 8, 1, 1, 1, 8, 8, 8, 8, 1, 1, 8, 1, 1, 1 };
  321.  
  322. static const small_short nunmap[(NO_COLS+2)*(NO_ROWS+4)] =
  323. {
  324.   -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
  325.   -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 
  326.   -1,  0,  1,  2,  3,  4,  5,  6,  7,  8, -1,
  327.   -1,  9, 10, 11, 12, 13, 14, 15, 16, 17, -1,
  328.   -1, 18, 19, 20, 21, 22, 23, 24, 25, 26, -1,
  329.   -1, 27, 28, 29, 30, 31, 32, 33, 34, 35, -1,
  330.   -1, 36, 37, 38, 39, 40, 41, 42, 43, 44, -1,
  331.   -1, 45, 46, 47, 48, 49, 50, 51, 52, 53, -1,
  332.   -1, 54, 55, 56, 57, 58, 59, 60, 61, 62, -1,
  333.   -1, 63, 64, 65, 66, 67, 68, 69, 70, 71, -1,
  334.   -1, 72, 73, 74, 75, 76, 77, 78, 79, 80, -1,
  335.   -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
  336.   -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1};
  337.  
  338.  
  339. int InitFlag = false;
  340.  
  341. void
  342. Initialize_moves (void)
  343.  
  344. /*
  345.  * This procedure pre-calculates all moves for every piece from every square.
  346.  * This data is stored in nextpos/nextdir and used later in the move
  347.  * generation routines.
  348.  */
  349.  
  350. {
  351.   short ptyp, po, p0, d, di, s, delta;
  352.   unsigned char *ppos, *pdir;       
  353.   short dest[8][9];
  354.   short sorted[9];              
  355.   short steps[8];
  356.   short fpo=23,tpo=120;
  357.  
  358.   for (ptyp = 0; ptyp < NO_PTYPE_PIECES; ptyp++)
  359.     for (po = 0; po < NO_SQUARES; po++)
  360.       for (p0 = 0; p0 < NO_SQUARES; p0++)
  361.     { 
  362.       (*nextpos[ptyp])[po][p0] = (unsigned char) po;
  363.       (*nextdir[ptyp])[po][p0] = (unsigned char) po;
  364.     }
  365.     
  366.   for (ptyp = 0; ptyp < NO_PTYPE_PIECES; ptyp++) 
  367.     for (po = fpo; po < tpo; po++)
  368.       if (nunmap[po] >= 0)
  369.     { 
  370.       ppos = (*nextpos[ptyp])[nunmap[po]];
  371.       pdir = (*nextdir[ptyp])[nunmap[po]];
  372.       /* dest is a function of direction and steps */
  373.       for (d = 0; d < 8; d++)
  374.         {
  375.           dest[d][0] = nunmap[po];
  376.           delta = direc[ptyp][d];
  377.           if (delta != 0)
  378.         {
  379.           p0 = po;
  380.           for (s = 0; s < max_steps[ptyp]; s++)
  381.             {
  382.               p0 = p0 + delta;
  383.  
  384.               /*
  385.                * break if (off board) or (promoted rooks wishes to 
  386.                        * move two steps diagonal) or (promoted
  387.                        * bishops wishes to move two steps non-diagonal) 
  388.                */                     
  389.               if ( (nunmap[p0] < 0) ||
  390.                            ((ptyp == ptype_prook) && (s > 0) && diagonal(delta)) ||
  391.                            ((ptyp == ptype_pbishop) && (s > 0) && !diagonal(delta)) )
  392.             break;
  393.               else
  394.             dest[d][s] = nunmap[p0];
  395.             }
  396.         }
  397.           else
  398.         s = 0;
  399.  
  400.           /*
  401.            * sort dest in number of steps order currently no sort
  402.            * is done due to compability with the move generation
  403.            * order in old gnu chess
  404.            */
  405.           steps[d] = s;
  406.           for (di = d; s > 0 && di > 0; di--)
  407.         if (steps[sorted[di - 1]] == 0)    /* should be: < s */
  408.           sorted[di] = sorted[di - 1];
  409.         else
  410.           break;
  411.           sorted[di] = d;
  412.         }
  413.  
  414.       /*
  415.        * update nextpos/nextdir
  416.        */
  417.       p0 = nunmap[po];
  418.       pdir[p0] = (unsigned char) dest[sorted[0]][0];
  419.       for (d = 0; d < 8; d++)
  420.           for (s = 0; s < steps[sorted[d]]; s++)
  421.           {
  422.             ppos[p0] = (unsigned char) dest[sorted[d]][s];
  423.             p0 = dest[sorted[d]][s];
  424.             if (d < 7)
  425.               pdir[p0] = (unsigned char) dest[sorted[d + 1]][0];
  426.  
  427.             /*
  428.              * else is already initialized
  429.              */
  430.           }
  431.     }
  432. }
  433.  
  434.  
  435. void
  436. NewGame (void)
  437.  
  438. /*
  439.  * Reset the board and other variables to start a new game.
  440.  */
  441.  
  442. {
  443.   short l, c, p;
  444. #ifdef HASGETTIMEOFDAY
  445.   struct timeval tv;
  446. #endif
  447.   compptr = oppptr = -1;
  448.   stage = stage2 = -1;        /* the game is not yet started */
  449.   flag.illegal = flag.mate = flag.post = flag.quit = flag.reverse = flag.bothsides = flag.onemove = flag.force = false;
  450.   flag.material = flag.coords = flag.hash = flag.easy = flag.beep = flag.rcptr = true;
  451.   flag.stars = flag.shade = flag.back = flag.musttimeout = false;
  452.   flag.gamein = false;
  453. #if defined(MSDOS) && !defined(SEVENBIT)
  454.   flag.rv = false;
  455. #else
  456.   flag.rv = true;
  457. #endif /* MSDOS && !SEVENBIT */
  458.   mycnt1 = mycnt2 = 0;
  459.   GenCnt = NodeCnt = et0 = dither =  XCmore = 0;
  460.   WAwindow = WAWNDW;
  461.   WBwindow = WBWNDW;
  462.   BAwindow = BAWNDW;
  463.   BBwindow = BBWNDW;
  464.   xwndw = BXWNDW;
  465.   if (!MaxSearchDepth)
  466.     MaxSearchDepth = MAXDEPTH - 1;
  467.   contempt = 0;
  468.   GameCnt = 0;
  469.   Game50 = 1;
  470.   CptrFlag[0] = false;
  471.   hint = OPENING_HINT;
  472.   ZeroRPT ();
  473.   GameType[0] = GameType[1] = UNKNOWN;
  474.   Pscore[0] = Tscore[0] = (SCORE_LIMIT+3000);
  475.   opponent = black;
  476.   computer = white;
  477.   for (l = 0; l < TREE; l++)
  478.     Tree[l].f = Tree[l].t = 0;
  479.   gsrand ((unsigned int) 1);
  480.   if (!InitFlag)
  481.     {
  482.       for (c = black; c <= white; c++)
  483.     for (p = pawn; p <= king; p++)
  484.       for (l = 0; l < (NO_SQUARES+(2*NO_PIECES)); l++)
  485.         {
  486.           hashcode[c][p][l].key = (((unsigned long) urand ()));
  487.           hashcode[c][p][l].key += (((unsigned long) urand ()) << 16);
  488.           hashcode[c][p][l].bd = (((unsigned long) urand ()));
  489.           hashcode[c][p][l].bd += (((unsigned long) urand ()) << 16);
  490. #ifdef LONG64
  491.           hashcode[c][p][l].key += (((unsigned long) urand ()) << 32);
  492.           hashcode[c][p][l].key += (((unsigned long) urand ()) << 48);
  493.           hashcode[c][p][l].bd += (((unsigned long) urand ()) << 32);
  494.           hashcode[c][p][l].bd += (((unsigned long) urand ()) << 48);
  495. #endif
  496.         }
  497.     }
  498.   for (l = 0; l < NO_SQUARES; l++)
  499.     {
  500.       board[l] = Stboard[l];
  501.       color[l] = Stcolor[l];
  502.       Mvboard[l] = 0;
  503.     }
  504.   ClearCaptured ();
  505.   ClrScreen ();
  506.   InitializeStats ();
  507. #ifdef HASGETTIMEOFDAY
  508.   gettimeofday(&tv, NULL);
  509.   time0 = tv.tv_sec*100+tv.tv_usec/10000;
  510. #else
  511.   time0 = time ((long *) 0);
  512. #endif
  513.   ElapsedTime (1);
  514.   flag.regularstart = true;
  515.   Book = BOOKFAIL;
  516.   if (!InitFlag)
  517.     {
  518.     char sx[256];
  519.     strcpy(sx,"level");
  520.       if (TCflag)
  521.     SetTimeControl ();
  522.       else if (MaxResponseTime == 0)
  523.     SelectLevel (sx);
  524.       UpdateDisplay (0, 0, 1, 0);
  525.       GetOpenings ();
  526. #ifdef USE_PATTERN
  527.       GetOpeningPatterns ();
  528.       /* ShowOpeningPatterns (); */
  529. #endif
  530. #if ttblsz
  531.       Initialize_ttable();
  532. #endif
  533.       InitFlag = true;
  534.     }
  535.   hashbd = hashkey = 0;
  536. #if ttblsz
  537.   ZeroTTable ();
  538.   TTadd = 0;
  539. #endif /* ttblsz */
  540. }
  541.  
  542. void
  543. InitConst (char *lang)
  544. {
  545.   FILE *constfile;
  546.   char s[256];
  547.   char sl[5];
  548.   int len, entry;
  549.   char *p, *q;
  550.   constfile = fopen (LANGFILE, "r");
  551.   if (!constfile)
  552.     {
  553.       printf ("NO LANGFILE\n");
  554.       exit (1);
  555.     }
  556.   while (fgets (s, sizeof (s), constfile))
  557.     {
  558.       if (s[0] == '!')
  559.     continue;
  560.       len = strlen (s);
  561.       for (q = &s[len]; q > &s[8]; q--)
  562.     if (*q == '}')
  563.       break;
  564.       if (q == &s[8])
  565.     {
  566.       printf ("{ error in cinstfile\n");
  567.       exit (1);
  568.     }
  569.       *q = '\0';
  570.       if (s[3] != ':' || s[7] != ':' || s[8] != '{')
  571.     {
  572.       printf ("Langfile format error %s\n", s);
  573.       exit (1);
  574.     }
  575.       s[3] = s[7] = '\0';
  576.       if (lang == NULL)
  577.     {
  578.       lang = sl;
  579.       strcpy (sl, &s[4]);
  580.     }
  581.       if (strcmp (&s[4], lang))
  582.     continue;
  583.       entry = atoi (s);
  584.       if (entry < 0 || entry >= CPSIZE)
  585.     {
  586.       printf ("Langfile number error\n");
  587.       exit (1);
  588.     }
  589.       for (q = p = &s[9]; *p; p++)
  590.     {
  591.       if (*p != '\\')
  592.         {
  593.           *q++ = *p;
  594.         }
  595.       else if (*(p + 1) == 'n')
  596.         {
  597.           *q++ = '\n';
  598.           p++;
  599.         }
  600.     }
  601.       *q = '\0';
  602.       if (entry < 0 || entry > 255)
  603.     {
  604.       printf ("Langfile error %d\n", entry);
  605.       exit (0);
  606.     }
  607.       CP[entry] = (char *) malloc ((unsigned) strlen (&s[9]) + 1);
  608.       if (CP[entry] == NULL)
  609.     {
  610.       perror ("malloc");
  611.       exit (0);
  612.     }
  613.       strcpy (CP[entry], &s[9]);
  614.  
  615.     }
  616.   fclose (constfile);
  617. }
  618.  
  619. #if ttblsz
  620. void
  621.  
  622. Initialize_ttable ()
  623. {
  624.   int doit = true;
  625.  
  626.   if (rehash < 0)
  627.     rehash = MAXrehash;
  628.  
  629.   while ( doit && ttblsize > 0 ) {
  630.     ttable[0] = (struct hashentry *)malloc((unsigned)(sizeof(struct hashentry))*(ttblsize+rehash));
  631.     ttable[1] = (struct hashentry *)malloc((unsigned)(sizeof(struct hashentry))*(ttblsize+rehash));
  632.     if (ttable[0] == NULL || ttable[1] == NULL) {
  633.       if (ttable[0] != NULL) free(ttable[0]);
  634.       if (ttable[1] != NULL) free(ttable[1]);
  635.       ttblsize = ttblsize >> 1;
  636.     } else doit = false;
  637.   }
  638.  
  639.   if (ttable[0] == NULL || ttable[1] == NULL) {
  640.     perror("memory alloc");
  641.     exit(1);
  642.   }
  643.  
  644. #if !defined BAREBONES && defined NONDSP
  645.   { char s[80];
  646.     sprintf(s,"transposition table is %d",ttblsize);
  647.     ShowMessage(s);
  648.   }
  649. #endif
  650. }
  651.  
  652. #endif /* ttblsz */
  653.  
  654.  
  655.