Changing license to GPL3 (and bumping version to 1.4.0).
[gnushogi.git] / gnushogi / sizetest.c
blobbfd007fcfa8bb3167b3c17a37d41adc652c7b64f
1 /*
2 * FILE: sizetest.c
4 * Display memory usage of GNU Shogi data structures.
6 * ----------------------------------------------------------------------
8 * Copyright (c) 2012 Free Software Foundation
10 * GNU SHOGI is based on GNU CHESS
12 * This file is part of GNU SHOGI.
14 * GNU Shogi is free software; you can redistribute it and/or modify it
15 * under the terms of the GNU General Public License as published by the
16 * Free Software Foundation; either version 3 of the License,
17 * or (at your option) any later version.
19 * GNU Shogi is distributed in the hope that it will be useful, but WITHOUT
20 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22 * for more details.
24 * You should have received a copy of the GNU General Public License along
25 * with GNU Shogi; see the file COPYING. If not, see
26 * <http://www.gnu.org/licenses/>.
27 * ----------------------------------------------------------------------
31 #include "version.h"
32 #include "gnushogi.h"
34 #include <signal.h>
36 struct leaf *Tree, *root;
38 short FROMsquare, TOsquare;
40 small_short ChkFlag[MAXDEPTH], CptrFlag[MAXDEPTH], TesujiFlag[MAXDEPTH];
41 short Pscore[MAXDEPTH], Tscore[MAXDEPTH];
42 small_short Pindex[NO_SQUARES];
44 short mtl[2], hung[2];
45 small_short PieceCnt[2];
47 struct GameRec *GameList;
49 char ColorStr[2][10];
51 long znodes;
55 * In a networked enviroment gnushogi might be compiled on different hosts
56 * with different random number generators; that is not acceptable if they
57 * are going to share the same transposition table.
60 unsigned long next = 1;
62 unsigned int
63 urand(void)
65 next *= 1103515245;
66 next += 12345;
67 return ((unsigned int) (next >> 16) & 0xFFFF);
71 void
72 gsrand(unsigned int seed)
74 next = seed;
78 #if ttblsz
79 struct hashentry *ttable[2];
80 unsigned int ttblsize;
81 #endif
83 #ifdef BINBOOK
84 extern char *binbookfile;
85 #endif
87 extern char *bookfile;
89 char savefile[128] = "";
90 char listfile[128] = "";
92 #if defined HISTORY
93 unsigned short *history;
94 #endif
96 short rpthash[2][256];
97 short TrPnt[MAXDEPTH];
98 small_short PieceList[2][NO_SQUARES];
99 small_short PawnCnt[2][NO_COLS];
100 small_short Captured[2][NO_PIECES];
101 small_short Mvboard[NO_SQUARES];
103 #if !defined SAVE_SVALUE
104 short svalue[NO_SQUARES];
105 #endif
107 struct flags flag;
109 short opponent, computer, WAwindow, WBwindow, BAwindow, BBwindow, dither,
110 INCscore;
111 long ResponseTime, ExtraTime, MaxResponseTime, et, et0, time0, ft;
112 long GenCnt, NodeCnt, ETnodes, EvalNodes, HashCnt,
113 HashAdd, FHashCnt, FHashAdd,
114 HashCol, THashCol, filesz, hashmask, hashbase;
115 long replus, reminus;
116 short HashDepth = HASHDEPTH, HashMoveLimit = HASHMOVELIMIT;
117 short player, xwndw;
118 /*unsigned*/ short rehash; /* -1 is used as a flag --tpm */
119 short Sdepth, Game50, MaxSearchDepth;
120 short GameCnt = 0;
121 short contempt;
122 int Book;
123 struct TimeControlRec TimeControl;
124 int TCadd = 0;
125 short TCflag, TCmoves, TCminutes, TCseconds, OperatorTime;
126 short XCmoves[3], XCminutes[3], XCseconds[3], XC, XCmore;
127 const short otherside[3] = { white, black, neutral };
128 unsigned short hint;
129 short TOflag; /* force search re-init if we backup search */
131 unsigned short killr0[MAXDEPTH], killr1[MAXDEPTH];
132 unsigned short killr2[MAXDEPTH], killr3[MAXDEPTH];
133 unsigned short PV, SwagHt, Swag0, Swag1, Swag2, Swag3, Swag4, sidebit;
135 small_short HasPiece[2][NO_PIECES];
136 const short kingP[3] = { 4, 76, 0 };
138 const long control[NO_PIECES] =
139 { 0, ctlP, ctlL, ctlN, ctlS, ctlG, ctlB, ctlR,
140 ctlPp, ctlLp, ctlNp, ctlSp, ctlBp, ctlRp, ctlK };
142 short stage, stage2;
144 FILE *hashfile;
146 unsigned int starttime;
147 short ahead = true, hash = true;
150 int timeopp[MINGAMEIN], timecomp[MINGAMEIN];
151 int compptr, oppptr;
153 void
154 TimeCalc()
156 /* adjust number of moves remaining in gamein games */
157 int increment = 0;
158 int topsum = 0;
159 int tcompsum = 0;
160 int me, him;
161 int i;
163 /* don't do anything til you have enough numbers */
164 if (GameCnt < (MINGAMEIN * 2))
165 return;
167 /* calculate average time in sec for last MINGAMEIN moves */
168 for (i = 0; i < MINGAMEIN; i++)
170 tcompsum += timecomp[i];
171 topsum += timeopp[i];
174 topsum /= (100 * MINGAMEIN);
175 tcompsum /= (100 * MINGAMEIN);
176 /* if I have less time than opponent add another move */
177 me = TimeControl.clock[computer] / 100;
178 him = TimeControl.clock[opponent] / 100;
180 if (me < him)
181 increment += 2;
183 if (((him - me) > 60) || ((me < him) && (me < 120)))
184 increment++;
186 /* if I am losing more time with each move add another */
187 /* if (!((me - him) > 60) && tcompsum > topsum) increment++; */
189 if (tcompsum > topsum)
191 increment += 2;
193 else if ((TimeControl.moves[computer] < MINMOVES) && !increment)
195 /* but don't let moves go below MINMOVES */
196 increment++;
198 else if ((me > him) && (tcompsum < topsum))
200 /* if I am doing really well use more time per move */
201 increment = -1;
204 TimeControl.moves[computer] += increment;
210 main(int argc, char **argv)
212 long l;
213 int n;
215 #if ttblsz
216 l = (long)sizeof(struct hashentry);
217 n = (int)((l * (ttblsz + rehash) * 2) / 1000);
218 printf("ttable:\t\t%4d\tkByte\t[hashentry:%ld "
219 "* (ttblsz:%d + rehash:%d) * 2]\n",
220 n, l, ttblsz, rehash);
221 #endif
223 #if defined CACHE
224 l = (long)sizeof(struct etable);
225 n = (int)((l * (size_t)ETABLE) / 1000);
226 #else
227 l = n = 0;
228 #endif
230 printf("etab:\t\t%4d\tkByte\t[etable:%ld ETABLE:%d]\n",
231 n, l, ETABLE);
233 l = (long)sizeof(struct leaf);
234 n = (int)(l * TREE / 1000);
235 printf("Tree:\t\t%4d\tkByte\t[leaf:%ld * TREE:%d]\n",
236 n, l, TREE);
238 #if defined HISTORY
239 n = (int)(sizeof_history / 1000);
240 #else
241 n = 0;
242 #endif
244 printf("history:\t%4d\tkByte\t[unsigned short:%d "
245 "* HISTORY_SIZE:%ld]\n",
246 n, sizeof(unsigned short), (long)HISTORY_SIZE);
248 #ifndef SAVE_NEXTPOS
249 l = (long)sizeof(next_array);
250 n = (int)((l * NO_PTYPE_PIECES) / 1000);
252 printf("nextpos:\t%4d\tkByte\t[next_array:%ld "
253 "* NO_PTYPE_PIECES:%d]\n",
254 n, l, NO_PTYPE_PIECES);
256 l = (long)sizeof(next_array);
257 n = (int)((l * NO_PTYPE_PIECES) / 1000);
258 printf("nextdir:\t%4d\tkByte\t[next_array:%ld "
259 "* NO_PTYPE_PIECES:%d]\n",
260 n, l, NO_PTYPE_PIECES);
261 #endif
263 #ifndef SAVE_DISTDATA
264 n = (int)(sizeof(distdata_array) / 1000);
265 printf("distdata:\t%4d\tkByte\n", n);
266 #endif
268 #ifndef SAVE_PTYPE_DISTDATA
269 l = (long)sizeof(distdata_array);
270 n = (int)((l * NO_PTYPE_PIECES) / 1000);
271 printf("ptype_distdata:\t%4d\tkByte\t[distdata_array:%ld "
272 "* NO_PTYPE_PIECES:%d]\n",
273 n, l, NO_PTYPE_PIECES);
274 #endif
276 l = (long)sizeof(hashcode_array);
277 n = (int)(l / 1000);
278 printf("hashcode:\t%4d\tkByte\t[hashval:%ld]\n",
279 n, (long)sizeof(struct hashval));
281 l = (long)sizeof(drop_hashcode_array);
282 n = (int)(l / 1000);
283 printf("drop_hashcode:\t%4d\tkByte\t[hashval:%ld]\n",
284 n, (long)sizeof(struct hashval));
286 l = (long)sizeof(value_array);
287 n = (int)(l / 1000);
288 printf("value:\t\t%4d\tkByte\n", n);
290 l = (long)sizeof(fscore_array);
291 n = (int)(l / 1000);
292 printf("fscore:\t\t%4d\tkByte\n", n);
294 return 0;