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