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
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 * ----------------------------------------------------------------------
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;
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;
70 return ((unsigned int) (next >> 16) & 0xFFFF);
75 gsrand(unsigned int seed)
82 struct hashentry *ttable[2];
83 unsigned int ttblsize;
87 extern char *binbookfile;
90 extern char *bookfile;
92 char savefile[128] = "";
93 char listfile[128] = "";
96 unsigned short *history;
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];
112 short opponent, computer, WAwindow, WBwindow, BAwindow, BBwindow, dither,
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;
121 /*unsigned*/ short rehash; /* -1 is used as a flag --tpm */
122 short Sdepth, Game50, MaxSearchDepth;
126 struct TimeControlRec TimeControl;
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 };
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 };
149 unsigned int starttime;
150 short ahead = true, hash = true;
153 int timeopp[MINGAMEIN], timecomp[MINGAMEIN];
159 /* adjust number of moves remaining in gamein games */
166 /* don't do anything til you have enough numbers */
167 if (GameCnt < (MINGAMEIN * 2))
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;
186 if (((him - me) > 60) || ((me < him) && (me < 120)))
189 /* if I am losing more time with each move add another */
190 /* if (!((me - him) > 60) && tcompsum > topsum) increment++; */
192 if (tcompsum > topsum)
196 else if ((TimeControl.moves[computer] < MINMOVES) && !increment)
198 /* but don't let moves go below MINMOVES */
201 else if ((me > him) && (tcompsum < topsum))
203 /* if I am doing really well use more time per move */
207 TimeControl.moves[computer] += increment;
213 main(int argc, char **argv)
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);
227 l = (long)sizeof(struct etable);
228 n = (int)((l * (size_t)ETABLE) / 1000);
233 printf("etab:\t\t%4d\tkByte\t[etable:%ld ETABLE:%d]\n",
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",
242 n = (int)(sizeof_history / 1000);
247 printf("history:\t%4d\tkByte\t[unsigned short:%lu "
248 "* HISTORY_SIZE:%ld]\n",
249 n, sizeof(unsigned short), (long)HISTORY_SIZE);
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);
266 #ifndef SAVE_DISTDATA
267 n = (int)(sizeof(distdata_array) / 1000);
268 printf("distdata:\t%4d\tkByte\n", n);
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);
279 l = (long)sizeof(hashcode_array);
281 printf("hashcode:\t%4d\tkByte\t[hashval:%ld]\n",
282 n, (long)sizeof(struct hashval));
284 l = (long)sizeof(drop_hashcode_array);
286 printf("drop_hashcode:\t%4d\tkByte\t[hashval:%ld]\n",
287 n, (long)sizeof(struct hashval));
289 l = (long)sizeof(value_array);
291 printf("value:\t\t%4d\tkByte\n", n);
293 l = (long)sizeof(fscore_array);
295 printf("fscore:\t\t%4d\tkByte\n", n);