2 * sizetest.c - display memory usage of GNU SHOGI data
4 * Copyright (c) 1993, 1994, 1995 Matthias Mutz (GNU Shogi)
6 * This file is part of GNU SHOGI.
8 * GNU Shogi is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 1, or (at your option)
13 * GNU Shogi is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with GNU Shogi; see the file COPYING. If not, write to
20 * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
34 struct leaf far *Tree, *root;
36 short FROMsquare, TOsquare;
38 small_short ChkFlag[MAXDEPTH], CptrFlag[MAXDEPTH], TesujiFlag[MAXDEPTH];
39 short Pscore[MAXDEPTH], Tscore[MAXDEPTH];
40 small_short Pindex[NO_SQUARES];
42 short mtl[2], hung[2];
43 small_short PieceCnt[2];
45 struct GameRec far *GameList;
52 #if defined HASGETTIMEOFDAY && defined THINK_C
54 #define USEC_PER_CLOCK (1000000 / CLOCKS_PER_SEC)
56 int gettimeofday(struct timeval *tp, void *tzp)
58 long clock_count = (long)clock();
59 tp->tv_sec = clock_count / CLOCKS_PER_SEC;
60 tp->tv_usec = (clock_count % CLOCKS_PER_SEC) * USEC_PER_CLOCK;
67 * In a networked enviroment gnuchess might be compiled on different hosts
68 * with different random number generators, that is not acceptable if they
69 * are going to share the same transposition table.
71 unsigned long int next = 1;
78 return ((unsigned int) (next >> 16) & 0xFFFF);
82 gsrand (unsigned int seed)
88 struct hashentry *ttable[2];
89 unsigned int ttblsize;
92 extern char *binbookfile;
94 extern char *bookfile;
96 char savefile[128] = "";
97 char listfile[128] = "";
100 unsigned short far *history;
103 short rpthash[2][256];
104 short TrPnt[MAXDEPTH];
105 small_short PieceList[2][NO_SQUARES];
106 small_short PawnCnt[2][NO_COLS];
107 small_short Captured[2][NO_PIECES];
108 small_short Mvboard[NO_SQUARES];
109 #if !defined SAVE_SVALUE
110 short svalue[NO_SQUARES];
114 short opponent, computer, WAwindow, WBwindow, BAwindow, BBwindow, dither,
116 long ResponseTime, ExtraTime, MaxResponseTime, et, et0, time0, ft;
117 long GenCnt, NodeCnt, ETnodes, EvalNodes, HashCnt, HashAdd, FHashCnt, FHashAdd,
118 HashCol, THashCol, filesz, hashmask, hashbase;
119 long replus, reminus;
120 short HashDepth = HASHDEPTH, HashMoveLimit = HASHMOVELIMIT;
122 /*unsigned*/ short rehash; /* -1 is used as a flag --tpm */
123 short Sdepth, Game50, MaxSearchDepth;
127 struct TimeControlRec TimeControl;
129 short TCflag, TCmoves, TCminutes, TCseconds, OperatorTime;
130 short XCmoves[3], XCminutes[3], XCseconds[3], XC, XCmore;
131 const short otherside[3] =
132 {white, black, neutral};
134 short int TOflag; /* force search re-init if we backup search */
136 unsigned short killr0[MAXDEPTH], killr1[MAXDEPTH];
137 unsigned short killr2[MAXDEPTH], killr3[MAXDEPTH];
138 unsigned short PV, SwagHt, Swag0, Swag1, Swag2, Swag3, Swag4, sidebit;
140 small_short HasPiece[2][NO_PIECES];
141 const short kingP[3] =
144 const long control[NO_PIECES] =
145 {0, ctlP, ctlL, ctlN, ctlS, ctlG, ctlB, ctlR,
146 ctlPp, ctlLp, ctlNp, ctlSp, ctlBp, ctlRp, ctlK };
152 unsigned int starttime;
153 short int ahead = true, hash = true;
159 TerminateChess (int sig)
168 int timeopp[MINGAMEIN], timecomp[MINGAMEIN];
174 /* adjust number of moves remaining in gamein games */
180 /* dont do anything til you have enough numbers */
181 if (GameCnt < (MINGAMEIN * 2)) return;
182 /* calculate average time in sec for last MINGAMEIN moves */
183 for (i = 0; i < MINGAMEIN; i++)
185 tcompsum += timecomp[i];
186 topsum += timeopp[i];
188 topsum /= (100 * MINGAMEIN);
189 tcompsum /= (100 * MINGAMEIN);
190 /* if I have less time than opponent add another move */
191 me = TimeControl.clock[computer]/100;
192 him = TimeControl.clock[opponent]/100;
193 if(me < him) increment += 2;
194 if((him - me) > 60 || (me<him && me < 120))increment++;
195 /* if I am losing more time with each move add another */
196 /*if ( !((me - him) > 60) && tcompsum > topsum) increment++;*/
197 if ( tcompsum > topsum) increment +=2;
198 /* but dont let moves go below MINMOVES */
199 else if (TimeControl.moves[computer] < MINMOVES && !increment) increment++;
200 /* if I am doing really well use more time per move */
201 else if (me > him && tcompsum < topsum) increment = -1;
202 TimeControl.moves[computer] += increment;
210 main (int argc, char **argv)
216 console_options.ncols = 100;
221 l = (long)sizeof(struct hashentry);
222 n = (int)((l * (ttblsz + rehash) * 2) / 1000);
223 printf("ttable:\t\t%4d\tkByte\t[hashentry:%ld * (ttblsz:%d + rehash:%d) * 2]\n",
228 l = (long)sizeof(struct etable);
229 n = (int)((l * (size_t)ETABLE) / 1000);
233 printf("etab:\t\t%4d\tkByte\t[etable:%ld ETABLE:%d]\n",n,l,ETABLE);
235 l = (long)sizeof(struct leaf);
236 n = (int)(l * TREE / 1000);
237 printf("Tree:\t\t%4d\tkByte\t[leaf:%ld * TREE:%d]\n",n,l,TREE);
240 n = (int)(sizeof_history / 1000);
244 printf("history:\t%4d\tkByte\t[unsigned short:%ld * HISTORY_SIZE:%ld]\n",
245 n,sizeof(unsigned short),(long)HISTORY_SIZE);
249 l = (long)sizeof(next_array);
250 n = (int)((l * NO_PTYPE_PIECES) / 1000);
251 printf("nextpos:\t%4d\tkByte\t[next_array:%ld * NO_PTYPE_PIECES:%d]\n",
252 n,l,NO_PTYPE_PIECES);
254 l = (long)sizeof(next_array);
255 n = (int)((l * NO_PTYPE_PIECES) / 1000);
256 printf("nextdir:\t%4d\tkByte\t[next_array:%ld * NO_PTYPE_PIECES:%d]\n",
257 n,l,NO_PTYPE_PIECES);
262 n = (int)(sizeof(distdata_array) / 1000);
263 printf("distdata:\t%4d\tkByte\n",n);
266 #ifdef SAVE_PTYPE_DISTDATA
268 l = (long)sizeof(distdata_array);
269 n = (int)((l * NO_PTYPE_PIECES) / 1000);
270 printf("ptype_distdata:\t%4d\tkByte\t[distdata_array:%ld * NO_PTYPE_PIECES:%d]\n",
271 n,l,NO_PTYPE_PIECES);
274 l = (long)sizeof(hashcode_array);
276 printf("hashcode:\t%4d\tkByte\t[hashval:%ld]\n",
277 n,(long)sizeof(struct hashval));
279 l = (long)sizeof(drop_hashcode_array);
281 printf("drop_hashcode:\t%4d\tkByte\t[hashval:%ld]\n",
282 n,(long)sizeof(struct hashval));
284 l = (long)sizeof(value_array);
286 printf("value:\t\t%4d\tkByte\n",n);
288 l = (long)sizeof(fscore_array);
290 printf("fscore:\t\t%4d\tkByte\n",n);