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, 2013 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. */
59 typedef int (*FileProc) P((FILE *f, int n, char *title));
61 extern char *wbOptions;
62 extern int gotPremove;
63 extern GameMode gameMode;
66 extern int pausing, cmailMsgLoaded, flipView, mute;
67 extern char white_holding[], black_holding[];
68 extern int currentMove, backwardMostMove, forwardMostMove;
69 extern int blackPlaysFirst;
71 extern char* programVersion;
72 extern Board boards[];
73 extern char marker[BOARD_RANKS][BOARD_FILES];
74 extern char lastMsg[MSG_SIZ];
75 extern Boolean bookUp;
76 extern int tinyLayout, smallLayout;
77 extern Boolean mcMode;
79 void MarkMenuItem P((char *menuRef, int state));
80 char *CmailMsg P((void));
81 /* Tord: Added the useFEN960 parameter in PositionToFEN() below */
82 char *PositionToFEN P((int move, char* useFEN960));
83 void AlphaRank P((char *s, int n)); /* [HGM] Shogi move preprocessor */
84 void EditPositionPasteFEN P((char *fen));
85 void TimeDelay P((long ms));
86 void SendMultiLineToICS P(( char *text ));
87 void AnalysisPeriodicEvent P((int force));
88 void SetWhiteToPlayEvent P((void));
89 void SetBlackToPlayEvent P((void));
90 void UploadGameEvent P((void));
91 void InitBackEnd1 P((void));
92 void InitBackEnd2 P((void));
93 int HasPromotionChoice P((int fromX, int fromY, int toX, int toY, char *choice, int sweep));
94 int InPalace P((int row, int column));
95 int PieceForSquare P((int x, int y));
96 int OKToStartUserMove P((int x, int y));
97 void Reset P((int redraw, int init));
98 void ResetGameEvent P((void));
99 Boolean HasPattern P(( const char * text, const char * pattern ));
100 Boolean SearchPattern P(( const char * text, const char * pattern ));
101 int LoadGame P((FILE *f, int n, char *title, int useList));
102 int LoadGameFromFile P((char *filename, int n, char *title, int useList));
103 int CmailLoadGame P((FILE *f, int n, char *title, int useList));
104 int ReloadGame P((int offset));
105 int SaveGame P((FILE *f, int dummy, char *dummy2));
106 int SaveGameToFile P((char *filename, int append));
107 int LoadPosition P((FILE *f, int n, char *title));
108 int ReloadPosition P((int offset));
109 int SavePosition P((FILE *f, int dummy, char *dummy2));
110 int DrawSeekGraph P(());
111 int SeekGraphClick P((ClickType click, int x, int y, int moving));
112 void EditPositionEvent P((void));
113 void FlipViewEvent P((void));
114 void MachineWhiteEvent P((void));
115 void MachineBlackEvent P((void));
116 void TwoMachinesEvent P((void));
117 void EditGameEvent P((void));
118 void TrainingEvent P((void));
119 void IcsClientEvent P((void));
120 void ForwardEvent P((void));
121 void BackwardEvent P((void));
122 void ToEndEvent P((void));
123 void ToStartEvent P((void));
124 void ToNrEvent P((int to));
125 void RevertEvent P((Boolean annotate));
126 void RetractMoveEvent P((void));
127 void MoveNowEvent P((void));
128 void TruncateGameEvent P((void));
129 void PauseEvent P((void));
130 void CallFlagEvent P((void));
131 void ClockClick P((int which));
132 void AcceptEvent P((void));
133 void DeclineEvent P((void));
134 void RematchEvent P((void));
135 void DrawEvent P((void));
136 void AbortEvent P((void));
137 void AdjournEvent P((void));
138 void ResignEvent P((void));
139 void UserAdjudicationEvent P((int result));
140 void StopObservingEvent P((void));
141 void StopExaminingEvent P((void));
142 void PonderNextMoveEvent P((int newState));
143 void ShowThinkingEvent P(());
144 void PeriodicUpdatesEvent P((int newState));
145 void HintEvent P((void));
146 void BookEvent P((void));
147 void AboutGameEvent P((void));
148 void ExitEvent P((int status));
149 char *DefaultFileName P((char *));
150 ChessMove UserMoveTest P((int fromX, int fromY, int toX, int toY, int promoChar, Boolean captureOwn));
151 void UserMoveEvent P((int fromX, int fromY, int toX, int toY, int promoChar));
152 void DecrementClocks P((void));
153 char *TimeString P((long millisec));
154 void AutoPlayGameLoop P((void));
155 void AdjustClock P((Boolean which, int dir));
156 void DisplayBothClocks P((void));
157 void EditPositionMenuEvent P((ChessSquare selection, int x, int y));
158 void DropMenuEvent P((ChessSquare selection, int x, int y));
159 int ParseTimeControl P((char *tc, float ti, int mps));
160 void EscapeExpand(char *p, char *q);
161 void ProcessICSInitScript P((FILE * f));
162 void EditCommentEvent P((void));
163 void ReplaceComment P((int index, char *text));
164 int ReplaceTags P((char *tags, GameInfo *gi));/* returns nonzero on error */
165 void AppendComment P((int index, char *text, Boolean addBraces));
166 void LoadVariation P((int index, char *text));
167 void ReloadCmailMsgEvent P((int unregister));
168 void MailMoveEvent P((void));
169 void EditTagsEvent P((void));
170 void GetMoveListEvent P((void));
171 void ExitAnalyzeMode P((void));
172 int AnalyzeModeEvent P((void));
173 void AnalyzeFileEvent P((void));
174 void MatchEvent P((int mode));
175 void RecentEngineEvent P((int nr));
176 void TypeInEvent P((char first));
177 void TypeInDoneEvent P((char *move));
178 void InitPosition P((int redraw));
179 void NewSettingEvent P((int option, int *feature, char *command, int value));
180 void SettingsMenuIfReady P((void));
181 void DoEcho P((void));
182 void DontEcho P((void));
183 void TidyProgramName P((char *prog, char *host, char *buf));
184 void SetGameInfo P((void));
185 void AskQuestionEvent P((char *title, char *question,
186 char *replyPrefix, char *which));
187 Boolean ParseOneMove P((char *move, int moveNum,
188 ChessMove *moveType, int *fromX, int *fromY,
189 int *toX, int *toY, char *promoChar));
190 char *VariantName P((VariantClass v));
191 VariantClass StringToVariant P((char *e));
192 double u64ToDouble P((u64 value));
193 void OutputChatMessage P((int partner, char *mess));
194 void EditPositionDone P((Boolean fakeRights));
195 Boolean GetArgValue P((char *name));
196 Boolean LoadPV P((int x, int y));
197 Boolean LoadMultiPV P((int x, int y, char *buf, int index, int *start, int *end, int pane));
199 void MovePV P((int x, int y, int h));
200 int PromoScroll P((int x, int y));
201 void EditBookEvent P((void));
202 Boolean DisplayBook P((int moveNr));
203 void SaveToBook P((char *text));
204 int PackGame P((Board board));
205 Boolean ParseFEN P((Board board, int *blackPlaysFirst, char *fen));
206 void ApplyMove P((int fromX, int fromY, int toX, int toY, int promoChar, Board board));
207 void PackMove P((int fromX, int fromY, int toX, int toY, ChessSquare promoPiece));
208 void ics_printf P((char *format, ...));
209 int GetEngineLine P((char *nick, int engine));
210 void AddGameToBook P((int always));
211 void FlushBook P((void));
213 char *StrStr P((char *string, char *match));
214 char *StrCaseStr P((char *string, char *match));
215 char *StrSave P((char *s));
216 char *StrSavePtr P((char *s, char **savePtr));
217 char *SavePart P((char *));
218 char* safeStrCpy P(( char *dst, const char *src, size_t count ));
221 int StrCaseCmp P((char *s1, char *s2));
222 int ToLower P((int c));
223 int ToUpper P((int c));
225 #define StrCaseCmp Stricmp /* Use utility.library functions */
226 #include <proto/utility.h>
229 extern GameInfo gameInfo;
231 /* ICS vars used with backend.c and zippy.c */
232 enum ICS_TYPE { ICS_GENERIC, ICS_ICC, ICS_FICS, ICS_CHESSNET /* not really supported */ };
233 enum ICS_TYPE ics_type;
235 /* pgntags.c prototypes
237 char *PGNTags P((GameInfo *));
238 void PrintPGNTags P((FILE *f, GameInfo *));
239 int ParsePGNTag P((char *, GameInfo *));
240 char *PGNResult P((ChessMove result));
243 /* gamelist.c prototypes
245 /* A game node in the double linked list of games.
247 typedef struct XB_ListGame {
252 unsigned long offset; /* Byte offset of game within file. */
253 GameInfo gameInfo; /* Note that some entries may be NULL. */
256 extern int doubleClick;
257 extern int storedGames;
258 extern int opponentKibitzes;
259 extern ChessSquare gatingPiece;
260 extern List gameList;
261 extern int lastLoadGameNumber;
262 void ClearGameInfo P((GameInfo *));
263 int GameListBuild P((FILE *));
264 void GameListInitGameInfo P((GameInfo *));
265 char *GameListLine P((int, GameInfo *));
266 char * GameListLineFull P(( int, GameInfo *));
267 void InitSearch P((void));
268 int GameContainsPosition P((FILE *f, ListGame *lg));
269 void GLT_TagsToList P(( char * tags ));
270 void GLT_ParseList P((void));
271 int NamesToList P((char *name, char **engines, char **mnemonics, char *group));
272 int CreateTourney P((char *name));
273 char *MakeName P((char *templ));
274 void SwapEngines P((int n));
275 void Substitute P((char *participants, int expunge));
277 extern char* StripHighlight P((char *)); /* returns static data */
278 extern char* StripHighlightAndTitle P((char *)); /* returns static data */
279 extern void ics_update_width P((int new_width));
280 extern Boolean set_cont_sequence P((char *new_seq));
281 extern int wrap P((char *dest, char *src, int count, int width, int *lp));
282 int Explode P((Board board, int fromX, int fromY, int toX, int toY));
284 typedef enum { CheckBox, ComboBox, TextBox, Button, Spin, ResetButton, SaveButton, ListBox, Graph, PopUp,
285 FileName, PathName, Slider, Message, Fractional, Label, Icon,
286 BoxBegin, BoxEnd, BarBegin, BarEnd, DropDown, Break, EndMark } Control;
288 typedef struct XB_OPT { // [HGM] options: descriptor of UCI-style option
289 int value; // current setting, starts as default
290 int min; // Also used for flags
292 void *handle; // for use by front end
293 void *target; // for use by front end
294 char *textValue; // points to beginning of text value in name field
295 char **choice; // points to array of combo choices in cps->combo
297 char *name; // holds both option name and text value (in allocated memory)
300 typedef struct XB_CPS {
305 char *twoMachinesColor; /* "white\n" or "black\n" */
309 struct XB_CPS *other;
311 char *computerString;
312 int sendTime; /* 0=don't, 1=do, 2=test */
316 int offeredDraw; /* countdown */
318 int useSetboard; /* 0=use "edit"; 1=use "setboard" */
319 int extendedEdit;/* 1=also set holdings with "edit" */
320 int useSAN; /* 0=use coordinate notation; 1=use SAN */
321 int usePing; /* 0=not OK to use ping; 1=OK */
324 int usePlayother;/* 0=not OK to use playother; 1=OK */
325 int useColors; /* 0=avoid obsolete white/black commands; 1=use them */
326 int useUsermove; /* 0=just send move; 1=send "usermove move" */
327 int sendICS; /* 0=don't use "ics" command; 1=do */
328 int sendName; /* 0=don't use "name" command; 1=do */
329 int sdKludge; /* 0=use "sd DEPTH" command; 1=use "depth\nDEPTH" */
330 int stKludge; /* 0=use "st TIME" command; 1=use "level 1 TIME" */
331 int excludeMoves;/* 0=don't use "exclude" command; 1=do */
341 int useFEN960; /* 0=use "KQkq" style FENs, 1=use "HAha" style FENs */
342 int useOOCastle; /* 0="O-O" notation for castling, 1="king capture rook" notation */
343 /* End of additions by Tord */
345 int scoreIsAbsolute; /* [AS] 0=don't know (standard), 1=score is always from white side */
346 int isUCI; /* [AS] 0=no (Winboard), 1=UCI (requires Polyglot) */
347 int hasOwnBookUCI; /* [AS] 0=use GUI or Polyglot book, 1=has own book */
349 /* [HGM] time odds */
350 float timeOdds; /* factor through which we divide time for this engine */
351 int debug; /* [HGM] ignore engine debug lines starting with '#' */
352 int maxNrOfSessions; /* [HGM] secondary TC: max args in 'level' command */
353 int accumulateTC; /* [HGM] secondary TC: how to handle extra sessions */
354 int nps; /* [HGM] nps: factor for node count to replace time */
356 int alphaRank; /* [HGM] shogi: engine uses shogi-type coordinates */
357 int maxCores; /* [HGM] SMP: engine understands cores command */
358 int memSize; /* [HGM] memsize: engine understands memory command */
359 char *egtFormats; /* [HGM] EGT: supported tablebase formats */
360 int bookSuspend; /* [HGM] book: go was deferred because of book hit */
361 int pause; /* [HGM] pause: 1=supports it, 2=actually paused */
362 int nrOptions; /* [HGM] options: remembered option="..." features */
363 #define MAX_OPTIONS 200
364 Option option[MAX_OPTIONS];
366 char *comboList[20*MAX_OPTIONS];
367 char *optionSettings;
368 void *programLogo; /* [HGM] logo: bitmap of the logo */
369 char *fenOverride; /* [HGM} FRC: force FEN casling & ep fields by hand */
370 char userError; /* [HGM] crash: flag to suppress fatal-error messages*/
371 char reload; /* [HGM] options: flag to resend options with xreuse */
374 extern ChessProgramState first, second;
376 /* Search stats from chessprogram */
378 char movelist[2*MSG_SIZ]; /* Last PV we were sent */
379 int depth; /* Current search depth */
380 int nr_moves; /* Total nr of root moves */
381 int moves_left; /* Moves remaining to be searched */
382 char move_name[MOVE_LEN]; /* Current move being searched, if provided */
383 u64 nodes; /* # of nodes searched */
384 int time; /* Search time (centiseconds) */
385 int score; /* Score (centipawns) */
386 int got_only_move; /* If last msg was "(only move)" */
387 int got_fail; /* 0 - nothing, 1 - got "--", 2 - got "++" */
388 int ok_to_send; /* handshaking between send & recv */
389 int line_is_book; /* 1 if movelist is book moves */
390 int seen_stat; /* 1 if we've seen the stat01: line */
393 extern ChessProgramStats_Move pvInfoList[MAX_MOVES];
394 extern Boolean shuffleOpenings;
395 extern ChessProgramStats programStats;
396 extern int opponentKibitzes; // used by wengineo.c
397 extern int errorExitStatus;
398 extern char *recentEngines;
399 extern char *comboLine;
400 extern Boolean partnerUp, twoBoards;
401 void SettingsPopUp P((ChessProgramState *cps)); // [HGM] really in front-end, but CPS not known in frontend.h
402 int WaitForEngine P((ChessProgramState *cps, DelayedEventCallback x));
403 void Load P((ChessProgramState *cps, int n));
404 int MultiPV P((ChessProgramState *cps));
405 void MoveHistorySet P(( char movelist[][2*MOVE_LEN], int first, int last, int current, ChessProgramStats_Move * pvInfo ));
406 void MakeEngineOutputTitle P((void));
407 void LoadTheme P((void));
408 void CreateBookEvent P((void));
410 /* A point in time */
412 long sec; /* Assuming this is >= 32 bits */
413 int ms; /* Assuming this is >= 16 bits */
416 void GetTimeMark P((TimeMark *));
417 long SubtractTimeMarks P((TimeMark *, TimeMark *));
419 #endif /* XB_BACKEND */