Initial commit based on GNU Shogi 1.2 patchlevel 3.
[gnushogi.git] / src / sizetest.c
blob9cc0f874b8563dafe35914d46dd2118ed9ec58fa
1 /*
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)
11 * any later version.
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.
24 #include "version.h"
25 #include "gnushogi.h"
27 #include <signal.h>
29 #if defined THINK_C
30 #include <console.h>
31 #include <time.h>
32 #endif
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;
47 char ColorStr[2][10];
49 long znodes;
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;
61 return(0);
64 #endif
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;
73 unsigned int
74 urand (void)
76 next *= 1103515245;
77 next += 12345;
78 return ((unsigned int) (next >> 16) & 0xFFFF);
81 void
82 gsrand (unsigned int seed)
84 next = seed;
87 #if ttblsz
88 struct hashentry *ttable[2];
89 unsigned int ttblsize;
90 #endif
91 #ifdef BINBOOK
92 extern char *binbookfile;
93 #endif
94 extern char *bookfile;
96 char savefile[128] = "";
97 char listfile[128] = "";
99 #if defined HISTORY
100 unsigned short far *history;
101 #endif
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];
111 #endif
112 struct flags flag;
114 short opponent, computer, WAwindow, WBwindow, BAwindow, BBwindow, dither,
115 INCscore;
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;
121 short player, xwndw;
122 /*unsigned*/ short rehash; /* -1 is used as a flag --tpm */
123 short Sdepth, Game50, MaxSearchDepth;
124 short GameCnt = 0;
125 short contempt;
126 int Book;
127 struct TimeControlRec TimeControl;
128 int TCadd = 0;
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};
133 unsigned short hint;
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] =
142 {4, 76, 0};
144 const long control[NO_PIECES] =
145 {0, ctlP, ctlL, ctlN, ctlS, ctlG, ctlB, ctlR,
146 ctlPp, ctlLp, ctlNp, ctlSp, ctlBp, ctlRp, ctlK };
148 short stage, stage2;
150 FILE *hashfile;
152 unsigned int starttime;
153 short int ahead = true, hash = true;
157 #if defined XSHOGI
158 void
159 TerminateChess (int sig)
161 ExitChess ();
164 #endif
168 int timeopp[MINGAMEIN], timecomp[MINGAMEIN];
169 int compptr, oppptr;
171 void
172 TimeCalc ()
174 /* adjust number of moves remaining in gamein games */
175 int increment = 0;
176 int topsum = 0;
177 int tcompsum = 0;
178 int me,him;
179 int i;
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)
212 long l;
213 int n;
215 #ifdef THINK_C
216 console_options.ncols = 100;
217 cshow(stdout);
218 #endif
220 #if ttblsz
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",
224 n,l,ttblsz,rehash);
225 #endif
227 #if defined CACHE
228 l = (long)sizeof(struct etable);
229 n = (int)((l * (size_t)ETABLE) / 1000);
230 #else
231 l = n = 0;
232 #endif
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);
239 #if defined HISTORY
240 n = (int)(sizeof_history / 1000);
241 #else
242 n = 0;
243 #endif
244 printf("history:\t%4d\tkByte\t[unsigned short:%ld * HISTORY_SIZE:%ld]\n",
245 n,sizeof(unsigned short),(long)HISTORY_SIZE);
247 #ifdef SAVE_NEXTPOS
248 #else
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);
258 #endif
260 #ifdef SAVE_DISTDATA
261 #else
262 n = (int)(sizeof(distdata_array) / 1000);
263 printf("distdata:\t%4d\tkByte\n",n);
264 #endif
266 #ifdef SAVE_PTYPE_DISTDATA
267 #else
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);
272 #endif
274 l = (long)sizeof(hashcode_array);
275 n = (int)(l / 1000);
276 printf("hashcode:\t%4d\tkByte\t[hashval:%ld]\n",
277 n,(long)sizeof(struct hashval));
279 l = (long)sizeof(drop_hashcode_array);
280 n = (int)(l / 1000);
281 printf("drop_hashcode:\t%4d\tkByte\t[hashval:%ld]\n",
282 n,(long)sizeof(struct hashval));
284 l = (long)sizeof(value_array);
285 n = (int)(l / 1000);
286 printf("value:\t\t%4d\tkByte\n",n);
288 l = (long)sizeof(fscore_array);
289 n = (int)(l / 1000);
290 printf("fscore:\t\t%4d\tkByte\n",n);