Drop -ansi from gcc extra flags.
[gnushogi.git] / gnushogi / sizetest.c
blob7ed8bf3261de53437e2b9ed6db7895956a6fd130
1 /*
2 * FILE: sizetest.c
4 * Display memory usage of GNU Shogi data structures.
6 * ----------------------------------------------------------------------
7 * Copyright (c) 1993, 1994, 1995 Matthias Mutz
8 * Copyright (c) 1999 Michael Vanier and the Free Software Foundation
9 * Copyright (c) 2008, 2013, 2014 Yann Dirson and the Free Software Foundation
11 * GNU SHOGI is based on GNU CHESS
13 * Copyright (c) 1988, 1989, 1990 John Stanback
14 * Copyright (c) 1992 Free Software Foundation
16 * This file is part of GNU SHOGI.
18 * GNU Shogi is free software; you can redistribute it and/or modify it
19 * under the terms of the GNU General Public License as published by the
20 * Free Software Foundation; either version 3 of the License,
21 * or (at your option) any later version.
23 * GNU Shogi is distributed in the hope that it will be useful, but WITHOUT
24 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
25 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
26 * for more details.
28 * You should have received a copy of the GNU General Public License along
29 * with GNU Shogi; see the file COPYING. If not, see
30 * <http://www.gnu.org/licenses/>.
31 * ----------------------------------------------------------------------
35 #include "gnushogi.h"
37 #include <signal.h>
39 struct leaf *Tree, *root;
41 short FROMsquare, TOsquare;
43 small_short ChkFlag[MAXDEPTH], CptrFlag[MAXDEPTH], TesujiFlag[MAXDEPTH];
44 short Pscore[MAXDEPTH], Tscore[MAXDEPTH];
45 small_short Pindex[NO_SQUARES];
47 short mtl[2], hung[2];
48 small_short PieceCnt[2];
50 struct GameRec *GameList;
52 char ColorStr[2][10];
54 long znodes;
58 * In a networked enviroment gnushogi might be compiled on different hosts
59 * with different random number generators; that is not acceptable if they
60 * are going to share the same transposition table.
63 unsigned long next = 1;
65 unsigned int
66 urand(void)
68 next *= 1103515245;
69 next += 12345;
70 return ((unsigned int) (next >> 16) & 0xFFFF);
74 void
75 gsrand(unsigned int seed)
77 next = seed;
81 #if ttblsz
82 struct hashentry *ttable[2];
83 unsigned int ttblsize;
84 #endif
86 #ifdef BINBOOK
87 extern char *binbookfile;
88 #endif
90 extern char *bookfile;
92 char savefile[128] = "";
93 char listfile[128] = "";
95 #if defined HISTORY
96 unsigned short *history;
97 #endif
99 short rpthash[2][256];
100 short TrPnt[MAXDEPTH];
101 small_short PieceList[2][NO_SQUARES];
102 small_short PawnCnt[2][NO_COLS];
103 small_short Captured[2][NO_PIECES];
104 small_short Mvboard[NO_SQUARES];
106 #if !defined SAVE_SVALUE
107 short svalue[NO_SQUARES];
108 #endif
110 struct flags flag;
112 short opponent, computer, WAwindow, WBwindow, BAwindow, BBwindow, dither,
113 INCscore;
114 long ResponseTime, ExtraTime, MaxResponseTime, et, et0, time0, ft;
115 long GenCnt, NodeCnt, ETnodes, EvalNodes, HashCnt,
116 HashAdd, FHashCnt, FHashAdd,
117 HashCol, THashCol, filesz, hashmask, hashbase;
118 long replus, reminus;
119 short HashDepth = HASHDEPTH, HashMoveLimit = HASHMOVELIMIT;
120 short player, xwndw;
121 /*unsigned*/ short rehash; /* -1 is used as a flag --tpm */
122 short Sdepth, Game50, MaxSearchDepth;
123 short GameCnt = 0;
124 short contempt;
125 int Book;
126 struct TimeControlRec TimeControl;
127 int TCadd = 0;
128 short TCflag, TCmoves, TCminutes, TCseconds, OperatorTime;
129 short XCmoves[3], XCminutes[3], XCseconds[3], XC, XCmore;
130 const short otherside[3] = { white, black, neutral };
131 unsigned short hint;
132 short TOflag; /* force search re-init if we backup search */
134 unsigned short killr0[MAXDEPTH], killr1[MAXDEPTH];
135 unsigned short killr2[MAXDEPTH], killr3[MAXDEPTH];
136 unsigned short PV, SwagHt, Swag0, Swag1, Swag2, Swag3, Swag4, sidebit;
138 small_short HasPiece[2][NO_PIECES];
139 const short kingP[3] = { 4, 76, 0 };
141 const long control[NO_PIECES] =
142 { 0, ctlP, ctlL, ctlN, ctlS, ctlG, ctlB, ctlR,
143 ctlPp, ctlLp, ctlNp, ctlSp, ctlBp, ctlRp, ctlK };
145 short stage, stage2;
147 FILE *hashfile;
149 unsigned int starttime;
150 short ahead = true, hash = true;
153 int timeopp[MINGAMEIN], timecomp[MINGAMEIN];
154 int compptr, oppptr;
156 void
157 TimeCalc()
159 /* adjust number of moves remaining in gamein games */
160 int increment = 0;
161 int topsum = 0;
162 int tcompsum = 0;
163 int me, him;
164 int i;
166 /* don't do anything til you have enough numbers */
167 if (GameCnt < (MINGAMEIN * 2))
168 return;
170 /* calculate average time in sec for last MINGAMEIN moves */
171 for (i = 0; i < MINGAMEIN; i++)
173 tcompsum += timecomp[i];
174 topsum += timeopp[i];
177 topsum /= (100 * MINGAMEIN);
178 tcompsum /= (100 * MINGAMEIN);
179 /* if I have less time than opponent add another move */
180 me = TimeControl.clock[computer] / 100;
181 him = TimeControl.clock[opponent] / 100;
183 if (me < him)
184 increment += 2;
186 if (((him - me) > 60) || ((me < him) && (me < 120)))
187 increment++;
189 /* if I am losing more time with each move add another */
190 /* if (!((me - him) > 60) && tcompsum > topsum) increment++; */
192 if (tcompsum > topsum)
194 increment += 2;
196 else if ((TimeControl.moves[computer] < MINMOVES) && !increment)
198 /* but don't let moves go below MINMOVES */
199 increment++;
201 else if ((me > him) && (tcompsum < topsum))
203 /* if I am doing really well use more time per move */
204 increment = -1;
207 TimeControl.moves[computer] += increment;
213 main(int argc, char **argv)
215 long l;
216 int n;
218 #if ttblsz
219 l = (long)sizeof(struct hashentry);
220 n = (int)((l * (ttblsz + rehash) * 2) / 1000);
221 printf("ttable:\t\t%4d\tkByte\t[hashentry:%ld "
222 "* (ttblsz:%d + rehash:%d) * 2]\n",
223 n, l, ttblsz, rehash);
224 #endif
226 #if defined CACHE
227 l = (long)sizeof(struct etable);
228 n = (int)((l * (size_t)ETABLE) / 1000);
229 #else
230 l = n = 0;
231 #endif
233 printf("etab:\t\t%4d\tkByte\t[etable:%ld ETABLE:%d]\n",
234 n, l, ETABLE);
236 l = (long)sizeof(struct leaf);
237 n = (int)(l * TREE / 1000);
238 printf("Tree:\t\t%4d\tkByte\t[leaf:%ld * TREE:%d]\n",
239 n, l, TREE);
241 #if defined HISTORY
242 n = (int)(sizeof_history / 1000);
243 #else
244 n = 0;
245 #endif
247 printf("history:\t%4d\tkByte\t[unsigned short:%d "
248 "* HISTORY_SIZE:%ld]\n",
249 n, sizeof(unsigned short), (long)HISTORY_SIZE);
251 #ifndef SAVE_NEXTPOS
252 l = (long)sizeof(next_array);
253 n = (int)((l * NO_PTYPE_PIECES) / 1000);
255 printf("nextpos:\t%4d\tkByte\t[next_array:%ld "
256 "* NO_PTYPE_PIECES:%d]\n",
257 n, l, NO_PTYPE_PIECES);
259 l = (long)sizeof(next_array);
260 n = (int)((l * NO_PTYPE_PIECES) / 1000);
261 printf("nextdir:\t%4d\tkByte\t[next_array:%ld "
262 "* NO_PTYPE_PIECES:%d]\n",
263 n, l, NO_PTYPE_PIECES);
264 #endif
266 #ifndef SAVE_DISTDATA
267 n = (int)(sizeof(distdata_array) / 1000);
268 printf("distdata:\t%4d\tkByte\n", n);
269 #endif
271 #ifndef SAVE_PTYPE_DISTDATA
272 l = (long)sizeof(distdata_array);
273 n = (int)((l * NO_PTYPE_PIECES) / 1000);
274 printf("ptype_distdata:\t%4d\tkByte\t[distdata_array:%ld "
275 "* NO_PTYPE_PIECES:%d]\n",
276 n, l, NO_PTYPE_PIECES);
277 #endif
279 l = (long)sizeof(hashcode_array);
280 n = (int)(l / 1000);
281 printf("hashcode:\t%4d\tkByte\t[hashval:%ld]\n",
282 n, (long)sizeof(struct hashval));
284 l = (long)sizeof(drop_hashcode_array);
285 n = (int)(l / 1000);
286 printf("drop_hashcode:\t%4d\tkByte\t[hashval:%ld]\n",
287 n, (long)sizeof(struct hashval));
289 l = (long)sizeof(value_array);
290 n = (int)(l / 1000);
291 printf("value:\t\t%4d\tkByte\n", n);
293 l = (long)sizeof(fscore_array);
294 n = (int)(l / 1000);
295 printf("fscore:\t\t%4d\tkByte\n", n);
297 return 0;