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
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 * ----------------------------------------------------------------------
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
;
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;
67 return ((unsigned int) (next
>> 16) & 0xFFFF);
72 gsrand(unsigned int seed
)
79 struct hashentry
*ttable
[2];
80 unsigned int ttblsize
;
84 extern char *binbookfile
;
87 extern char *bookfile
;
89 char savefile
[128] = "";
90 char listfile
[128] = "";
93 unsigned short *history
;
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
];
109 short opponent
, computer
, WAwindow
, WBwindow
, BAwindow
, BBwindow
, dither
,
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
;
118 /*unsigned*/ short rehash
; /* -1 is used as a flag --tpm */
119 short Sdepth
, Game50
, MaxSearchDepth
;
123 struct TimeControlRec TimeControl
;
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
};
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
};
146 unsigned int starttime
;
147 short ahead
= true, hash
= true;
150 int timeopp
[MINGAMEIN
], timecomp
[MINGAMEIN
];
156 /* adjust number of moves remaining in gamein games */
163 /* don't do anything til you have enough numbers */
164 if (GameCnt
< (MINGAMEIN
* 2))
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;
183 if (((him
- me
) > 60) || ((me
< him
) && (me
< 120)))
186 /* if I am losing more time with each move add another */
187 /* if (!((me - him) > 60) && tcompsum > topsum) increment++; */
189 if (tcompsum
> topsum
)
193 else if ((TimeControl
.moves
[computer
] < MINMOVES
) && !increment
)
195 /* but don't let moves go below MINMOVES */
198 else if ((me
> him
) && (tcompsum
< topsum
))
200 /* if I am doing really well use more time per move */
204 TimeControl
.moves
[computer
] += increment
;
210 main(int argc
, char **argv
)
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
);
224 l
= (long)sizeof(struct etable
);
225 n
= (int)((l
* (size_t)ETABLE
) / 1000);
230 printf("etab:\t\t%4d\tkByte\t[etable:%ld ETABLE:%d]\n",
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",
239 n
= (int)(sizeof_history
/ 1000);
244 printf("history:\t%4d\tkByte\t[unsigned short:%d "
245 "* HISTORY_SIZE:%ld]\n",
246 n
, sizeof(unsigned short), (long)HISTORY_SIZE
);
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
);
263 #ifndef SAVE_DISTDATA
264 n
= (int)(sizeof(distdata_array
) / 1000);
265 printf("distdata:\t%4d\tkByte\n", n
);
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
);
276 l
= (long)sizeof(hashcode_array
);
278 printf("hashcode:\t%4d\tkByte\t[hashval:%ld]\n",
279 n
, (long)sizeof(struct hashval
));
281 l
= (long)sizeof(drop_hashcode_array
);
283 printf("drop_hashcode:\t%4d\tkByte\t[hashval:%ld]\n",
284 n
, (long)sizeof(struct hashval
));
286 l
= (long)sizeof(value_array
);
288 printf("value:\t\t%4d\tkByte\n", n
);
290 l
= (long)sizeof(fscore_array
);
292 printf("fscore:\t\t%4d\tkByte\n", n
);