Refactor move generator, and add Chu-Shogi pieces
[xboard.git] / common.h
1 /*
2  * common.h -- Common definitions for X and Windows NT versions of XBoard
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 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 XB_COMMON
55 #define XB_COMMON
56
57
58 /* Begin compatibility grunge  */
59
60 #if defined(__STDC__) || defined(WIN32) || defined(_amigados)
61 #define P(args) args
62 typedef void *VOIDSTAR;
63 #else
64 #define P(args)         ()
65 typedef char *VOIDSTAR;
66 #endif
67
68 #ifdef WIN32
69 typedef char Boolean;
70 typedef char *String;
71 #define popen _popen
72 #define pclose _pclose
73
74 #else
75 #ifdef _amigados        /*  It is important, that these types have  */
76 typedef int Boolean;    /*  a length of 4 bytes each, as we are     */
77 typedef char *String;   /*  using ReadArgs() for argument parsing.  */
78 #ifdef _DCC
79 FILE *popen(const char *, const char *);
80 int pclose(FILE *);
81 #endif
82
83 #else
84 #ifdef X11
85 #include <X11/Intrinsic.h>
86 #else
87 typedef char Boolean;
88 typedef char *String;
89 #define True 1
90 #define False 0
91 #endif
92 #endif
93 #endif
94
95
96 #ifndef TRUE
97 #define TRUE 1
98 #define FALSE 0
99 #endif
100
101 #define UNKNOWN -1 /* [HGM] nps */
102
103 #if !HAVE_RANDOM
104 # if HAVE_RAND48
105 #  define srandom srand48
106 #  define random lrand48
107 # else /* not HAVE_RAND48 */
108 #  define srandom srand
109 #  define random rand
110 # endif /* not HAVE_RAND48 */
111 #endif /* !HAVE_RANDOM */
112
113 /* End compatibility grunge */
114
115 #define PROTOVER                2       /* engine protocol version */
116
117 // [HGM] license: Messages that engines must print to satisfy their license requirements for patented variants
118 #define GOTHIC "Gothic Chess (see www.GothicChess.com) is licensed under U.S. Patent #6,481,716 by Ed Trice"
119 #define FALCON "Falcon Chess (see www.chessvariants.com) is licensed under U.S. Patent #5,690,334 by George W. Duke"
120
121 /* [HGM] Some notes about board sizes:
122    In games that allow piece drops, the holdings are considered part of the
123    board, in the leftmost and rightmost two files. This way they are
124    automatically part of the game-history states, and enjoy all display
125    functions (including drag-drop and click-click moves to the regular part
126    of the board). The drawback of this is that the internal numbering of
127    files starts at 2 for the a-file if holdings are displayed. To ensure
128    consistency, this shifted numbering system is used _everywhere_ in the
129    code, and conversion to the 'normal' system only takes place when the
130    file number is converted to or from ASCII (by redefining the character
131    constant 'a'). This works because Winboard only communicates with the
132    outside world in ASCII. In a similar way, the different rank numbering
133    systems (starting at rank 0 or 1) are implemented by redefining '1'.
134 */
135 #define BOARD_RANKS             17            /* [HGM] for in declarations  */
136 #define BOARD_FILES             16             /* [HGM] for in declarations  */
137 #define BOARD_HEIGHT (gameInfo.boardHeight)    /* [HGM] made user adjustable */
138 #define BOARD_WIDTH  (gameInfo.boardWidth + 2*gameInfo.holdingsWidth)
139 #define BOARD_LEFT   (gameInfo.holdingsWidth)  /* [HGM] play-board edges     */
140 #define BOARD_RGHT   (gameInfo.boardWidth + gameInfo.holdingsWidth)
141 #define CASTLING     (BOARD_RANKS-1)           /* [HGM] hide in upper rank   */
142 #define VIRGIN       (BOARD_RANKS-2)           /* [HGM] pieces not moved     */
143 #define EP_STATUS    CASTLING][(BOARD_FILES-2) /* [HGM] in upper rank        */
144 #define HOLDINGS_SET CASTLING][(BOARD_FILES-1) /* [HGM] in upper-right corner*/
145 #define ONE          ('1'-(BOARD_HEIGHT>9))    /* [HGM] foremost board rank  */
146 #define AAA          ('a'-BOARD_LEFT)          /* [HGM] leftmost board file  */
147 #define VIRGIN_W                 1             /* [HGM] flags in Board[VIRGIN][X] */
148 #define VIRGIN_B                 2
149 #define DROP_RANK               -3
150 #define MAX_MOVES               1000
151 #define MSG_SIZ                 512
152 #define DIALOG_SIZE             256
153 #define STAR_MATCH_N            16
154 #define MOVE_LEN                32
155 #define TIME_CONTROL            "5"     /* in minutes */
156 #define TIME_DELAY_QUOTE        "1.0"   /* seconds between moves */
157 #define TIME_DELAY              ((float) 1.0)
158 #define MOVES_PER_SESSION       40      /* moves per TIME_CONTROL */
159 #define TIME_INCREMENT          -1      /* if >= 0, MOVES_PER_SESSION unused */
160 #define WhiteOnMove(move)       (((move) % 2) == 0)
161 #define ICS_HOST                "chessclub.com"
162 #define ICS_PORT                "5000"
163 #define ICS_COMM_PORT           ""
164 #define FIRST_HOST              "localhost"
165 #define SECOND_HOST             "localhost"
166 #define TELNET_PROGRAM          "telnet"
167 #define DEF_BITMAP_DIR          BITMAPDIR
168 #define MATCH_MODE              "False"
169 #define INIT_STRING             "new\nrandom\n"
170 #define WHITE_STRING            "white\ngo\n"
171 #define BLACK_STRING            "black\ngo\n"
172 #define COMPUTER_STRING         "computer\n"
173 #define REUSE_CHESS_PROGRAMS    1
174 #define WHITE_PIECE_COLOR       "#FFFFCC"
175 #define BLACK_PIECE_COLOR       "#202020"
176 #define LIGHT_SQUARE_COLOR      "#C8C365"
177 #define DARK_SQUARE_COLOR       "#77A26D"
178 #define JAIL_SQUARE_COLOR       "#808080"
179 #define HIGHLIGHT_SQUARE_COLOR  "#FFFF00"
180 #define PREMOVE_HIGHLIGHT_COLOR "#FF0000"
181 #define LOWTIMEWARNING_COLOR    "#FF0000"
182 #define BELLCHAR                '\007'
183 #define NULLCHAR                '\000'
184 #define FEATURE_TIMEOUT         10000 /*ms*/
185
186 #define CLOCK_FONT 0
187 #define MESSAGE_FONT 1
188 #define COORD_FONT 2
189 #define CONSOLE_FONT 3
190 #define COMMENT_FONT 4
191 #define EDITTAGS_FONT 5
192 #define MOVEHISTORY_FONT 6
193 #define GAMELIST_FONT 7
194 #define NUM_FONTS 8
195
196 /* Default to no flashing (the "usual" XBoard behavior) */
197 #define FLASH_COUNT     0               /* Number of times to flash */
198 #define FLASH_RATE      5               /* Flashes per second */
199
200 /* Default delay per character (in msec) while sending login script */
201 #define MS_LOGIN_DELAY  0
202
203 /* [AS] Support for background textures */
204 #define BACK_TEXTURE_MODE_DISABLED      0
205 #define BACK_TEXTURE_MODE_PLAIN         1
206 #define BACK_TEXTURE_MODE_FULL_RANDOM   2
207
208 /* Zippy defaults */
209 #define ZIPPY_TALK FALSE
210 #define ZIPPY_PLAY FALSE
211 #define ZIPPY_LINES "yow.lines"
212 #define ZIPPY_PINHEAD ""
213 #define ZIPPY_PASSWORD ""
214 #define ZIPPY_PASSWORD2 ""
215 #define ZIPPY_WRONG_PASSWORD ""
216 #define ZIPPY_ACCEPT_ONLY ""
217 #define ZIPPY_USE_I TRUE
218 #define ZIPPY_BUGHOUSE 0
219 #define ZIPPY_NOPLAY_CRAFTY FALSE
220 #define ZIPPY_GAME_END "gameend\n"
221 #define ZIPPY_GAME_START ""
222 #define ZIPPY_ADJOURN FALSE
223 #define ZIPPY_ABORT FALSE
224 #define ZIPPY_VARIANTS "normal,fischerandom,crazyhouse,losers,suicide,3checks,twokings,bughouse,shatranj"
225 #define ZIPPY_MAX_GAMES 0
226 #define ZIPPY_REPLAY_TIMEOUT 120
227
228 typedef VOIDSTAR ProcRef;
229 #define NoProc ((ProcRef) 0)
230 typedef VOIDSTAR InputSourceRef;
231
232 typedef void (*DelayedEventCallback) P((void));
233
234 typedef enum { Press, Release } ClickType;
235
236 typedef enum {
237     BeginningOfGame, MachinePlaysWhite, MachinePlaysBlack,
238     AnalyzeMode, AnalyzeFile, TwoMachinesPlay,
239     EditGame, PlayFromGameFile, EndOfGame, EditPosition, Training,
240     IcsIdle, IcsPlayingWhite, IcsPlayingBlack, IcsObserving,
241     IcsExamining
242   } GameMode;
243
244 typedef enum {
245     /* [HGM] the order here is crucial for Crazyhouse & Shogi: */
246     /* only the first N pieces can go into the holdings, and   */
247     /* promotions in those variants shift P-W to U-S           */
248     WhitePawn, WhiteKnight, WhiteBishop, WhiteRook, WhiteQueen,
249     WhiteFerz, WhiteAlfil, WhiteAngel, WhiteMarshall, WhiteWazir, WhiteMan,
250     WhiteCannon, WhiteNightrider, WhiteCardinal, WhiteDragon, WhiteGrasshopper,
251     WhiteSilver, WhiteFalcon, WhiteLance, WhiteCobra, WhiteUnicorn, WhiteLion,
252     WhiteTokin, WhiteDagger, WhitePCardinal, WhitePDragon, WhiteCat,
253     WhitePSword, WhiteMonarch, WhiteMother, WhiteNothing, WhitePRook, WhitePDagger,
254     WhiteDolphin, WhiteStag, WhiteHorned, WhiteEagle, WhiteSword,
255     WhiteCrown, WhiteHCrown, WhiteHorse, WhiteDrunk, WhitePBishop, WhiteKing,
256     BlackPawn, BlackKnight, BlackBishop, BlackRook, BlackQueen,
257     BlackFerz, BlackAlfil, BlackAngel, BlackMarshall, BlackWazir, BlackMan,
258     BlackCannon, BlackNightrider, BlackCardinal, BlackDragon, BlackGrasshopper,
259     BlackSilver, BlackFalcon, BlackLance, BlackCobra, BlackUnicorn, BlackLion,
260     BlackTokin, BlackDagger, BlackPCardinal, BlackPDragon, BlackCat,
261     BlackPSword, BlackMonarch, BlackMother, BlackNothing, BlackPRook, BlackPDagger,
262     BlackDolphin, BlackStag, BlackHorned, BlackEagle, BlackSword,
263     BlackCrown, BlackHCrown, BlackHorse, BlackDrunk, BlackPBishop, BlackKing,
264     EmptySquare, DarkSquare,
265     NoRights, // [HGM] gamestate: for castling rights hidden in board[CASTLING]
266     ClearBoard, WhitePlay, BlackPlay, PromotePiece, DemotePiece /*for use on EditPosition menus*/
267   } ChessSquare;
268
269 /* [HGM] some macros that can be used as prefixes to convert piece types */
270 #define WHITE_TO_BLACK (int)BlackPawn - (int)WhitePawn + (int)
271 #define BLACK_TO_WHITE (int)WhitePawn - (int)BlackPawn + (int)
272 #define PROMOTED       (int)WhiteDragon - (int)WhiteRook + (int)
273 #define DEMOTED        (int)WhiteRook - (int)WhiteDragon + (int)
274 #define SHOGI          (int)EmptySquare + (int)
275 #define CHUPROMOTED    ((int)WhitePDragon - (int)WhiteDragon)*(gameInfo.variant == VariantChu) + PROMOTED
276 #define IS_SHOGI(V)    ((V) == VariantShogi || (V) == VariantChu)
277
278
279 typedef ChessSquare Board[BOARD_RANKS][BOARD_FILES];
280
281 typedef enum {
282     EndOfFile = 0,
283     WhiteKingSideCastle, WhiteQueenSideCastle,
284     WhiteKingSideCastleWild, WhiteQueenSideCastleWild,
285     WhiteHSideCastleFR, WhiteASideCastleFR,
286     BlackKingSideCastle, BlackQueenSideCastle,
287     BlackKingSideCastleWild, BlackQueenSideCastleWild,
288     BlackHSideCastleFR, BlackASideCastleFR,
289     WhitePromotion, WhiteNonPromotion,
290     BlackPromotion, BlackNonPromotion,
291     WhiteCapturesEnPassant, BlackCapturesEnPassant,
292     WhiteDrop, BlackDrop, FirstLeg,
293     NormalMove, AmbiguousMove, IllegalMove, ImpossibleMove,
294     WhiteWins, BlackWins, GameIsDrawn, GameUnfinished,
295     GNUChessGame, XBoardGame, MoveNumberOne, Open, Close, Nothing,
296     Comment, PositionDiagram, ElapsedTime, PGNTag, NAG
297   } ChessMove;
298
299 typedef enum {
300     ColorShout, ColorSShout, ColorChannel1, ColorChannel, ColorKibitz,
301     ColorTell, ColorChallenge, ColorRequest, ColorSeek, ColorNormal,
302     ColorNone, NColorClasses
303 } ColorClass;
304
305 typedef enum {
306     SoundMove, SoundBell, SoundAlarm, SoundIcsWin, SoundIcsLoss,
307     SoundIcsDraw, SoundIcsUnfinished, NSoundClasses
308 } SoundClass;
309
310 /* Names for chess variants, not necessarily supported */
311 typedef enum {
312     VariantNormal,       /* Normal chess */
313     VariantLoadable,     /* "loadgame" command allowed (not really a variant)*/
314     VariantWildCastle,   /* Shuffle chess where king can castle from d file */
315     VariantNoCastle,     /* Shuffle chess with no castling at all */
316     VariantFischeRandom, /* FischeRandom */
317     VariantBughouse,     /* Bughouse, ICC/FICS rules */
318     VariantCrazyhouse,   /* Crazyhouse, ICC/FICS rules */
319     VariantLosers,       /* Try to lose all pieces or get mated (ICC wild 17)*/
320     VariantSuicide,      /* Try to lose all pieces incl. king (FICS) */
321     VariantGiveaway,     /* Try to have no legal moves left (ICC wild 26) */
322     VariantTwoKings,     /* Weird ICC wild 9 */
323     VariantKriegspiel,   /* Kriegspiel; pawns can capture invisible pieces */
324     VariantAtomic,       /* Capturing piece explodes (ICC wild 27) */
325     Variant3Check,       /* Win by giving check 3 times (ICC wild 25) */
326     VariantShatranj,     /* Unsupported (ICC wild 28) */
327     Variant29,           /* Temporary name for possible future ICC wild 29 */
328     Variant30,           /* Temporary name for possible future ICC wild 30 */
329     Variant31,           /* Temporary name for possible future ICC wild 31 */
330     Variant32,           /* Temporary name for possible future ICC wild 32 */
331     Variant33,           /* Temporary name for possible future ICC wild 33 */
332     Variant34,           /* Temporary name for possible future ICC wild 34 */
333     Variant35,           /* Temporary name for possible future ICC wild 35 */
334     Variant36,           /* Temporary name for possible future ICC wild 36 */
335     VariantShogi,        /* [HGM] added variants */
336     VariantChu,
337     VariantXiangqi,
338     VariantCourier,
339     VariantGothic,
340     VariantCapablanca,
341     VariantKnightmate,
342     VariantFairy,
343     VariantCylinder,
344     VariantFalcon,
345     VariantCapaRandom,
346     VariantBerolina,
347     VariantJanus,
348     VariantSuper,
349     VariantGreat,
350     VariantTwilight,
351     VariantMakruk,
352     VariantASEAN,
353     VariantSChess,
354     VariantGrand,
355     VariantSpartan,
356     VariantLion,
357     VariantUnknown       /* Catchall for other unknown variants */
358 } VariantClass;
359
360 #define VARIANT_NAMES { \
361   "normal", \
362   "normal", \
363   "wildcastle", \
364   "nocastle", \
365   "fischerandom", \
366   "bughouse", \
367   "crazyhouse", \
368   "losers", \
369   "suicide", \
370   "giveaway", \
371   "twokings", \
372   "kriegspiel", \
373   "atomic", \
374   "3check", \
375   "shatranj", \
376   "wild29", \
377   "wild30", \
378   "wild31", \
379   "wild32", \
380   "wild33", \
381   "wild34", \
382   "wild35", \
383   "wild36", \
384   "shogi", \
385   "chu", \
386   "xiangqi", \
387   "courier", \
388   "gothic", \
389   "capablanca", \
390   "knightmate", \
391   "fairy", \
392   "cylinder", \
393   "falcon",\
394   "caparandom",\
395   "berolina",\
396   "janus",\
397   "super",\
398   "great",\
399   "twilight",\
400   "makruk",\
401   "asean",\
402   "seirawan",\
403   "grand",\
404   "spartan",\
405   "lion",\
406   "unknown" \
407 }
408
409 #define ENGINES 2
410
411 typedef struct {
412     char *language;
413 #if !defined(_amigados)
414     char *whitePieceColor;
415     char *blackPieceColor;
416     char *lightSquareColor;
417     char *darkSquareColor;
418     char *jailSquareColor;
419     char *highlightSquareColor;
420     char *premoveHighlightColor;
421     char *dialogColor;
422     char *buttonColor;
423 #else
424     int whitePieceColor;
425     int blackPieceColor;
426     int lightSquareColor;
427     int darkSquareColor;
428     int jailSquareColor;
429     int highlightSquareColor;
430     int premoveHighlightColor;
431 #endif
432     int movesPerSession;
433     float timeIncrement;
434     char *engInitString[ENGINES];
435     char *computerString[ENGINES];
436     char *chessProgram[ENGINES];
437     char *directory[ENGINES];
438     char *pgnName[ENGINES];
439     Boolean firstPlaysBlack;
440     Boolean noChessProgram;
441     char *host[ENGINES];
442     char *themeNames;
443     char *pieceDirectory;
444     char *border;
445     char *soundDirectory;
446     char *remoteShell;
447     char *remoteUser;
448     float timeDelay;
449     char *timeControl;
450     Boolean trueColors;
451     Boolean icsActive;
452     Boolean autoBox;
453     char *icsHost;
454     char *icsPort;
455     char *icsCommPort;  /* if set, use serial port instead of tcp host/port */
456     char *icsLogon;     /* Hack to permit variable logon scripts. */
457     char *icsHelper;
458     Boolean icsInputBox;
459     Boolean useTelnet;
460     Boolean seekGraph;
461     Boolean autoRefresh;
462     char *telnetProgram;
463     char *gateway;
464     char *loadGameFile;
465     int loadGameIndex;      /* game # within file */
466     char *saveGameFile;
467     Boolean autoSaveGames;
468     Boolean onlyOwn;        /* [HGM] suppress auto-saving of observed games */
469     char *loadPositionFile;
470     int loadPositionIndex;  /* position # within file */
471     char *savePositionFile;
472     Boolean matchMode;
473     int matchGames;
474     Boolean monoMode;
475     Boolean debugMode;
476     Boolean clockMode;
477     char *boardSize;
478     char *logoDir;
479     int logoSize;
480     Boolean Iconic;
481     char *searchTime;
482     int searchDepth;
483     Boolean showCoords;
484     char *clockFont;
485     char *messageFont; /* WinBoard only */
486     char *coordFont;
487     char *font; /* xboard only: all other fonts */
488     char *tagsFont; /* WinBoard only */
489     char *commentFont; /* WinBoard only */
490     char *icsFont; /* WinBoard only */
491     Boolean ringBellAfterMoves;
492     Boolean autoCallFlag;
493     Boolean flipView;
494     Boolean autoFlipView;
495     char *cmailGameName; /* xboard only */
496     Boolean alwaysPromoteToQueen;
497     Boolean oldSaveStyle;
498     Boolean oneClick;
499     Boolean quietPlay;
500     Boolean showThinking;
501     Boolean ponderNextMove;
502     Boolean periodicUpdates;
503     Boolean autoObserve;
504     Boolean autoCreateLogon;
505     Boolean autoComment;
506     Boolean getMoveList;
507     Boolean testLegality;
508     Boolean topLevel;      /* xboard, top-level auxiliary windows */
509     Boolean titleInWindow; /* xboard only */
510     Boolean localLineEditing; /* WinBoard only */
511     Boolean zippyTalk;
512     Boolean zippyPlay;
513     int flashCount; /* Number of times to flash (xboard only) */
514     int flashRate; /* Flashes per second (xboard only)  */
515     int msLoginDelay;  /* Delay per character (in msec) while sending
516                           ICS logon script (xboard only) */
517     Boolean colorize;   /* If True, use the following colors to color text */
518     /* Strings for colors, as "fg, bg, bold" (strings used in xboard only) */
519     char *colorShout;    // [HGM] IMPORTANT: order must conform to ColorClass definition
520     char *colorSShout;
521     char *colorChannel1;
522     char *colorChannel;
523     char *colorKibitz;
524     char *colorTell;
525     char *colorChallenge;
526     char *colorRequest;
527     char *colorSeek;
528     char *colorNormal;
529     char *soundProgram; /* sound-playing program */
530     char *soundShout;     // [HGM] IMPORTANT: order must be as in ColorClass
531     char *soundSShout;
532     char *soundChannel1;
533     char *soundChannel;
534     char *soundKibitz;
535     char *soundTell;
536     char *soundChallenge;
537     char *soundRequest;
538     char *soundSeek;
539     char *soundMove;     // [HGM] IMPORTANT: order must be as in SoundClass
540     char *soundBell;
541     char *soundIcsAlarm;
542     char *soundIcsWin;
543     char *soundIcsLoss;
544     char *soundIcsDraw;
545     char *soundIcsUnfinished;
546     Boolean disguise;        /* [HGM] Promoted Pawns look like pieces in bughouse */
547     Boolean reuse[ENGINES];
548     Boolean animateDragging; /* If True, animate mouse dragging of pieces */
549     Boolean animate;    /* If True, animate non-mouse moves */
550     int animSpeed;      /* Delay in milliseconds between animation frames */
551     Boolean popupMoveErrors;
552     Boolean popupExitMessage;
553     int showJail;
554     Boolean highlightLastMove;
555     Boolean highlightDragging;
556     Boolean blindfold;          /* if true, no pieces are drawn */
557     Boolean premove;            /* true if premove feature enabled */
558     Boolean premoveWhite;       /* true if premoving White first move  */
559     char *premoveWhiteText;     /* text of White premove 1 */
560     Boolean premoveBlack;       /* true if premoving Black first move */
561     char *premoveBlackText;     /* text of Black premove 1 */
562     Boolean icsAlarm;           /* true if sounding alarm at a certain time */
563     int icsAlarmTime;           /* time to sound alarm, in milliseconds */
564     Boolean autoRaiseBoard;
565     int fontSizeTolerance; /* xboard only */
566     char *initialMode;
567     char *variant;
568     char *chatBoxes;
569     int protocolVersion[ENGINES];
570     Boolean showButtonBar;
571     Boolean icsEngineAnalyze;
572     Boolean variations;         /* [HGM] enable variation-tree walking */
573     Boolean autoExtend;         /* [HGM] enable playing move(s) of right-clicked PV in analysis mode */
574
575     /* [AS] New properties (down to the "ZIPPY" part) */
576     Boolean scoreIsAbsolute[ENGINES];  /* If true, engine score is always from white side */
577     Boolean saveExtendedInfoInPGN; /* If true, saved PGN games contain extended info */
578     Boolean hideThinkingFromHuman; /* If true, program thinking is generated but not displayed in human/computer matches */
579     Boolean useBitmaps;
580     Boolean useFont;
581     Boolean useBorder;
582     char * liteBackTextureFile; /* Name of texture bitmap for lite squares */
583     char * darkBackTextureFile; /* Name of texture bitmap for dark squares */
584     int liteBackTextureMode;
585     int darkBackTextureMode;
586     char * renderPiecesWithFont; /* Name of font for rendering chess pieces */
587     char * fontToPieceTable; /* Map to translate font character to chess pieces */
588     int fontBackColorWhite;
589     int fontForeColorWhite;
590     int fontBackColorBlack;
591     int fontForeColorBlack;
592     int fontPieceSize; /* Size of font relative to square (percentage) */
593     int overrideLineGap; /* If >= 0 overrides the lineGap value of the board size properties */
594     int adjudicateLossThreshold; /* Adjudicate a two-machine game if both engines agree the score is below this for 6 plies */
595     int delayBeforeQuit;
596     int delayAfterQuit;
597     char * nameOfDebugFile;
598     char * pgnEventHeader;
599     int defaultFrcPosition;
600     char * gameListTags;
601     Boolean saveOutOfBookInfo;
602     Boolean showEvalInMoveHistory;
603     int evalHistColorWhite;
604     int evalHistColorBlack;
605     Boolean highlightMoveWithArrow;
606     Boolean tourney;
607     char * tourneyOptions;
608     int highlightArrowColor;
609     Boolean useStickyWindows;
610     Boolean bgObserve;   /* [HGM] bughouse */
611     Boolean dualBoard;   /* [HGM] dual     */
612     Boolean viewer;
613     char * viewerOptions;
614     int adjudicateDrawMoves;
615     Boolean autoDisplayComment;
616     Boolean autoDisplayTags;
617     Boolean isUCI[ENGINES];
618     Boolean hasOwnBookUCI[ENGINES];
619     char * adapterCommand;
620     char * ucciAdapter;
621     char * polyglotDir;
622     Boolean usePolyglotBook;
623     Boolean defNoBook;
624     char * polyglotBook;
625     int bookDepth;
626     int bookStrength;
627     int defaultHashSize;
628     int defaultCacheSizeEGTB;
629     char * defaultPathEGTB;
630     int defaultMatchGames;
631
632     /* [HGM] Board size */
633     int NrFiles;
634     int NrRanks;
635     int holdingsSize;
636     int matchPause;
637     char * pieceToCharTable;
638     char * pieceNickNames;
639     char * colorNickNames;
640     Boolean allWhite;
641     Boolean upsideDown;
642     Boolean alphaRank;
643     Boolean testClaims;
644     Boolean checkMates;
645     Boolean materialDraws;
646     Boolean trivialDraws;
647     int ruleMoves;
648     int drawRepeats;
649
650 #if ZIPPY
651     char *zippyLines;
652     char *zippyPinhead;
653     char *zippyPassword;
654     char *zippyPassword2;
655     char *zippyWrongPassword;
656     char *zippyAcceptOnly;
657     int zippyUseI;
658     int zippyBughouse;
659     int zippyNoplayCrafty;
660     char *zippyGameEnd;
661     char *zippyGameStart;
662     int zippyAdjourn;
663     int zippyAbort;
664     char *zippyVariants;
665     int zippyMaxGames;
666     int zippyReplayTimeout; /*seconds*/
667     int zippyShortGame; /* [HGM] aborter   */
668 #endif
669     Boolean lowTimeWarning; /* [HGM] low time */
670     Boolean quitNext;
671     char *lowTimeWarningColor;
672
673     char *serverFileName;
674     char *serverMovesName;
675     char *finger;
676     Boolean suppressLoadMoves;
677     int serverPause;
678     int timeOdds[ENGINES];
679     int timeOddsMode;
680     int accumulateTC[ENGINES];
681     int NPS[ENGINES];
682     Boolean autoKibitz;
683     int engineComments;
684     int eloThreshold1;  /* [HGM] select   */
685     int eloThreshold2;
686     int dateThreshold;
687     int searchMode;
688     int stretch;
689     Boolean ignoreColors;
690     Boolean findMirror;
691     char *userName;
692     int rewindIndex;    /* [HGM] autoinc   */
693     int sameColorGames; /* [HGM] alternate */
694     int smpCores;       /* [HGM] SMP       */
695     char *egtFormats;
696     int niceEngines;    /* [HGM] nice      */
697     char *logo[ENGINES];/* [HGM] logo      */
698     char *pairingEngine;/* [HGM] pairing   */
699     Boolean autoLogo;
700     Boolean noGUI;      /* [HGM] fast: suppress all display updates */
701     char *engOptions[ENGINES]; /* [HGM] options   */
702     char *fenOverride[ENGINES];
703     char *features[ENGINES];
704     char *featureDefaults;
705     char *sysOpen;
706     Boolean keepAlive;  /* [HGM] alive     */
707     Boolean forceIllegal;/*[HGM] illegal   */
708     Boolean noJoin;     /* [HGM] join      */
709     char *wrapContSeq; /* continuation sequence when xboard wraps text */
710     Boolean useInternalWrap; /* use internal wrapping -- noJoin usurps this if set */
711     Boolean pasteSelection; /* paste X selection instead of clipboard */
712     int nrVariations;   /* [HGM] multivar  */
713     int zoom;           /* [HGM] evalGraph */
714     int evalThreshold;  /* [HGM] evalGraph */
715     Boolean dropMenu;   /* [HGM] pv        */
716     Boolean markers;    /* [HGM] markers   */
717     Boolean autoCopyPV;
718     Boolean pieceMenu;
719     Boolean sweepSelect;
720     Boolean whitePOV;
721     Boolean scoreWhite;
722     Boolean pvSAN[ENGINES];
723
724     int recentEngines;
725     char *recentEngineList;
726     char *tourneyFile;
727     char *defName;
728     char *processes;
729     char *results;
730     char *participants;
731     char *afterGame;
732     char *afterTourney;
733     int tourneyType;
734     int tourneyCycles;
735     int seedBase;
736     Boolean roundSync;
737     Boolean cycleSync;
738     Boolean numberTag;
739 } AppData, *AppDataPtr;
740
741 /*  PGN tags (for showing in the game list) */
742 #define LPUSERGLT_SIZE      64
743
744 #define GLT_EVENT           'e'
745 #define GLT_SITE            's'
746 #define GLT_DATE            'd'
747 #define GLT_ROUND           'o'
748 #define GLT_PLAYERS         'p'     /* I.e. white "-" black */
749 #define GLT_RESULT          'r'
750 #define GLT_WHITE_ELO       'w'
751 #define GLT_BLACK_ELO       'b'
752 #define GLT_TIME_CONTROL    't'
753 #define GLT_VARIANT         'v'
754 #define GLT_OUT_OF_BOOK     'a'
755 #define GLT_RESULT_COMMENT  'c'     /* [HGM] rescom */
756
757 #define GLT_DEFAULT_TAGS    "eprd"  /* Event, players, result, date */
758
759 #define GLT_ALL_TAGS        "esdoprwbtvac"
760
761 #define PGN_OUT_OF_BOOK     "Annotator"
762
763 extern AppData appData;
764
765 typedef struct {
766     /* PGN 7-tag info */
767     char *event;
768     char *site;
769     char *date;
770     char *round;
771     char *white;
772     char *black;
773     ChessMove result;
774     /* Additional info */
775     char *fen;          /* NULL or FEN for starting position; input only */
776     char *resultDetails;
777     char *timeControl;
778     char *extraTags;    /* NULL or "[Tag \"Value\"]\n", etc. */
779     int whiteRating;    /* -1 if unknown */
780     int blackRating;    /* -1 if unknown */
781     VariantClass variant;
782     char *outOfBook;    /* [AS] Move and score when engine went out of book */
783     int boardWidth;     /* [HGM] adjustable board size */
784     int boardHeight;
785 /* [HGM] For Shogi and Crazyhouse: */
786     int holdingsSize;  /* number of different piece types in holdings       */
787     int holdingsWidth; /* number of files left and right of board, 0 or 2   */
788 } GameInfo;
789
790 /* [AS] Search stats from chessprogram, for the played move */
791 // [HGM] moved here from backend.h because it occurs in declarations of front-end functions
792 typedef struct {
793     int score;  /* Centipawns */
794     int depth;  /* Plies */
795     int time;   /* Milliseconds */
796 } ChessProgramStats_Move;
797
798 /* [AS] Layout management */
799 typedef struct {
800     Boolean visible;
801     int x;
802     int y;
803     int width;
804     int height;
805 } WindowPlacement;
806
807 extern WindowPlacement wpEngineOutput;
808 extern WindowPlacement wpEvalGraph;
809 extern WindowPlacement wpMoveHistory;
810 extern WindowPlacement wpGameList;
811 extern WindowPlacement wpTags;
812
813 #define MAXENGINES 2000
814
815 // [HGM] chat
816 #define MAX_CHAT 5
817 extern int chatCount;
818 extern char chatPartner[MAX_CHAT][MSG_SIZ];
819
820 // Some prototypes of routines so general they should be available everywhere
821 /* If status == 0, we are exiting with a benign message, not an error */
822 void DisplayFatalError P((String message, int error, int status));
823 void DisplayError P((String message, int error));
824
825 // [HGM] generally useful macros; there are way too many memory leaks...
826 #define FREE(x) if(x) free(x)
827 #define ASSIGN(x, y) if(x) free(x); x = strdup(y)
828
829 // [HGM] for now we use the kludge to redefine all the unstructured options by their array counterpart
830 //       in due time we would have to make the actual substitutions all through the source
831
832 #define firstInitString       engInitString[0]
833 #define secondInitString      engInitString[1]
834 #define firstComputerString   computerString[0]
835 #define secondComputerString  computerString[1]
836 #define firstChessProgram     chessProgram[0]
837 #define secondChessProgram    chessProgram[1]
838 #define firstDirectory        directory[0]
839 #define secondDirectory       directory[1]
840 #define firstProtocolVersion  protocolVersion[0]
841 #define secondProtocolVersion protocolVersion[1]
842 #define firstScoreIsAbsolute  scoreIsAbsolute[0]
843 #define secondScoreIsAbsolute scoreIsAbsolute[1]
844 #define firstHasOwnBookUCI    hasOwnBookUCI[0]
845 #define secondHasOwnBookUCI   hasOwnBookUCI[1]
846 #define firstTimeOdds         timeOdds[0]
847 #define secondTimeOdds        timeOdds[1]
848 #define firstAccumulateTC     accumulateTC[0]
849 #define secondAccumulateTC    accumulateTC[1]
850 #define firstHost    host[0]
851 #define secondHost   host[1]
852 #define reuseFirst   reuse[0]
853 #define reuseSecond  reuse[1]
854 #define firstIsUCI   isUCI[0]
855 #define secondIsUCI  isUCI[1]
856 #define firstNPS     NPS[0]
857 #define secondNPS    NPS[1]
858 #define firstLogo    logo[0]
859 #define secondLogo   logo[1]
860 #define fenOverride1 fenOverride[0]
861 #define fenOverride2 fenOverride[1]
862 #define firstOptions      engOptions[0]
863 #define secondOptions     engOptions[1]
864
865 #endif