2 * backend.h -- Interface exported by XBoard back end
4 * Copyright 1991 by Digital Equipment Corporation, Maynard,
7 * Enhancements Copyright 1992-2001, 2002, 2003, 2004, 2005, 2006,
8 * 2007, 2008, 2009, 2010, 2011, 2012 Free Software Foundation, Inc.
10 * Enhancements Copyright 2005 Alessandro Scotti
12 * The following terms apply to Digital Equipment Corporation's copyright
14 * ------------------------------------------------------------------------
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.
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
32 * ------------------------------------------------------------------------
34 * The following terms apply to the enhanced version of XBoard
35 * distributed by the Free Software Foundation:
36 * ------------------------------------------------------------------------
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.
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.
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/. *
51 *------------------------------------------------------------------------
52 ** See the file ChangeLog for a revision history. */
57 /* unsigned int 64 for engine nodes work and display */
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
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)
72 * or dummy types for other compiler
73 * [HGM] seems that -mno-cygwin comple needs %I64?
75 #define u64 unsigned long long
76 #define s64 signed long long
78 #define u64Display "%I64u"
79 #define s64Display "%I64d"
81 #define u64Display "%llu"
82 #define s64Display "%lld"
84 #define u64Const(c) (c ## ULL)
85 #define s64Const(c) (c ## LL)
89 #define u64 unsigned long long
90 #define s64 signed long long
91 #define u64Display "%llu"
92 #define s64Display "%lld"
93 #define u64Const(c) (c ## ull)
94 #define s64Const(c) (c ## ll)
100 extern char *wbOptions;
101 extern int gotPremove;
102 extern GameMode gameMode;
103 extern int matchMode;
104 extern int matchGame;
105 extern int pausing, cmailMsgLoaded, flipView, mute;
106 extern char white_holding[], black_holding[];
107 extern int currentMove, backwardMostMove, forwardMostMove;
108 extern int blackPlaysFirst;
109 extern FILE *debugFP;
110 extern char* programVersion;
111 extern ProcRef firstProgramPR, secondProgramPR;
112 extern Board boards[];
113 extern char marker[BOARD_RANKS][BOARD_FILES];
114 extern char lastMsg[MSG_SIZ];
115 extern Boolean bookUp;
117 char *CmailMsg P((void));
118 /* Tord: Added the useFEN960 parameter in PositionToFEN() below */
119 char *PositionToFEN P((int move, char* useFEN960));
120 void AlphaRank P((char *s, int n)); /* [HGM] Shogi move preprocessor */
121 void EditPositionPasteFEN P((char *fen));
122 void TimeDelay P((long ms));
123 void SendMultiLineToICS P(( char *text ));
124 void AnalysisPeriodicEvent P((int force));
125 void SetWhiteToPlayEvent P((void));
126 void SetBlackToPlayEvent P((void));
127 void UploadGameEvent P((void));
128 void InitBackEnd1 P((void));
129 void InitBackEnd2 P((void));
130 int HasPromotionChoice P((int fromX, int fromY, int toX, int toY, char *choice, int sweep));
131 int InPalace P((int row, int column));
132 int PieceForSquare P((int x, int y));
133 int OKToStartUserMove P((int x, int y));
134 void Reset P((int redraw, int init));
135 void ResetGameEvent P((void));
136 Boolean HasPattern P(( const char * text, const char * pattern ));
137 Boolean SearchPattern P(( const char * text, const char * pattern ));
138 int LoadGame P((FILE *f, int n, char *title, int useList));
139 int LoadGameFromFile P((char *filename, int n, char *title, int useList));
140 int CmailLoadGame P((FILE *f, int n, char *title, int useList));
141 int ReloadGame P((int offset));
142 int SaveGame P((FILE *f, int dummy, char *dummy2));
143 int SaveGameToFile P((char *filename, int append));
144 int LoadPosition P((FILE *f, int n, char *title));
145 int ReloadPosition P((int offset));
146 int SavePosition P((FILE *f, int dummy, char *dummy2));
147 int DrawSeekGraph P(());
148 int SeekGraphClick P((ClickType click, int x, int y, int moving));
149 void EditPositionEvent P((void));
150 void FlipViewEvent P((void));
151 void MachineWhiteEvent P((void));
152 void MachineBlackEvent P((void));
153 void TwoMachinesEvent P((void));
154 void EditGameEvent P((void));
155 void TrainingEvent P((void));
156 void IcsClientEvent P((void));
157 void ForwardEvent P((void));
158 void BackwardEvent P((void));
159 void ToEndEvent P((void));
160 void ToStartEvent P((void));
161 void ToNrEvent P((int to));
162 void RevertEvent P((Boolean annotate));
163 void RetractMoveEvent P((void));
164 void MoveNowEvent P((void));
165 void TruncateGameEvent P((void));
166 void PauseEvent P((void));
167 void CallFlagEvent P((void));
168 void ClockClick P((int which));
169 void AcceptEvent P((void));
170 void DeclineEvent P((void));
171 void RematchEvent P((void));
172 void DrawEvent P((void));
173 void AbortEvent P((void));
174 void AdjournEvent P((void));
175 void ResignEvent P((void));
176 void UserAdjudicationEvent P((int result));
177 void StopObservingEvent P((void));
178 void StopExaminingEvent P((void));
179 void PonderNextMoveEvent P((int newState));
180 void ShowThinkingEvent P(());
181 void PeriodicUpdatesEvent P((int newState));
182 void HintEvent P((void));
183 void BookEvent P((void));
184 void AboutGameEvent P((void));
185 void ExitEvent P((int status));
186 char *DefaultFileName P((char *));
187 ChessMove UserMoveTest P((int fromX, int fromY, int toX, int toY, int promoChar, Boolean captureOwn));
188 void UserMoveEvent P((int fromX, int fromY, int toX, int toY, int promoChar));
189 void DecrementClocks P((void));
190 char *TimeString P((long millisec));
191 void AutoPlayGameLoop P((void));
192 void AdjustClock P((Boolean which, int dir));
193 void DisplayBothClocks P((void));
194 void EditPositionMenuEvent P((ChessSquare selection, int x, int y));
195 void DropMenuEvent P((ChessSquare selection, int x, int y));
196 int ParseTimeControl P((char *tc, float ti, int mps));
197 void EscapeExpand(char *p, char *q);
198 void ProcessICSInitScript P((FILE * f));
199 void EditCommentEvent P((void));
200 void ReplaceComment P((int index, char *text));
201 int ReplaceTags P((char *tags, GameInfo *gi));/* returns nonzero on error */
202 void AppendComment P((int index, char *text, Boolean addBraces));
203 void LoadVariation P((int index, char *text));
204 void ReloadCmailMsgEvent P((int unregister));
205 void MailMoveEvent P((void));
206 void EditTagsEvent P((void));
207 void GetMoveListEvent P((void));
208 void ExitAnalyzeMode P((void));
209 void AnalyzeModeEvent P((void));
210 void AnalyzeFileEvent P((void));
211 void MatchEvent P((int mode));
212 void RecentEngineEvent P((int nr));
213 void TypeInEvent P((char first));
214 void TypeInDoneEvent P((char *move));
215 void InitPosition P((int redraw));
216 void NewSettingEvent P((int option, int *feature, char *command, int value));
217 void SettingsMenuIfReady P((void));
218 void DoEcho P((void));
219 void DontEcho P((void));
220 void TidyProgramName P((char *prog, char *host, char *buf));
221 void SetGameInfo P((void));
222 void AskQuestionEvent P((char *title, char *question,
223 char *replyPrefix, char *which));
224 Boolean ParseOneMove P((char *move, int moveNum,
225 ChessMove *moveType, int *fromX, int *fromY,
226 int *toX, int *toY, char *promoChar));
227 char *VariantName P((VariantClass v));
228 VariantClass StringToVariant P((char *e));
229 double u64ToDouble P((u64 value));
230 void OutputChatMessage P((int partner, char *mess));
231 void EditPositionDone P((Boolean fakeRights));
232 Boolean GetArgValue P((char *name));
233 Boolean LoadPV P((int x, int y));
234 Boolean LoadMultiPV P((int x, int y, char *buf, int index, int *start, int *end));
236 void MovePV P((int x, int y, int h));
237 int PromoScroll P((int x, int y));
238 void EditBookEvent P((void));
239 Boolean DisplayBook P((int moveNr));
240 void SaveToBook P((char *text));
241 int PackGame P((Board board));
242 Boolean ParseFEN P((Board board, int *blackPlaysFirst, char *fen));
243 void ApplyMove P((int fromX, int fromY, int toX, int toY, int promoChar, Board board));
244 void PackMove P((int fromX, int fromY, int toX, int toY, ChessSquare promoPiece));
246 char *StrStr P((char *string, char *match));
247 char *StrCaseStr P((char *string, char *match));
248 char *StrSave P((char *s));
249 char *StrSavePtr P((char *s, char **savePtr));
250 char *SavePart P((char *));
251 char* safeStrCpy P(( char *dst, const char *src, size_t count ));
254 int StrCaseCmp P((char *s1, char *s2));
255 int ToLower P((int c));
256 int ToUpper P((int c));
258 #define StrCaseCmp Stricmp /* Use utility.library functions */
259 #include <proto/utility.h>
262 extern GameInfo gameInfo;
264 /* ICS vars used with backend.c and zippy.c */
265 #define ICS_GENERIC 0
268 #define ICS_CHESSNET 3 /* not really supported */
273 /* pgntags.c prototypes
275 char *PGNTags P((GameInfo *));
276 void PrintPGNTags P((FILE *f, GameInfo *));
277 int ParsePGNTag P((char *, GameInfo *));
278 char *PGNResult P((ChessMove result));
281 /* gamelist.c prototypes
283 /* A game node in the double linked list of games.
285 typedef struct _ListGame {
290 unsigned long offset; /* Byte offset of game within file. */
291 GameInfo gameInfo; /* Note that some entries may be NULL. */
294 extern int storedGames;
295 extern int opponentKibitzes;
296 extern ChessSquare gatingPiece;
297 extern List gameList;
298 extern int lastLoadGameNumber;
299 void ClearGameInfo P((GameInfo *));
300 int GameListBuild P((FILE *));
301 void GameListInitGameInfo P((GameInfo *));
302 char *GameListLine P((int, GameInfo *));
303 char * GameListLineFull P(( int, GameInfo *));
304 void InitSearch P((void));
305 int GameContainsPosition P((FILE *f, ListGame *lg));
306 void GLT_TagsToList P(( char * tags ));
307 void GLT_ParseList P((void));
308 int NamesToList P((char *name, char **engines, char **mnemonics, char *group));
309 int CreateTourney P((char *name));
310 char *MakeName P((char *templ));
311 void SwapEngines P((int n));
312 void Substitute P((char *participants, int expunge));
314 extern char* StripHighlight P((char *)); /* returns static data */
315 extern char* StripHighlightAndTitle P((char *)); /* returns static data */
316 extern void ics_update_width P((int new_width));
317 extern Boolean set_cont_sequence P((char *new_seq));
318 extern int wrap P((char *dest, char *src, int count, int width, int *lp));
319 int Explode P((Board board, int fromX, int fromY, int toX, int toY));
321 typedef enum { CheckBox, ComboBox, TextBox, Button, Spin, ResetButton, SaveButton, ListBox,
322 FileName, PathName, Slider, Message, Fractional, Label, Break, EndMark } Control;
324 /* Flags Option.min used for ComboBox: */
325 #define COMBO_CALLBACK (1 << 0)
326 #define NO_GETTEXT (1 << 1)
328 /* Flags for Option.min used for Button, SaveButton, EndMark: */
329 #define SAME_ROW (1 << 0)
330 #define NO_OK (1 << 1)
332 typedef struct _OPT { // [HGM] options: descriptor of UCI-style option
333 int value; // current setting, starts as default
334 int min; // Also used for flags
336 void *handle; // for use by front end
337 void *target; // for use by front end
338 char *textValue; // points to beginning of text value in name field
339 char **choice; // points to array of combo choices in cps->combo
341 char name[MSG_SIZ]; // holds both option name and text value
344 typedef struct _CPS {
349 char *twoMachinesColor; /* "white\n" or "black\n" */
355 char *computerString;
356 int sendTime; /* 0=don't, 1=do, 2=test */
360 int offeredDraw; /* countdown */
362 int useSetboard; /* 0=use "edit"; 1=use "setboard" */
363 int extendedEdit;/* 1=also set holdings with "edit" */
364 int useSAN; /* 0=use coordinate notation; 1=use SAN */
365 int usePing; /* 0=not OK to use ping; 1=OK */
368 int usePlayother;/* 0=not OK to use playother; 1=OK */
369 int useColors; /* 0=avoid obsolete white/black commands; 1=use them */
370 int useUsermove; /* 0=just send move; 1=send "usermove move" */
371 int sendICS; /* 0=don't use "ics" command; 1=do */
372 int sendName; /* 0=don't use "name" command; 1=do */
373 int sdKludge; /* 0=use "sd DEPTH" command; 1=use "depth\nDEPTH" */
374 int stKludge; /* 0=use "st TIME" command; 1=use "level 1 TIME" */
375 int excludeMoves;/* 0=don't use "exclude" command; 1=do */
378 char variants[MSG_SIZ];
385 int useFEN960; /* 0=use "KQkq" style FENs, 1=use "HAha" style FENs */
386 int useOOCastle; /* 0="O-O" notation for castling, 1="king capture rook" notation */
387 /* End of additions by Tord */
389 int scoreIsAbsolute; /* [AS] 0=don't know (standard), 1=score is always from white side */
390 int isUCI; /* [AS] 0=no (Winboard), 1=UCI (requires Polyglot) */
391 int hasOwnBookUCI; /* [AS] 0=use GUI or Polyglot book, 1=has own book */
393 /* [HGM] time odds */
394 float timeOdds; /* factor through which we divide time for this engine */
395 int debug; /* [HGM] ignore engine debug lines starting with '#' */
396 int maxNrOfSessions; /* [HGM] secondary TC: max args in 'level' command */
397 int accumulateTC; /* [HGM] secondary TC: how to handle extra sessions */
398 int nps; /* [HGM] nps: factor for node count to replace time */
400 int alphaRank; /* [HGM] shogi: engine uses shogi-type coordinates */
401 int maxCores; /* [HGM] SMP: engine understands cores command */
402 int memSize; /* [HGM] memsize: engine understands memory command */
403 char egtFormats[MSG_SIZ]; /* [HGM] EGT: supported tablebase formats */
404 int bookSuspend; /* [HGM] book: go was deferred because of book hit */
405 int nrOptions; /* [HGM] options: remembered option="..." features */
406 #define MAX_OPTIONS 200
407 Option option[MAX_OPTIONS];
409 char *comboList[20*MAX_OPTIONS];
410 char *optionSettings;
411 void *programLogo; /* [HGM] logo: bitmap of the logo */
412 char *fenOverride; /* [HGM} FRC: force FEN casling & ep fields by hand */
413 char userError; /* [HGM] crash: flag to suppress fatal-error messages*/
416 extern ChessProgramState first, second;
418 /* Search stats from chessprogram */
420 char movelist[2*MSG_SIZ]; /* Last PV we were sent */
421 int depth; /* Current search depth */
422 int nr_moves; /* Total nr of root moves */
423 int moves_left; /* Moves remaining to be searched */
424 char move_name[MOVE_LEN]; /* Current move being searched, if provided */
425 u64 nodes; /* # of nodes searched */
426 int time; /* Search time (centiseconds) */
427 int score; /* Score (centipawns) */
428 int got_only_move; /* If last msg was "(only move)" */
429 int got_fail; /* 0 - nothing, 1 - got "--", 2 - got "++" */
430 int ok_to_send; /* handshaking between send & recv */
431 int line_is_book; /* 1 if movelist is book moves */
432 int seen_stat; /* 1 if we've seen the stat01: line */
435 extern ChessProgramStats_Move pvInfoList[MAX_MOVES];
436 extern Boolean shuffleOpenings;
437 extern ChessProgramStats programStats;
438 extern int opponentKibitzes; // used by wengineo.c
439 extern int errorExitStatus;
440 extern char *recentEngines;
441 extern char *comboLine;
442 extern Boolean partnerUp, twoBoards;
443 void SettingsPopUp P((ChessProgramState *cps)); // [HGM] really in front-end, but CPS not known in frontend.h
444 int WaitForEngine P((ChessProgramState *cps, DelayedEventCallback x));
445 void Load P((ChessProgramState *cps, int n));
446 int MultiPV P((ChessProgramState *cps));
447 void MoveHistorySet P(( char movelist[][2*MOVE_LEN], int first, int last, int current, ChessProgramStats_Move * pvInfo ));
448 void EvalGraphSet P(( int first, int last, int current, ChessProgramStats_Move * pvInfo ));
449 void MakeEngineOutputTitle P((void));
451 /* A point in time */
453 long sec; /* Assuming this is >= 32 bits */
454 int ms; /* Assuming this is >= 16 bits */
457 void GetTimeMark P((TimeMark *));
458 long SubtractTimeMarks P((TimeMark *, TimeMark *));
460 #endif /* _BACKEND */