2 * init.c - C source for GNU SHOGI
4 * Copyright (c) 1993, 1994, 1995 Matthias Mutz
6 * GNU SHOGI is based on GNU CHESS
8 * Copyright (c) 1988,1989,1990 John Stanback
9 * Copyright (c) 1992 Free Software Foundation
11 * This file is part of GNU SHOGI.
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)
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.
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.
32 #if defined HASGETTIMEOFDAY && !defined THINK_C
47 unsigned int ttbllimit;
49 /* .... MOVE GENERATION VARIABLES AND INITIALIZATIONS .... */
53 #define abs(a) (((a)<0)?-(a):(a))
55 #if !defined(MSDOS) || defined(__GO32__)
56 #define max(a,b) (((a)<(b))?(b):(a))
58 #define odd(a) ((a) & 1)
61 const small_short piece_of_ptype[NO_PTYPE_PIECES] =
62 { pawn, lance, knight, silver, gold, bishop, rook, pbishop, prook, king,
63 pawn, lance, knight, silver, gold };
66 const small_short side_of_ptype[NO_PTYPE_PIECES] =
67 { black, black, black, black, black, black, black, black, black, black,
68 white, white, white, white, white };
71 const small_short psweep[NO_PTYPE_PIECES] =
72 { false, true, false, false, false, true, true, true, true, false,
73 false, true, false, false, false };
76 const small_short sweep[NO_PIECES] =
77 { false, false, true, false, false, false, true, true,
78 false, false, false, false, true, true, false };
81 #if !defined EXTLANGFILE
83 char far *CP[CPSIZE] =
90 #include "gnushogi.lng"
102 ptype_distance (short ptyp, short f, short t)
105 * Determine the minimum number of moves for a piece from
106 * square "f" to square "t". If the piece cannot reach "t",
107 * the count is set to CANNOT_REACH.
110 #define csquare(sq) ((side == black) ? sq : (NO_SQUARES-1-sq))
111 #define crow(sq) row(csquare(sq))
112 #define ccol(sq) column(csquare(sq))
116 short colf, colt, rowf, rowt, dcol, drow;
121 piece = piece_of_ptype[ptyp];
122 side = side_of_ptype[ptyp];
124 dcol = (colt = ccol(t)) - (colf = ccol(f));
125 drow = (rowt = crow(t)) - (rowf = crow(f));
130 if ( (dcol != 0) || (drow < 1) )
131 return (CANNOT_REACH);
136 if ( (dcol != 0) || (drow < 1) )
137 return (CANNOT_REACH);
142 if ( odd(drow) || (odd(drow / 2) != odd(dcol)) )
143 return (CANNOT_REACH);
144 else if ( (drow == 0) || ((drow / 2) < abs(dcol)) )
145 return (CANNOT_REACH);
151 if ( odd(drow) == odd(dcol) )
152 return max(abs(drow),abs(dcol));
154 if ( abs(dcol) <= drow )
157 return (max(abs(drow),abs(dcol))+1);
159 if ( odd(drow) == odd(dcol) )
160 return (max(abs(drow),abs(dcol)));
162 return (max(abs(drow)+1,abs(dcol))+1);
170 if ( abs(dcol) == 0 )
172 else if ( drow >= 0 )
173 return max(drow,abs(dcol));
175 return (abs(dcol)-drow);
178 if ( odd(dcol) != odd(drow) )
179 return (CANNOT_REACH);
181 return ((abs(dcol) == abs(drow)) ? 1 : 2);
184 if ( odd(dcol) != odd(drow) )
185 if ( (abs(dcol) <= 1) && (abs(drow) <= 1) )
187 else if ( abs(abs(dcol) - abs(drow)) == 1 )
192 return ((abs(dcol) == abs(drow)) ? 1 : 2);
195 if ( (dcol == 0) || (drow == 0) )
201 if ( (dcol == 0) || (drow == 0) )
203 else if ( (abs(dcol) == 1) && (abs(drow) == 1) )
209 return max(abs(drow),abs(dcol));
212 /* should never occur */
213 return (CANNOT_REACH);
221 short distance (short a, short b)
223 return (short)computed_distance(a,b);
226 short distance (short a, short b)
228 return (use_distdata ? (short)(*distdata)[(int)a][(int)b] : (short)computed_distance(a,b));
233 #ifdef SAVE_PTYPE_DISTDATA
234 short piece_distance(short side,short piece,short f,short t)
236 return ((f > NO_SQUARES) ? (short)1 : (short)ptype_distance(ptype[side][piece],f,t));
239 short piece_distance(short side,short piece,short f,short t)
241 return ((f > NO_SQUARES) ? (short)1 :
242 (use_ptype_distdata ? (short)(*ptype_distdata[ptype[side][piece]])[f][t] :
243 (short)ptype_distance(ptype[side][piece],f,t)));
249 Initialize_dist (void)
251 register short a, b, d, di, ptyp;
252 #ifndef SAVE_DISTDATA
253 for (a = 0; a < NO_SQUARES; a++)
254 for (b = 0; b < NO_SQUARES; b++)
256 d = abs (column (a) - column (b));
257 di = abs (row (a) - row (b));
258 (*distdata)[a][b] = (small_short)((d > di) ? d : di);
261 #ifndef SAVE_PTYPE_DISTDATA
262 for (ptyp = 0; ptyp < NO_PTYPE_PIECES; ptyp++)
264 for (a = 0; a < NO_SQUARES; a++)
265 for (b = 0; b < NO_SQUARES; b++)
266 (*ptype_distdata[ptyp])[a][b] = ptype_distance(ptyp,a,b);
273 * nextpos[piece][from-square] , nextdir[piece][from-square] gives vector of
274 * positions reachable from from-square in ppos with piece such that the
275 * sequence ppos = nextpos[piece][from-square]; pdir =
276 * nextdir[piece][from-square]; u = ppos[sq]; do { u = ppos[u]; if(color[u]
277 * != neutral) u = pdir[u]; } while (sq != u); will generate the sequence of
278 * all squares reachable from sq.
280 * If the path is blocked u = pdir[sq] will generate the continuation of the
281 * sequence in other directions.
286 * ptype is used to separate black and white pawns, like this; ptyp =
287 * ptype[side][piece] piece can be used directly in nextpos/nextdir when
288 * generating moves for pieces that are not white pawns.
291 const small_short ptype[2][NO_PIECES] =
292 { ptype_no_piece, ptype_pawn, ptype_lance, ptype_knight,
293 ptype_silver, ptype_gold, ptype_bishop, ptype_rook,
294 ptype_gold, ptype_gold, ptype_gold, ptype_gold,
295 ptype_pbishop, ptype_prook, ptype_king,
296 ptype_no_piece, ptype_wpawn, ptype_wlance, ptype_wknight,
297 ptype_wsilver, ptype_wgold, ptype_bishop, ptype_rook,
298 ptype_wgold, ptype_wgold, ptype_wgold, ptype_wgold,
299 ptype_pbishop, ptype_prook, ptype_king};
301 const small_short promoted[NO_PIECES] =
302 { no_piece, ppawn, plance, pknight, psilver, gold, pbishop, prook,
303 ppawn, plance, pknight, psilver, pbishop, prook, king };
305 const small_short unpromoted[NO_PIECES] =
306 { no_piece, pawn, lance, knight, silver, gold, bishop, rook,
307 pawn, lance, knight, silver, bishop, rook, king };
309 const small_short is_promoted[NO_PIECES] =
310 { false, false, false, false, false, false, false, false,
311 true, true, true, true, true, true, false };
313 /* data used to generate nextpos/nextdir */
314 #if !defined SAVE_NEXTPOS
317 const small_short direc[NO_PTYPE_PIECES][8] =
319 11, 0, 0, 0, 0, 0, 0, 0 , /* 0 ptype_pawn */
320 11, 0, 0, 0, 0, 0, 0, 0 , /* 1 ptype_lance */
321 21, 23, 0, 0, 0, 0, 0, 0 , /* 2 ptype_knight */
322 10, 11, 12,-12,-10, 0, 0, 0 , /* 3 ptype_silver */
323 10, 11, 12, -1, 1,-11, 0, 0 , /* 4 ptype_gold */
324 10, 12,-12,-10, 0, 0, 0, 0 , /* 5 ptype_bishop */
325 11, -1, 1,-11, 0, 0, 0, 0 , /* 6 ptype_rook */
326 10, 12,-12,-10, 11, -1, 1,-11 , /* 7 ptype_pbishop */
327 11, -1, 1,-11, 10, 12,-12,-10 , /* 8 ptype_prook */
328 10, 11, 12, -1, 1,-12,-11,-10 , /* 9 ptype_king */
329 -11, 0, 0, 0, 0, 0, 0, 0 , /* 10 ptype_wpawn */
330 -11, 0, 0, 0, 0, 0, 0, 0 , /* 11 ptype_wlance */
331 -21,-23, 0, 0, 0, 0, 0, 0 , /* 12 ptype_wknight */
332 -10,-11,-12, 12, 10, 0, 0, 0 , /* 13 ptype_wsilver */
333 -10,-11,-12, 1, -1, 11, 0, 0 }; /* 14 ptype_wgold */
336 small_short diagonal(short d)
337 { return(abs(d) == 10 || abs(d) == 12);
341 static const small_short max_steps[NO_PTYPE_PIECES] =
342 {1, 8, 1, 1, 1, 8, 8, 8, 8, 1, 1, 8, 1, 1, 1 };
344 const small_short nunmap[(NO_COLS+2)*(NO_ROWS+4)] =
346 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
347 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
348 -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, -1,
349 -1, 9, 10, 11, 12, 13, 14, 15, 16, 17, -1,
350 -1, 18, 19, 20, 21, 22, 23, 24, 25, 26, -1,
351 -1, 27, 28, 29, 30, 31, 32, 33, 34, 35, -1,
352 -1, 36, 37, 38, 39, 40, 41, 42, 43, 44, -1,
353 -1, 45, 46, 47, 48, 49, 50, 51, 52, 53, -1,
354 -1, 54, 55, 56, 57, 58, 59, 60, 61, 62, -1,
355 -1, 63, 64, 65, 66, 67, 68, 69, 70, 71, -1,
356 -1, 72, 73, 74, 75, 76, 77, 78, 79, 80, -1,
357 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
358 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1};
361 const small_short inunmap[NO_SQUARES] =
363 23, 24, 25, 26, 27, 28, 29, 30, 31,
364 34, 35, 36, 37, 38, 39, 40, 41, 42,
365 45, 46, 47, 48, 49, 50, 51, 52, 53,
366 56, 57, 58, 59, 60, 61, 62, 63, 64,
367 67, 68, 69, 70, 71, 72, 73, 74, 75,
368 78, 79, 80, 81, 82, 83, 84, 85, 86,
369 89, 90, 91, 92, 93, 94, 95, 96, 97,
370 100,101,102,103,104,105,106,107,108,
371 111,112,113,114,115,116,117,118,119 };
373 int InitFlag = false;
376 #if defined SAVE_NEXTPOS
378 short next_direction(short ptyp, short *d, short sq)
380 short delta, to, sfrom = inunmap[sq];
383 if ( *d >= 8 ) return sq;
384 delta = direc[ptyp][*d];
385 if ( delta == 0 ) return sq;
386 to = nunmap[sfrom + delta];
391 short next_position(short ptyp, short *d, short sq, short u)
393 if ( *d < 4 && psweep[ptyp] ) {
394 short to = nunmap[inunmap[u]+direc[ptyp][*d]];
396 return next_direction(ptyp,d,sq);
400 return next_direction(ptyp,d,sq);
404 short first_direction(short ptyp, short *d, short sq)
407 return next_direction(ptyp,d,sq);
413 Initialize_moves (void)
416 * This procedure pre-calculates all moves for every piece from every square.
417 * This data is stored in nextpos/nextdir and used later in the move
418 * generation routines.
422 short ptyp, po, p0, d, di, s, delta, i;
423 unsigned char far *ppos, *pdir;
427 short fpo=23,tpo=120;
429 for (ptyp = 0; ptyp < NO_PTYPE_PIECES; ptyp++)
431 for (po = 0; po < NO_SQUARES; po++)
432 for (p0 = 0; p0 < NO_SQUARES; p0++)
434 (*nextpos[ptyp])[po][p0] = (unsigned char) po;
435 (*nextdir[ptyp])[po][p0] = (unsigned char) po;
439 for (ptyp = 0; ptyp < NO_PTYPE_PIECES; ptyp++)
440 for (po = fpo; po < tpo; po++)
441 if (nunmap[po] >= (small_short)0)
443 ppos = (*nextpos[ptyp])[nunmap[po]];
444 pdir = (*nextdir[ptyp])[nunmap[po]];
445 /* dest is a function of direction and steps */
446 for (d = 0; d < 8; d++)
448 dest[d][0] = nunmap[po];
449 delta = direc[ptyp][d];
453 for (s = 0; s < max_steps[ptyp]; s++)
458 * break if (off board) or (promoted rooks wishes to
459 * move two steps diagonal) or (promoted
460 * bishops wishes to move two steps non-diagonal)
462 if ( (nunmap[p0] < (small_short)0) ||
463 ((ptyp == ptype_prook) && (s > 0) && diagonal(delta)) ||
464 ((ptyp == ptype_pbishop) && (s > 0) && !diagonal(delta)) )
467 dest[d][s] = nunmap[p0];
474 * sort dest in number of steps order currently no sort
475 * is done due to compability with the move generation
476 * order in old gnu chess
479 for (di = d; s > 0 && di > 0; di--)
480 if (steps[sorted[di - 1]] == 0) /* should be: < s */
481 sorted[di] = sorted[di - 1];
488 * update nextpos/nextdir
491 pdir[p0] = (unsigned char) dest[sorted[0]][0];
492 for (d = 0; d < 8; d++)
493 for (s = 0; s < steps[sorted[d]]; s++)
495 ppos[p0] = (unsigned char) dest[sorted[d]][s];
496 p0 = dest[sorted[d]][s];
498 pdir[p0] = (unsigned char) dest[sorted[d + 1]][0];
501 * else is already initialized
515 * Reset the board and other variables to start a new game.
519 short l, c, p, max_opening_sequence;
520 #ifdef HASGETTIMEOFDAY
523 compptr = oppptr = 0;
524 stage = 0; stage2 = -1; /* the game is not yet started */
525 flag.illegal = flag.mate = flag.post = flag.quit = flag.reverse = flag.bothsides = flag.onemove = flag.force = false;
526 flag.material = flag.coords = flag.hash = flag.easy = flag.beep = flag.rcptr = true;
527 flag.stars = flag.shade = flag.back = flag.musttimeout = false;
529 #if defined(MSDOS) && !defined(SEVENBIT)
533 #endif /* MSDOS && !SEVENBIT */
535 GenCnt = NodeCnt = et0 = dither = XCmore = 0;
543 MaxSearchDepth = MAXDEPTH - 1;
547 CptrFlag[0] = TesujiFlag[0] = false;
550 GameType[0] = GameType[1] = UNKNOWN;
551 Pscore[0] = Tscore[0] = (SCORE_LIMIT+3000);
552 opponent = player = black;
554 for (l = 0; l < TREE; l++)
555 Tree[l].f = Tree[l].t = 0;
556 gsrand ((unsigned int) 1);
559 for (c = black; c <= white; c++)
560 for (p = pawn; p <= king; p++)
561 for (l = 0; l < NO_SQUARES; l++)
563 (*hashcode)[c][p][l].key = (((unsigned long) urand ()));
564 (*hashcode)[c][p][l].key += (((unsigned long) urand ()) << 16);
565 (*hashcode)[c][p][l].bd = (((unsigned long) urand ()));
566 (*hashcode)[c][p][l].bd += (((unsigned long) urand ()) << 16);
568 (*hashcode)[c][p][l].key += (((unsigned long) urand ()) << 32);
569 (*hashcode)[c][p][l].key += (((unsigned long) urand ()) << 48);
570 (*hashcode)[c][p][l].bd += (((unsigned long) urand ()) << 32);
571 (*hashcode)[c][p][l].bd += (((unsigned long) urand ()) << 48);
574 for (c = black; c <= white; c++)
575 for (p = pawn; p <= king; p++)
576 for (l = 0; l < MAX_CAPTURED; l++)
578 (*drop_hashcode)[c][p][l].key = (((unsigned long) urand ()));
579 (*drop_hashcode)[c][p][l].key += (((unsigned long) urand ()) << 16);
580 (*drop_hashcode)[c][p][l].bd = (((unsigned long) urand ()));
581 (*drop_hashcode)[c][p][l].bd += (((unsigned long) urand ()) << 16);
583 (*drop_hashcode)[c][p][l].key += (((unsigned long) urand ()) << 32);
584 (*drop_hashcode)[c][p][l].key += (((unsigned long) urand ()) << 48);
585 (*drop_hashcode)[c][p][l].bd += (((unsigned long) urand ()) << 32);
586 (*drop_hashcode)[c][p][l].bd += (((unsigned long) urand ()) << 48);
590 for (l = 0; l < NO_SQUARES; l++)
592 board[l] = Stboard[l];
593 color[l] = Stcolor[l];
599 #ifdef HASGETTIMEOFDAY
600 gettimeofday(&tv, NULL);
601 time0 = tv.tv_sec*100+tv.tv_usec/10000;
602 #elif defined THINK_C
605 time0 = time ((long *) 0);
607 /* resetting reference time */
608 ElapsedTime (COMPUTE_AND_INIT_MODE);
609 flag.regularstart = true;
617 else if (MaxResponseTime == 0)
619 UpdateDisplay (0, 0, 1, 0);
621 GetOpeningPatterns (&max_opening_sequence);
623 /* ShowOpeningPatterns (max_opening_sequence); */
628 if(TTadd){ZeroTTable (); TTadd = 0;}
630 hashbd = hashkey = 0;
637 Initialize_data (void)
641 char buffer[60],buf2[60];
647 ShowMessage("datatype 'small_short' is unsigned; check gnushogi.h\n");
652 n = sizeof(struct leaf) * (size_t)TREE;
653 Tree = HEAP_ALLOC(n);
655 sprintf(buffer,"Cannot allocate %ld bytes for search tree",n);
656 ShowMessage (buffer);
660 printf("Tree memory: %ld\n",(long)n);
664 n = sizeof(hashcode_array);
665 hashcode = HEAP_ALLOC(n);
667 sprintf(buffer,"Cannot allocate %ld bytes for hashcode",n);
672 printf("hashcode memory: %ld\n",(long)n);
676 n = sizeof(drop_hashcode_array);
677 drop_hashcode = HEAP_ALLOC(n);
678 if ( !drop_hashcode ) {
679 sprintf(buffer,"Cannot allocate %ld bytes for drop_hashcode",n);
684 printf("drop_hashcode memory: %ld\n",(long)n);
688 n = sizeof(struct GameRec) * (size_t)(MAXMOVES + MAXDEPTH);
689 GameList = HEAP_ALLOC(n);
691 sprintf(buffer,"Cannot allocate %ld bytes for game record",n);
696 printf("GameList memory: %ld\n",(long)n);
700 #if !defined SAVE_NEXTPOS
701 n = sizeof(next_array);
702 for ( i=0; i<NO_PTYPE_PIECES; i++ ) {
703 nextdir[i] = use_nextpos ? HEAP_ALLOC(n) : NULL;
706 sprintf(buffer,"cannot allocate %ld space for nextdir %d",(long)(n),i);
707 ShowMessage (buffer);
712 nextpos[i] = use_nextpos ? HEAP_ALLOC(n) : NULL;
715 sprintf(buffer,"cannot allocate %ld space for nextpos %d",(long)(n),i);
716 ShowMessage (buffer);
721 if ( !use_nextpos ) {
725 printf("nextdir+nextpos memory: %ld\n",(long)(n*2*NO_PTYPE_PIECES));
730 n = sizeof(value_array);
731 value = HEAP_ALLOC(n);
733 ShowMessage("cannot allocate value space");
737 printf("value memory: %ld\n",(long)n);
740 n = sizeof(fscore_array);
741 fscore = HEAP_ALLOC(n);
743 ShowMessage("cannot allocate fscore space");
747 printf("fscore memory: %ld\n",(long)n);
753 history = HEAP_ALLOC(n);
755 sprintf(buffer,"Cannot allocate %ld bytes for history table",sizeof_history);
760 printf("history memory: %ld\n",(long)n);
766 n = sizeof(struct etable) * (size_t)ETABLE;
767 for ( i=0; i<2; i++ ) {
768 etab[i] = use_etable ? HEAP_ALLOC(n) : 0;
770 sprintf(buffer,"Cannot allocate %ld bytes for cache table i",n,i);
771 ShowMessage (buffer);
777 printf("etab memory: %ld (etable=%ld ETABLE=%ld)\n",
778 (long)(n*2),(long)sizeof(struct etable),(long)ETABLE);
787 n = sizeof(struct hashentry)*(ttblsize+rehash);
789 printf("ttblsize = %ld rehash = %ld n = %ld\n",(long)ttblsize,(long)rehash,(long)n);
791 while ( doit && ttblsize > MINTTABLE ) {
793 printf("try to allocate %d bytes for transposition table\n",(long)2*n);
795 ttable[0] = HEAP_ALLOC(n);
796 ttable[1] = ttable[0] ? HEAP_ALLOC(n) : NULL;
797 if ( !ttable[0] || !ttable[1] ) {
799 HEAP_FREE(ttable[0]);
802 HEAP_FREE(ttable[1]);
804 ttblsize = ttblsize >> 1;
805 n = sizeof(struct hashentry)*(ttblsize+rehash);
808 if ( ttblsize <= MINTTABLE ) {
813 sprintf(buffer,"ttable's memory: %ld, ttblsize=%ld rehash=%ld",
814 (long)2*n,(long)ttblsize,(long)rehash);
817 ttbllimit = ttblsize<<1 - ttblsize>>2;
819 printf("ttbllimit = %ld\n",(long)ttbllimit);
822 sprintf(buffer,"Cannot allocate %ld bytes for transposition table",(long)(2*n));
823 ShowMessage (buffer);
824 ttable[0] = ttable[1] = NULL;
828 #if !defined SAVE_DISTDATA
829 n = sizeof(distdata_array);
830 distdata = HEAP_ALLOC(n);
833 ShowMessage("cannot allocate distdata space...");
834 use_distdata = false;
839 printf("distdata memory: %ld\n",(long)n);
844 #if !defined SAVE_PTYPE_DISTDATA
845 n = sizeof(distdata_array);
846 for ( i=0; i<NO_PTYPE_PIECES; i++ ) {
847 ptype_distdata[i] = use_ptype_distdata ? HEAP_ALLOC(n) : 0;
848 if ( !ptype_distdata[i] ) {
849 sprintf(buffer,"cannot allocate %ld bytes for ptype_distdata %d...",(long)n,i);
850 use_ptype_distdata = false;
854 if ( use_ptype_distdata ) {
855 printf("ptype_distdata memory: %ld\n",(long)(n*NO_PTYPE_PIECES));
864 #if defined EXTLANGFILE
871 InitConst (char *lang)
879 constfile = fopen (LANGFILE, "r");
882 ShowMessage ("NO LANGFILE");
885 while (fgets (s, sizeof (s), constfile))
890 for (q = &s[len]; q > &s[8]; q--)
895 ShowMessage("{ error in cinstfile");
899 if (s[3] != ':' || s[7] != ':' || s[8] != '{')
901 sprintf (buffer,"Langfile format error %s", s);
911 if (strcmp (&s[4], lang))
914 if (entry < 0 || entry >= CPSIZE)
916 ShowMessage("Langfile number error");
919 for (q = p = &s[9]; *p; p++)
925 else if (*(p + 1) == 'n')
932 if (entry < 0 || entry > 255)
934 sprintf (buffer,"Langfile error %d\n", entry);
938 CP[entry] = (char far *) GLOBAL_ALLOC ((unsigned) strlen (&s[9]) + 1);
939 if (CP[entry] == NULL)
942 sprintf(buffer,"CP MALLOC, entry %d",entry);
946 strcpy (CP[entry], &s[9]);
955 InitConst (char *lang)
963 constfile = fopen (LANGFILE, "r");
966 ShowMessage ("NO LANGFILE");
969 while (fgets (s, sizeof (s), constfile))
974 if (len > 3 && s[3] == ':' || len > 7 && s[7] == ':' )
976 ShowMessage("old Langfile error");
981 ShowMessage("length error in Langfile");
984 for (q = &s[len]; q > &s[15]; q--)
989 ShowMessage("\" error in Langfile");
993 if (s[6] != ':' || s[10] != ':' || s[15] != '"')
995 sprintf (buffer,"Langfile format error %s", s);
1005 if (strcmp (&s[7], lang))
1007 entry = atoi (&s[3]);
1008 if (entry < 0 || entry >= CPSIZE)
1010 ShowMessage("Langfile number error");
1013 for (q = p = &s[16]; *p; p++)
1019 else if (*(p + 1) == 'n')
1026 if (entry < 0 || entry > 255)
1028 sprintf (buffer,"Langfile error %d\n", entry);
1029 ShowMessage(buffer);
1032 CP[entry] = (char far *) GLOBAL_ALLOC ((unsigned) strlen (&s[16]) + 1);
1033 if (CP[entry] == NULL)
1036 sprintf(buffer,"CP MALLOC, entry %d",entry);
1040 strcpy (CP[entry], &s[16]);
1055 gsrand (starttime = ((unsigned int) time ((time_t *) 0))); /* init urand */
1057 gsrand (starttime = ((unsigned int) time ((long *) 0))); /* init urand */
1065 if ( Initialize_data() != 0 )
1068 #if defined EXTLANGFILE
1072 strcpy(ColorStr[0],CP[118]);
1073 strcpy(ColorStr[1],CP[119]);
1076 MaxResponseTime = 0;
1079 signal (SIGTERM, TerminateSearch);
1097 #if !defined SAVE_NEXTPOS
1098 Initialize_moves ();
1106 xwndw = atoi (xwin);
1114 hashfile = fopen (HASHFILE, RWA_ACC);
1117 fseek (hashfile, 0L, SEEK_END);
1118 filesz = ftell (hashfile) / sizeof (struct fileentry) - 1 - MAXrehash;
1119 hashmask = filesz>>1;
1120 hashbase = hashmask+1;
1122 #endif /* HASHFILE */
1140 #endif /* HASHFILE */