fadc9268bd57c561e911b0414421ef85ec4ffa2a
[xboard.git] / backend.h
1 /*
2  * backend.h -- Interface exported by XBoard back end
3  *
4  * Copyright 1991 by Digital Equipment Corporation, Maynard,
5  * Massachusetts.
6  *
7  * Enhancements Copyright 1992-2001, 2002, 2003, 2004, 2005, 2006,
8  * 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016 Free
9  * Software Foundation, Inc.
10  *
11  * Enhancements Copyright 2005 Alessandro Scotti
12  *
13  * The following terms apply to Digital Equipment Corporation's copyright
14  * interest in XBoard:
15  * ------------------------------------------------------------------------
16  * All Rights Reserved
17  *
18  * Permission to use, copy, modify, and distribute this software and its
19  * documentation for any purpose and without fee is hereby granted,
20  * provided that the above copyright notice appear in all copies and that
21  * both that copyright notice and this permission notice appear in
22  * supporting documentation, and that the name of Digital not be
23  * used in advertising or publicity pertaining to distribution of the
24  * software without specific, written prior permission.
25  *
26  * DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
27  * ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
28  * DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
29  * ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
30  * WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
31  * ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
32  * SOFTWARE.
33  * ------------------------------------------------------------------------
34  *
35  * The following terms apply to the enhanced version of XBoard
36  * distributed by the Free Software Foundation:
37  * ------------------------------------------------------------------------
38  *
39  * GNU XBoard is free software: you can redistribute it and/or modify
40  * it under the terms of the GNU General Public License as published by
41  * the Free Software Foundation, either version 3 of the License, or (at
42  * your option) any later version.
43  *
44  * GNU XBoard is distributed in the hope that it will be useful, but
45  * WITHOUT ANY WARRANTY; without even the implied warranty of
46  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
47  * General Public License for more details.
48  *
49  * You should have received a copy of the GNU General Public License
50  * along with this program. If not, see http://www.gnu.org/licenses/.  *
51  *
52  *------------------------------------------------------------------------
53  ** See the file ChangeLog for a revision history.  */
54
55 #ifndef XB_BACKEND
56 #define XB_BACKEND
57
58 #include "lists.h"
59
60 typedef int (*FileProc) P((FILE *f, int n, char *title));
61
62 extern char *wbOptions;
63 extern int gotPremove;
64 extern GameMode gameMode;
65 extern int matchMode;
66 extern int matchGame;
67 extern int pausing, cmailMsgLoaded, flipView, mute;
68 extern char white_holding[], black_holding[];
69 extern int currentMove, backwardMostMove, forwardMostMove;
70 extern int blackPlaysFirst;
71 extern FILE *debugFP;
72 extern char* programVersion;
73 extern Board boards[];
74 extern char marker[BOARD_RANKS][BOARD_FILES];
75 extern char lastMsg[MSG_SIZ];
76 extern Boolean bookUp;
77 extern Boolean addToBookFlag;
78 extern int tinyLayout, smallLayout;
79 extern Boolean mcMode;
80 extern int dragging;
81 extern char variantError[];
82 extern char lastTalker[];
83
84 void MarkMenuItem P((char *menuRef, int state));
85 char *CmailMsg P((void));
86 /* Tord: Added the useFEN960 parameter in PositionToFEN() below */
87 char *PositionToFEN P((int move, char* useFEN960, int moveCounts));
88 void AlphaRank P((char *s, int n)); /* [HGM] Shogi move preprocessor */
89 void EditPositionPasteFEN P((char *fen));
90 void TimeDelay P((long ms));
91 void SendMultiLineToICS P(( char *text ));
92 void AnalysisPeriodicEvent P((int force));
93 void SetWhiteToPlayEvent P((void));
94 void SetBlackToPlayEvent P((void));
95 void UploadGameEvent P((void));
96 void InitBackEnd1 P((void));
97 void InitBackEnd2 P((void));
98 int HasPromotionChoice P((int fromX, int fromY, int toX, int toY, char *choice, int sweep));
99 int InPalace P((int row, int column));
100 int PieceForSquare P((int x, int y));
101 int OKToStartUserMove P((int x, int y));
102 void Reset P((int redraw, int init));
103 void ResetGameEvent P((void));
104 Boolean HasPattern P(( const char * text, const char * pattern ));
105 Boolean SearchPattern P(( const char * text, const char * pattern ));
106 int LoadGame P((FILE *f, int n, char *title, int useList));
107 int LoadGameFromFile P((char *filename, int n, char *title, int useList));
108 int CmailLoadGame P((FILE *f, int n, char *title, int useList));
109 int ReloadGame P((int offset));
110 int SaveSelected P((FILE *f, int dummy, char *dummy2));
111 int SaveGame P((FILE *f, int dummy, char *dummy2));
112 int SaveGameToFile P((char *filename, int append));
113 int LoadPosition P((FILE *f, int n, char *title));
114 int ReloadPosition P((int offset));
115 int SavePosition P((FILE *f, int dummy, char *dummy2));
116 int DrawSeekGraph P(());
117 int SeekGraphClick P((ClickType click, int x, int y, int moving));
118 void EditPositionEvent P((void));
119 void FlipViewEvent P((void));
120 void MachineWhiteEvent P((void));
121 void MachineBlackEvent P((void));
122 void TwoMachinesEvent P((void));
123 void EditGameEvent P((void));
124 void TrainingEvent P((void));
125 void IcsClientEvent P((void));
126 void ForwardEvent P((void));
127 void BackwardEvent P((void));
128 void ToEndEvent P((void));
129 void ToStartEvent P((void));
130 void ToNrEvent P((int to));
131 void RevertEvent P((Boolean annotate));
132 void RetractMoveEvent P((void));
133 void MoveNowEvent P((void));
134 void TruncateGameEvent P((void));
135 void PauseEvent P((void));
136 void CallFlagEvent P((void));
137 void ClockClick P((int which));
138 void AcceptEvent P((void));
139 void DeclineEvent P((void));
140 void RematchEvent P((void));
141 void DrawEvent P((void));
142 void AbortEvent P((void));
143 void AdjournEvent P((void));
144 void ResignEvent P((void));
145 void UserAdjudicationEvent P((int result));
146 void StopObservingEvent P((void));
147 void StopExaminingEvent P((void));
148 void PonderNextMoveEvent P((int newState));
149 void ShowThinkingEvent P(());
150 void PeriodicUpdatesEvent P((int newState));
151 void HintEvent P((void));
152 void BookEvent P((void));
153 void AboutGameEvent P((void));
154 void ExitEvent P((int status));
155 char *DefaultFileName P((char *));
156 ChessMove UserMoveTest P((int fromX, int fromY, int toX, int toY, int promoChar, Boolean captureOwn));
157 void UserMoveEvent P((int fromX, int fromY, int toX, int toY, int promoChar));
158 void DecrementClocks P((void));
159 char *TimeString P((long millisec));
160 void AutoPlayGameLoop P((void));
161 void AdjustClock P((Boolean which, int dir));
162 void DisplayBothClocks P((void));
163 void EditPositionMenuEvent P((ChessSquare selection, int x, int y));
164 void DropMenuEvent P((ChessSquare selection, int x, int y));
165 int ParseTimeControl P((char *tc, float ti, int mps));
166 void EscapeExpand(char *p, char *q);
167 void ProcessICSInitScript P((FILE * f));
168 void EditCommentEvent P((void));
169 void ReplaceComment P((int index, char *text));
170 int ReplaceTags P((char *tags, GameInfo *gi));/* returns nonzero on error */
171 void AppendComment P((int index, char *text, Boolean addBraces));
172 void LoadVariation P((int index, char *text));
173 void ReloadCmailMsgEvent P((int unregister));
174 void MailMoveEvent P((void));
175 void EditTagsEvent P((void));
176 void GetMoveListEvent P((void));
177 void ExitAnalyzeMode P((void));
178 int  AnalyzeModeEvent P((void));
179 void AnalyzeFileEvent P((void));
180 void MatchEvent P((int mode));
181 void RecentEngineEvent P((int nr));
182 void TypeInEvent P((char first));
183 void TypeInDoneEvent P((char *move));
184 void InitPosition P((int redraw));
185 void NewSettingEvent P((int option, int *feature, char *command, int value));
186 void SettingsMenuIfReady P((void));
187 void DoEcho P((void));
188 void DontEcho P((void));
189 void TidyProgramName P((char *prog, char *host, char *buf));
190 void SetGameInfo P((void));
191 void AskQuestionEvent P((char *title, char *question,
192                          char *replyPrefix, char *which));
193 Boolean ParseOneMove P((char *move, int moveNum,
194                         ChessMove *moveType, int *fromX, int *fromY,
195                         int *toX, int *toY, char *promoChar));
196 char *VariantName P((VariantClass v));
197 VariantClass StringToVariant P((char *e));
198 double u64ToDouble P((u64 value));
199 void OutputChatMessage P((int partner, char *mess));
200 void EditPositionDone P((Boolean fakeRights));
201 Boolean GetArgValue P((char *name));
202 Boolean LoadPV P((int x, int y));
203 Boolean LoadMultiPV P((int x, int y, char *buf, int index, int *start, int *end, int pane));
204 void UnLoadPV P(());
205 void MovePV P((int x, int y, int h));
206 int PromoScroll P((int x, int y));
207 void EditBookEvent P((void));
208 Boolean DisplayBook P((int moveNr));
209 void SaveToBook P((char *text));
210 void AddBookMove P((char *text));
211 void PlayBookMove P((char *text, int index));
212 void HoverEvent P((int hiX, int hiY, int x, int y));
213 int PackGame P((Board board));
214 Boolean ParseFEN P((Board board, int *blackPlaysFirst, char *fen, Boolean autoSize));
215 void ApplyMove P((int fromX, int fromY, int toX, int toY, int promoChar, Board board));
216 void PackMove P((int fromX, int fromY, int toX, int toY, ChessSquare promoPiece));
217 void ics_printf P((char *format, ...));
218 int GetEngineLine P((char *nick, int engine));
219 void AddGameToBook P((int always));
220 void FlushBook P((void));
221 char PieceToChar P((ChessSquare p));
222 int LoadPieceDesc P((char *s));
223
224 char *StrStr P((char *string, char *match));
225 char *StrCaseStr P((char *string, char *match));
226 char *StrSave P((char *s));
227 char *StrSavePtr P((char *s, char **savePtr));
228 char *SavePart P((char *));
229 char* safeStrCpy P(( char *dst, const char *src, size_t count ));
230
231 #ifndef _amigados
232 int StrCaseCmp P((char *s1, char *s2));
233 int ToLower P((int c));
234 int ToUpper P((int c));
235 #else
236 #define StrCaseCmp Stricmp  /*  Use utility.library functions   */
237 #include <proto/utility.h>
238 #endif
239
240 extern GameInfo gameInfo;
241
242 /* ICS vars used with backend.c and zippy.c */
243 enum ICS_TYPE { ICS_GENERIC, ICS_ICC, ICS_FICS, ICS_CHESSNET /* not really supported */ };
244 enum ICS_TYPE ics_type;
245
246 /* pgntags.c prototypes
247  */
248 char *PGNTags P((GameInfo *));
249 void PrintPGNTags P((FILE *f, GameInfo *));
250 int ParsePGNTag P((char *, GameInfo *));
251 char *PGNResult P((ChessMove result));
252
253
254 /* gamelist.c prototypes
255  */
256 /* A game node in the double linked list of games.
257  */
258 typedef struct XB_ListGame {
259     ListNode node;
260     int number;
261     int position;
262     int moves;
263     unsigned long offset;   /*  Byte offset of game within file.     */
264     GameInfo gameInfo;      /*  Note that some entries may be NULL. */
265 } ListGame;
266
267 extern int border;
268 extern int doubleClick;
269 extern int storedGames;
270 extern int opponentKibitzes;
271 extern ChessSquare gatingPiece;
272 extern List gameList;
273 extern int lastLoadGameNumber;
274 void ClearGameInfo P((GameInfo *));
275 int GameListBuild P((FILE *));
276 void GameListInitGameInfo P((GameInfo *));
277 char *GameListLine P((int, GameInfo *));
278 char * GameListLineFull P(( int, GameInfo *));
279 void InitSearch P((void));
280 int GameContainsPosition P((FILE *f, ListGame *lg));
281 void GLT_TagsToList P(( char * tags ));
282 void GLT_ParseList P((void));
283 int NamesToList P((char *name, char **engines, char **mnemonics, char *group));
284 int CreateTourney P((char *name));
285 char *MakeName P((char *templ));
286 void SwapEngines P((int n));
287 void Substitute P((char *participants, int expunge));
288
289 extern char* StripHighlight P((char *));  /* returns static data */
290 extern char* StripHighlightAndTitle P((char *));  /* returns static data */
291 extern void ics_update_width P((int new_width));
292 extern Boolean set_cont_sequence P((char *new_seq));
293 extern int wrap P((char *dest, char *src, int count, int width, int *lp));
294 int Explode P((Board board, int fromX, int fromY, int toX, int toY));
295
296 typedef enum { CheckBox, ComboBox, TextBox, Button, Spin, ResetButton, SaveButton, ListBox, Graph, PopUp,
297                  FileName, PathName, Slider, Message, Fractional, Label, Icon,
298                  BoxBegin, BoxEnd, BarBegin, BarEnd, DropDown, Break, EndMark, Skip } Control;
299
300 typedef struct XB_OPT {   // [HGM] options: descriptor of UCI-style option
301     int value;          // current setting, starts as default
302     int min;            // Also used for flags
303     int max;
304     void *handle;       // for use by front end
305     void *target;       // for use by front end
306     char *textValue;    // points to beginning of text value in name field
307     char **choice;      // points to array of combo choices in cps->combo
308     Control type;
309     char *name;         // holds both option name and text value (in allocated memory)
310     char **font;
311 } Option;
312
313 typedef struct XB_CPS {
314     char *which;
315     int maybeThinking;
316     ProcRef pr;
317     InputSourceRef isr;
318     char *twoMachinesColor; /* "white\n" or "black\n" */
319     char *program;
320     char *host;
321     char *dir;
322     struct XB_CPS *other;
323     char *initString;
324     char *computerString;
325     int sendTime; /* 0=don't, 1=do, 2=test */
326     int sendDrawOffers;
327     int useSigint;
328     int useSigterm;
329     int offeredDraw; /* countdown */
330     int reuse;
331     int useSetboard; /* 0=use "edit"; 1=use "setboard" */
332     int extendedEdit;/* 1=also set holdings with "edit" */
333     int useSAN;      /* 0=use coordinate notation; 1=use SAN */
334     int usePing;     /* 0=not OK to use ping; 1=OK */
335     int lastPing;
336     int lastPong;
337     int usePlayother;/* 0=not OK to use playother; 1=OK */
338     int useColors;   /* 0=avoid obsolete white/black commands; 1=use them */
339     int useUsermove; /* 0=just send move; 1=send "usermove move" */
340     int sendICS;     /* 0=don't use "ics" command; 1=do */
341     int sendName;    /* 0=don't use "name" command; 1=do */
342     int sdKludge;    /* 0=use "sd DEPTH" command; 1=use "depth\nDEPTH" */
343     int stKludge;    /* 0=use "st TIME" command; 1=use "level 1 TIME" */
344     int excludeMoves;/* 0=don't use "exclude" command; 1=do */
345     char *tidy;
346     int matchWins;
347     char *variants;
348     int analysisSupport;
349     int analyzing;
350     int protocolVersion;
351     int initDone;
352     int pseudo;
353
354     /* Added by Tord: */
355     int useFEN960;   /* 0=use "KQkq" style FENs, 1=use "HAha" style FENs */
356     int useOOCastle; /* 0="O-O" notation for castling, 1="king capture rook" notation */
357     /* End of additions by Tord */
358
359     int scoreIsAbsolute; /* [AS] 0=don't know (standard), 1=score is always from white side */
360     int isUCI;           /* [AS] 0=no (Winboard), 1=UCI (requires Polyglot) */
361     int hasOwnBookUCI;   /* [AS] 0=use GUI or Polyglot book, 1=has own book */
362
363     /* [HGM] time odds */
364     float timeOdds; /* factor through which we divide time for this engine  */
365     int debug;      /* [HGM] ignore engine debug lines starting with '#'    */
366     int maxNrOfSessions; /* [HGM] secondary TC: max args in 'level' command */
367     int accumulateTC; /* [HGM] secondary TC: how to handle extra sessions   */
368     int drawDepth;    /* [HGM] egbb: search depth to play egbb draws        */
369     int nps;          /* [HGM] nps: factor for node count to replace time   */
370     int supportsNPS;
371     int alphaRank;    /* [HGM] shogi: engine uses shogi-type coordinates    */
372     int maxCores;     /* [HGM] SMP: engine understands cores command        */
373     int memSize;      /* [HGM] memsize: engine understands memory command   */
374     char *egtFormats; /* [HGM] EGT: supported tablebase formats             */
375     int bookSuspend;  /* [HGM] book: go was deferred because of book hit    */
376     int pause;        /* [HGM] pause: 1=supports it, 2=actually paused      */
377     int highlight;    /* [HGM] engine wants to get lift and put commands    */
378     int nrOptions;    /* [HGM] options: remembered option="..." features    */
379 #define MAX_OPTIONS 200
380     Option option[MAX_OPTIONS];
381     int comboCnt;
382     char *comboList[20*MAX_OPTIONS];
383     char *optionSettings;
384     void *programLogo; /* [HGM] logo: bitmap of the logo                    */
385     char *fenOverride; /* [HGM} FRC: force FEN casling & ep fields by hand  */
386     char userError;    /* [HGM] crash: flag to suppress fatal-error messages*/
387     char reload;       /* [HGM] options: flag to resend options with xreuse */
388 } ChessProgramState;
389
390 extern ChessProgramState first, second;
391
392 /* Search stats from chessprogram */
393 typedef struct {
394   char movelist[2*MSG_SIZ]; /* Last PV we were sent */
395   int depth;              /* Current search depth */
396   int nr_moves;           /* Total nr of root moves */
397   int moves_left;         /* Moves remaining to be searched */
398   char move_name[MOVE_LEN];  /* Current move being searched, if provided */
399   u64 nodes;    /* # of nodes searched */
400   int time;               /* Search time (centiseconds) */
401   int score;              /* Score (centipawns) */
402   int got_only_move;      /* If last msg was "(only move)" */
403   int got_fail;           /* 0 - nothing, 1 - got "--", 2 - got "++" */
404   int ok_to_send;         /* handshaking between send & recv */
405   int line_is_book;       /* 1 if movelist is book moves */
406   int seen_stat;          /* 1 if we've seen the stat01: line */
407 } ChessProgramStats;
408
409 extern ChessProgramStats_Move pvInfoList[MAX_MOVES];
410 extern Boolean shuffleOpenings;
411 extern ChessProgramStats programStats;
412 extern int opponentKibitzes; // used by wengineo.c
413 extern int errorExitStatus;
414 extern char *recentEngines;
415 extern char *comboLine;
416 extern Boolean partnerUp, twoBoards;
417 extern char engineVariant[];
418 char *EngineDefinedVariant P((ChessProgramState *cps, int n));
419 void SettingsPopUp P((ChessProgramState *cps)); // [HGM] really in front-end, but CPS not known in frontend.h
420 int WaitForEngine P((ChessProgramState *cps, DelayedEventCallback x));
421 void Load P((ChessProgramState *cps, int n));
422 int MultiPV P((ChessProgramState *cps, int kind));
423 void MoveHistorySet P(( char movelist[][2*MOVE_LEN], int first, int last, int current, ChessProgramStats_Move * pvInfo ));
424 void MakeEngineOutputTitle P((void));
425 void LoadTheme P((void));
426 void CreateBookEvent P((void));
427 char *SupportedVariant P((char *list, VariantClass v, int w, int h, int s, int proto, char *engine));
428 char *CollectPieceDescriptors P((void));
429 void RefreshSettingsDialog P((ChessProgramState *cps, int val));
430 void StartChessProgram P((ChessProgramState *cps));
431 void SendToICS P((char *s));
432 int PosFlags P((int n));
433
434
435 /* A point in time */
436 typedef struct {
437     long sec;  /* Assuming this is >= 32 bits */
438     int ms;    /* Assuming this is >= 16 bits */
439 } TimeMark;
440
441 extern TimeMark programStartTime;
442
443 void GetTimeMark P((TimeMark *));
444 long SubtractTimeMarks P((TimeMark *, TimeMark *));
445
446 #endif /* XB_BACKEND */