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