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