Updated all files to GPL version 3.
[xboard.git] / backend.h
1 /*\r
2  * backend.h -- Interface exported by XBoard back end\r
3  * $Id: backend.h,v 2.1 2003/10/27 19:21:00 mann Exp $\r
4  *\r
5  * Copyright 1991 by Digital Equipment Corporation, Maynard,\r
6  * Massachusetts.  Enhancements Copyright\r
7  * 1992-2001,2002,2003,2004,2005,2006,2007,2008,2009 Free Software\r
8  * Foundation, Inc.\r
9  *\r
10  * The following terms apply to Digital Equipment Corporation's copyright\r
11  * interest in XBoard:\r
12  * ------------------------------------------------------------------------\r
13  * All Rights Reserved\r
14  *\r
15  * Permission to use, copy, modify, and distribute this software and its\r
16  * documentation for any purpose and without fee is hereby granted,\r
17  * provided that the above copyright notice appear in all copies and that\r
18  * both that copyright notice and this permission notice appear in\r
19  * supporting documentation, and that the name of Digital not be\r
20  * used in advertising or publicity pertaining to distribution of the\r
21  * software without specific, written prior permission.\r
22  *\r
23  * DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING\r
24  * ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL\r
25  * DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR\r
26  * ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,\r
27  * WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,\r
28  * ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS\r
29  * SOFTWARE.\r
30  * ------------------------------------------------------------------------\r
31  *\r
32  * The following terms apply to the enhanced version of XBoard\r
33  * distributed by the Free Software Foundation:\r
34  * ------------------------------------------------------------------------\r
35  *\r
36  * GNU XBoard is free software: you can redistribute it and/or modify\r
37  * it under the terms of the GNU General Public License as published by\r
38  * the Free Software Foundation, either version 3 of the License, or (at\r
39  * your option) any later version.\r
40  *\r
41  * GNU XBoard is distributed in the hope that it will be useful, but\r
42  * WITHOUT ANY WARRANTY; without even the implied warranty of\r
43  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\r
44  * General Public License for more details.\r
45  *\r
46  * You should have received a copy of the GNU General Public License\r
47  * along with this program. If not, see http://www.gnu.org/licenses/.  *\r
48  *\r
49  *------------------------------------------------------------------------\r
50  ** See the file ChangeLog for a revision history.  */\r
51 \r
52 #ifndef _BACKEND\r
53 #define _BACKEND\r
54 \r
55 /* unsigned int 64 for engine nodes work and display */\r
56 #ifdef WIN32\r
57        /* I don't know the name for this type of other compiler\r
58         * If it not work, just modify here\r
59         * This is for MS Visual Studio\r
60         */\r
61        #ifdef _MSC_VER\r
62                #define u64 unsigned __int64\r
63                #define s64 signed __int64\r
64                #define u64Display "%I64u"\r
65                #define s64Display "%I64d"\r
66                #define u64Const(c) (c ## UI64)\r
67                #define s64Const(c) (c ## I64)\r
68        #else\r
69                /* place holder\r
70                 * or dummy types for other compiler\r
71                 */\r
72                #define u64 unsigned long long\r
73                #define s64 signed long long\r
74                #define u64Display "%llu"\r
75                #define s64Display "%lld"\r
76                #define u64Const(c) (c ## ULL)\r
77                #define s64Const(c) (c ## LL)\r
78        #endif\r
79 #else\r
80        /* GNU gcc */\r
81        #define u64 unsigned long long\r
82        #define s64 signed long long\r
83        #define u64Display "%llu"\r
84        #define s64Display "%lld"\r
85        #define u64Const(c) (c ## ull)\r
86        #define s64Const(c) (c ## ll)\r
87 #endif\r
88 \r
89 #include "lists.h"\r
90 #include "frontend.h"\r
91 \r
92 extern int gotPremove;\r
93 extern GameMode gameMode;\r
94 extern int pausing, cmailMsgLoaded, flipView;\r
95 extern char white_holding[], black_holding[];\r
96 extern int currentMove, backwardMostMove, forwardMostMove;\r
97 extern int blackPlaysFirst;\r
98 extern FILE *debugFP;\r
99 extern char* programVersion;\r
100 extern ProcRef firstProgramPR, secondProgramPR;\r
101 extern Board boards[];\r
102 \r
103 char *CmailMsg P((void));\r
104 /* Tord: Added the useFEN960 parameter in PositionToFEN() below */\r
105 char *PositionToFEN P((int move, int useFEN960));\r
106 void AlphaRank P((char *s, int n)); /* [HGM] Shogi move preprocessor */\r
107 void EditPositionPasteFEN P((char *fen));\r
108 void TimeDelay P((long ms));\r
109 void SendMultiLineToICS P(( char *text ));\r
110 void AnalysisPeriodicEvent P((int force));\r
111 void SetWhiteToPlayEvent P((void));\r
112 void SetBlackToPlayEvent P((void));\r
113 void InitBackEnd1 P((void));\r
114 void InitBackEnd2 P((void));\r
115 int IsPromotion P((int fromX, int fromY, int toX, int toY));\r
116 int InPalace P((int row, int column));\r
117 int PieceForSquare P((int x, int y));\r
118 int OKToStartUserMove P((int x, int y));\r
119 void Reset P((int redraw, int init));\r
120 void ResetGameEvent P((void));\r
121 int LoadGame P((FILE *f, int n, char *title, int useList));\r
122 int LoadGameFromFile P((char *filename, int n, char *title, int useList));\r
123 int CmailLoadGame P((FILE *f, int n, char *title, int useList));\r
124 int ReloadGame P((int offset));\r
125 int SaveGame P((FILE *f, int dummy, char *dummy2));\r
126 int SaveGameToFile P((char *filename, int append));\r
127 int LoadPosition P((FILE *f, int n, char *title));\r
128 int ReloadPosition P((int offset));\r
129 int SavePosition P((FILE *f, int dummy, char *dummy2));\r
130 void EditPositionEvent P((void));\r
131 void FlipViewEvent P((void));\r
132 void MachineWhiteEvent P((void));\r
133 void MachineBlackEvent P((void));\r
134 void TwoMachinesEvent P((void));\r
135 void EditGameEvent P((void));\r
136 void TrainingEvent P((void));\r
137 void IcsClientEvent P((void));\r
138 void ForwardEvent P((void));\r
139 void BackwardEvent P((void));\r
140 void ToEndEvent P((void));\r
141 void ToStartEvent P((void));\r
142 void ToNrEvent P((int to));\r
143 void RevertEvent P((void));\r
144 void RetractMoveEvent P((void));\r
145 void MoveNowEvent P((void));\r
146 void TruncateGameEvent P((void));\r
147 void PauseEvent P((void));\r
148 void CallFlagEvent P((void));\r
149 void AcceptEvent P((void));\r
150 void DeclineEvent P((void));\r
151 void RematchEvent P((void));\r
152 void DrawEvent P((void));\r
153 void AbortEvent P((void));\r
154 void AdjournEvent P((void));\r
155 void ResignEvent P((void));\r
156 void UserAdjudicationEvent P((int result));\r
157 void StopObservingEvent P((void));\r
158 void StopExaminingEvent P((void));\r
159 void PonderNextMoveEvent P((int newState));\r
160 void NewSettingeEvent P((int option, char *command, int value));\r
161 void ShowThinkingEvent P(());\r
162 void PeriodicUpdatesEvent P((int newState));\r
163 void HintEvent P((void));\r
164 void BookEvent P((void));\r
165 void AboutGameEvent P((void));\r
166 void ExitEvent P((int status));\r
167 char *DefaultFileName P((char *));\r
168 ChessMove UserMoveTest P((int fromX, int fromY, int toX, int toY, int promoChar));\r
169 void UserMoveEvent P((int fromX, int fromY, int toX, int toY, int promoChar));\r
170 void DecrementClocks P((void));\r
171 char *TimeString P((long millisec));\r
172 void AutoPlayGameLoop P((void));\r
173 void AdjustClock P((Boolean which, int dir));\r
174 void DisplayBothClocks P((void));\r
175 void EditPositionMenuEvent P((ChessSquare selection, int x, int y));\r
176 void DropMenuEvent P((ChessSquare selection, int x, int y));\r
177 int ParseTimeControl P((char *tc, int ti, int mps));\r
178 void ProcessICSInitScript P((FILE * f));\r
179 void EditCommentEvent P((void));\r
180 void ReplaceComment P((int index, char *text));\r
181 int ReplaceTags P((char *tags, GameInfo *gi));/* returns nonzero on error */\r
182 void AppendComment P((int index, char *text));\r
183 void ReloadCmailMsgEvent P((int unregister));\r
184 void MailMoveEvent P((void));\r
185 void EditTagsEvent P((void));\r
186 void GetMoveListEvent P((void));\r
187 void ExitAnalyzeMode P((void));\r
188 void AnalyzeModeEvent P((void));\r
189 void AnalyzeFileEvent P((void));\r
190 void DoEcho P((void));\r
191 void DontEcho P((void));\r
192 void TidyProgramName P((char *prog, char *host, char *buf));\r
193 void AskQuestionEvent P((char *title, char *question,\r
194                          char *replyPrefix, char *which));\r
195 Boolean ParseOneMove P((char *move, int moveNum,\r
196                         ChessMove *moveType, int *fromX, int *fromY,\r
197                         int *toX, int *toY, char *promoChar));\r
198 char *VariantName P((VariantClass v));\r
199 VariantClass StringToVariant P((char *e));\r
200 double u64ToDouble P((u64 value));\r
201 \r
202 char *StrStr P((char *string, char *match));\r
203 char *StrCaseStr P((char *string, char *match));\r
204 char *StrSave P((char *s));\r
205 char *StrSavePtr P((char *s, char **savePtr));\r
206 \r
207 #ifndef _amigados\r
208 int StrCaseCmp P((char *s1, char *s2));\r
209 int ToLower P((int c));\r
210 int ToUpper P((int c));\r
211 #else\r
212 #define StrCaseCmp Stricmp  /*  Use utility.library functions   */\r
213 #include <proto/utility.h>\r
214 #endif\r
215 \r
216 extern GameInfo gameInfo;\r
217 \r
218 /* ICS vars used with backend.c and zippy.c */\r
219 #define ICS_GENERIC 0\r
220 #define ICS_ICC 1\r
221 #define ICS_FICS 2\r
222 #define ICS_CHESSNET 3 /* not really supported */\r
223 int ics_type;\r
224 \r
225  \r
226 \r
227 /* pgntags.c prototypes\r
228  */\r
229 char *PGNTags P((GameInfo *));\r
230 void PrintPGNTags P((FILE *f, GameInfo *));\r
231 int ParsePGNTag P((char *, GameInfo *));\r
232 char *PGNResult P((ChessMove result));\r
233 \r
234 \r
235 /* gamelist.c prototypes\r
236  */\r
237 /* A game node in the double linked list of games.\r
238  */\r
239 typedef struct _ListGame {\r
240     ListNode node;\r
241     int number;\r
242     unsigned long offset;   /*  Byte offset of game within file.     */\r
243     GameInfo gameInfo;      /*  Note that some entries may be NULL. */\r
244 } ListGame;\r
245  \r
246 extern List gameList;\r
247 void ClearGameInfo P((GameInfo *));\r
248 int GameListBuild P((FILE *));\r
249 void GameListInitGameInfo P((GameInfo *));\r
250 char *GameListLine P((int, GameInfo *));\r
251 char * GameListLineFull P(( int, GameInfo *));\r
252 \r
253 extern char* StripHighlight P((char *));  /* returns static data */\r
254 extern char* StripHighlightAndTitle P((char *));  /* returns static data */\r
255 \r
256 typedef enum { CheckBox, ComboBox, TextBox, Button, Spin, SaveButton } Control;\r
257 \r
258 typedef struct _OPT {   // [HGM] options: descriptor of UCI-style option\r
259     int value;          // current setting, starts as default\r
260     int min;\r
261     int max;\r
262     void *handle;       // for use by front end\r
263     char *textValue;    // points to beginning of text value in name field\r
264     char **choice;      // points to array of combo choices in cps->combo\r
265     Control type;\r
266     char name[MSG_SIZ]; // holds both option name and text value\r
267 } Option;\r
268 \r
269 typedef struct _CPS {\r
270     char *which;\r
271     int maybeThinking;\r
272     ProcRef pr;\r
273     InputSourceRef isr;\r
274     char *twoMachinesColor; /* "white\n" or "black\n" */\r
275     char *program;\r
276     char *host;\r
277     char *dir;\r
278     struct _CPS *other;\r
279     char *initString;\r
280     char *computerString;\r
281     int sendTime; /* 0=don't, 1=do, 2=test */\r
282     int sendDrawOffers;\r
283     int useSigint;\r
284     int useSigterm;\r
285     int offeredDraw; /* countdown */\r
286     int reuse;\r
287     int useSetboard; /* 0=use "edit"; 1=use "setboard" */\r
288     int useSAN;      /* 0=use coordinate notation; 1=use SAN */\r
289     int usePing;     /* 0=not OK to use ping; 1=OK */\r
290     int lastPing;\r
291     int lastPong;\r
292     int usePlayother;/* 0=not OK to use playother; 1=OK */\r
293     int useColors;   /* 0=avoid obsolete white/black commands; 1=use them */\r
294     int useUsermove; /* 0=just send move; 1=send "usermove move" */\r
295     int sendICS;     /* 0=don't use "ics" command; 1=do */\r
296     int sendName;    /* 0=don't use "name" command; 1=do */\r
297     int sdKludge;    /* 0=use "sd DEPTH" command; 1=use "depth\nDEPTH" */\r
298     int stKludge;    /* 0=use "st TIME" command; 1=use "level 1 TIME" */\r
299     char tidy[MSG_SIZ];\r
300     int matchWins;\r
301     char variants[MSG_SIZ];\r
302     int analysisSupport;\r
303     int analyzing;\r
304     int protocolVersion;\r
305     int initDone;\r
306 \r
307     /* Added by Tord: */\r
308     int useFEN960;   /* 0=use "KQkq" style FENs, 1=use "HAha" style FENs */\r
309     int useOOCastle; /* 0="O-O" notation for castling, 1="king capture rook" notation */\r
310     /* End of additions by Tord */\r
311 \r
312     int scoreIsAbsolute; /* [AS] 0=don't know (standard), 1=score is always from white side */\r
313     int isUCI;           /* [AS] 0=no (Winboard), 1=UCI (requires Polyglot) */\r
314     int hasOwnBookUCI;   /* [AS] 0=use GUI or Polyglot book, 1=has own book */\r
315 \r
316     /* [HGM] time odds */\r
317     int timeOdds;   /* factor through which we divide time for this engine  */\r
318     int debug;      /* [HGM] ignore engine debug lines starting with '#'    */\r
319     int maxNrOfSessions; /* [HGM] secondary TC: max args in 'level' command */\r
320     int accumulateTC; /* [HGM] secondary TC: how to handle extra sessions   */\r
321     int nps;          /* [HGM] nps: factor for node count to replace time   */\r
322     int supportsNPS;\r
323     int alphaRank;    /* [HGM] shogi: engine uses shogi-type coordinates    */\r
324     int maxCores;     /* [HGM] SMP: engine understands cores command        */\r
325     int memSize;      /* [HGM] memsize: engine understands memory command   */\r
326     char egtFormats[MSG_SIZ];     /* [HGM] EGT: supported tablebase formats */\r
327     int bookSuspend;  /* [HGM] book: go was deferred because of book hit    */\r
328     int nrOptions;    /* [HGM] options: remembered option="..." features    */\r
329 #define MAX_OPTIONS 50\r
330     Option option[MAX_OPTIONS];\r
331     int comboCnt;\r
332     char *comboList[10*MAX_OPTIONS];\r
333     char *optionSettings;\r
334     void *programLogo; /* [HGM] logo: bitmap of the logo                    */\r
335 } ChessProgramState;\r
336 \r
337 extern ChessProgramState first, second;\r
338 \r
339 /* [AS] Search stats from chessprogram, for the played move */\r
340 typedef struct {\r
341     int score;  /* Centipawns */\r
342     int depth;  /* Plies */\r
343     int time;   /* Milliseconds */\r
344 } ChessProgramStats_Move;\r
345 \r
346 /* Search stats from chessprogram */\r
347 typedef struct {\r
348   char movelist[2*MSG_SIZ]; /* Last PV we were sent */\r
349   int depth;              /* Current search depth */\r
350   int nr_moves;           /* Total nr of root moves */\r
351   int moves_left;         /* Moves remaining to be searched */\r
352   char move_name[MOVE_LEN];  /* Current move being searched, if provided */\r
353   u64 nodes;    /* # of nodes searched */\r
354   int time;               /* Search time (centiseconds) */\r
355   int score;              /* Score (centipawns) */\r
356   int got_only_move;      /* If last msg was "(only move)" */\r
357   int got_fail;           /* 0 - nothing, 1 - got "--", 2 - got "++" */\r
358   int ok_to_send;         /* handshaking between send & recv */\r
359   int line_is_book;       /* 1 if movelist is book moves */\r
360   int seen_stat;          /* 1 if we've seen the stat01: line */\r
361 } ChessProgramStats;\r
362 \r
363 extern ChessProgramStats_Move pvInfoList[MAX_MOVES];\r
364 extern shuffleOpenings;\r
365 extern ChessProgramStats programStats;\r
366 \r
367 #endif /* _BACKEND */\r