1 /*
2  * FILE: globals.c
3  *
4  * ----------------------------------------------------------------------
5  * Copyright (c) 1993, 1994, 1995 Matthias Mutz
6  * Copyright (c) 1999 Michael Vanier and the Free Software Foundation
7  * Copyright (c) 2008, 2013, 2014 Yann Dirson and the Free Software Foundation
8  *
9  * GNU SHOGI is based on GNU CHESS
10  *
11  * Copyright (c) 1988, 1989, 1990 John Stanback
12  * Copyright (c) 1992 Free Software Foundation
13  *
14  * This file is part of GNU SHOGI.
15  *
16  * GNU Shogi is free software; you can redistribute it and/or modify it
17  * under the terms of the GNU General Public License as published by the
18  * Free Software Foundation; either version 3 of the License,
19  * or (at your option) any later version.
20  *
21  * GNU Shogi is distributed in the hope that it will be useful, but WITHOUT
22  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
23  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
24  * for more details.
25  *
26  * You should have received a copy of the GNU General Public License along
27  * with GNU Shogi; see the file COPYING. If not, see
28  * <http://www.gnu.org/licenses/>.
29  * ----------------------------------------------------------------------
30  *
31  */
32 
33 #include "gnushogi.h"
34 
35 
36 short ahead = true, hash = true;
37 char  *xwin = 0;
38 char  *Lang = NULL;
39 
40 
41 short FROMsquare, TOsquare;
42 
43 small_short ChkFlag[MAXDEPTH], CptrFlag[MAXDEPTH], TesujiFlag[MAXDEPTH];
44 short Pscore[MAXDEPTH], Tscore[MAXDEPTH];
45 small_short Pindex[NO_SQUARES];
46 
47 short mtl[2], hung[2];
48 small_short PieceCnt[2];
49 
50 char ColorStr[2][10];
51 
52 long znodes;
53 
54 unsigned short MV[MAXDEPTH];
55 int MSCORE;
56 int mycnt1, mycnt2;
57 
58 
59 
60 #ifdef BINBOOK
61 extern char *binbookfile;
62 #endif
63 
64 extern char *bookfile;
65 
66 unsigned long hashkey, hashbd;
67 
68 char savefile[128];
69 char listfile[128];
70 
71 short rpthash[2][256];
72 short TrPnt[MAXDEPTH];
73 small_short PieceList[2][NO_SQUARES];
74 small_short PawnCnt[2][NO_COLS];
75 small_short Captured[2][NO_PIECES];
76 small_short Mvboard[NO_SQUARES];
77 
78 #if !defined SAVE_SVALUE
79 short svalue[NO_SQUARES];
80 #endif
81 
82 struct flags flag;
83 
84 short opponent, computer, WAwindow, WBwindow, BAwindow, BBwindow, dither,
85     INCscore = 0;
86 long ResponseTime = 0, ExtraTime = 0, MaxResponseTime = 0,
87     et = 0, et0 = 0, time0 = 0, ft = 0;
88 
89 #ifdef INTERRUPT_TEST
90 long it, itime0;
91 #endif
92 
93 long  GenCnt, NodeCnt, ETnodes, EvalNodes, HashCnt, HashAdd,
94     FHashCnt, FHashAdd, HashCol, THashCol, filesz, hashmask, hashbase;
95 long  replus, reminus;
96 short HashDepth = HASHDEPTH, HashMoveLimit = HASHMOVELIMIT;
97 short player, xwndw;
98 short rehash = -1;
99 short Sdepth, Game50, MaxSearchDepth;
100 short GameCnt = 0;
101 short contempt;
102 int   Book;
103 struct TimeControlRec TimeControl;
104 int   TCadd = 0;
105 short TCflag, TCmoves, TCminutes, TCseconds, OperatorTime;
106 short XCmoves[3]   = { 0, 0, 0 };
107 short XCminutes[3] = { 0, 0, 0 };
108 short XCseconds[3] = { 0, 0, 0 };
109 short XC = 0, XCmore = 0;
110 const short otherside[3] = { white, black, neutral };
111 unsigned short hint;
112 short TOflag;       /* force search re-init if we backup search */
113 
114 unsigned short killr0[MAXDEPTH], killr1[MAXDEPTH];
115 unsigned short killr2[MAXDEPTH], killr3[MAXDEPTH];
116 unsigned short PV, SwagHt, Swag0, Swag1, Swag2, Swag3, Swag4, sidebit;
117 
118 small_short HasPiece[2][NO_PIECES];
119 
120 const short kingP[3] =
121 { 4, 76, 0 };
122 
123 const small_short relative_value[NO_PIECES] =
124 { 0,  1,
125 #ifndef MINISHOGI
126   3,  4,
127 #endif
128   7,  9,  10,  12,
129   2,
130 #ifndef MINISHOGI
131   5,  6,
132 #endif
133 8, 11, 13,  14 };
134 
135 const long control[NO_PIECES] =
136 { 0,  ctlP,
137 #ifndef MINISHOGI
138   ctlL,  ctlN,
139 #endif
140   ctlS,  ctlG, ctlB, ctlR,
141   ctlPp,
142 #ifndef MINISHOGI
143   ctlLp, ctlNp,
144 #endif
145   ctlSp, ctlBp, ctlRp, ctlK };
146 
147 short stage, stage2;
148 short balance[2];
149 
150 #ifdef HASHFILE
151 FILE *hashfile;
152 #endif
153 
154 unsigned int starttime;
155 
156 int timeopp[MINGAMEIN], timecomp[MINGAMEIN];
157 int compptr, oppptr;
158 
159 
160 struct leaf  *Tree = NULL;
161 
162 hashcode_array       *hashcode      = NULL;
163 drop_hashcode_array  *drop_hashcode = NULL;
164 
165 struct leaf  *root = NULL;
166 
167 struct GameRec  *GameList = NULL;
168 
169 value_array   *value  = NULL;
170 fscore_array  *fscore = NULL;
171 
172 #ifndef SAVE_DISTDATA
173 short use_distdata = true;
174 distdata_array  *distdata = NULL;
175 #endif
176 
177 #ifndef SAVE_PTYPE_DISTDATA
178 short use_ptype_distdata = true;
179 distdata_array  *ptype_distdata[NO_PTYPE_PIECES];
180 #endif
181 
182 #if !defined SAVE_NEXTPOS
183 next_array  *nextdir[NO_PTYPE_PIECES];
184 next_array  *nextpos[NO_PTYPE_PIECES];
185 short use_nextpos = true;
186 #endif
187 
188 #if defined HISTORY
189 short use_history = true;
190 unsigned short  *history = NULL;
191 #endif
192 
193 #ifdef CACHE
194 short use_etable = true;
195 etable_field  *etab[2] = { NULL, NULL };
196 #endif
197 
198 #if ttblsz
199 short use_ttable = true;
200 unsigned int ttblsize = ttblsz;
201 struct hashentry  *ttable[2] = { NULL, NULL };
202 #endif
203 
204 char *DRAW;
205 char *DRAW_REPETITION = "Repetition";
206 char *DRAW_MAXMOVES = "Max Moves";
207 char *DRAW_JUSTDRAW = "Drawn game!";
208