From: Arun Persaud Date: Wed, 10 Sep 2014 03:15:45 +0000 (-0700) Subject: Merge branch 'v4.7.x' into master X-Git-Url: http://winboard.nl/cgi-bin?a=commitdiff_plain;h=a799eb8719fdd78da3359ab5810adac322ea4365;hp=d6ad098f095eb0644827bf4dd6659870a1e09d07;p=xboard.git Merge branch 'v4.7.x' into master Conflicts: configure.ac po/da.po po/de.po po/es.po po/it.po po/ru.po po/tr.po po/uk.po po/vi.po po/xboard.pot po/zh_CN.po po/zh_HK.po po/zh_TW.po winboard/config.h --- diff --git a/Makefile.am b/Makefile.am index 61aa1d7..847084a 100644 --- a/Makefile.am +++ b/Makefile.am @@ -57,7 +57,7 @@ xboard_SOURCES = backend.c backend.h backendz.h \ ### SUBDIRS = po -xboard_LDADD = -lm @FRONTEND_LIBS@ @X_LIBS@ @LIBINTL@ @CAIRO_LIBS@ +xboard_LDADD = -ldl -lm @FRONTEND_LIBS@ @X_LIBS@ @LIBINTL@ @CAIRO_LIBS@ EXTRA_DIST = pixmaps themes png sounds winboard \ xboard.texi gpl.texinfo texi2man texinfo.tex xboard.man xboard.desktop xboard-config.desktop \ @@ -69,7 +69,8 @@ DISTCLEANFILES = stamp-h GITVERSION=$(shell sh -c 'git describe --dirty --always 2>/dev/null') AM_CPPFLAGS=-DINFODIR='"$(infodir)"' @X_CFLAGS@ @CAIRO_CFLAGS@ @FRONTEND_CFLAGS@ -DSYSCONFDIR='"$(sysconfdir)"' \ - -DLOCALEDIR='"$(localedir)"' -DSVGDIR='"$(svgdir)"' -D__GIT_VERSION='"$(GITVERSION)"' $(headers) + -DLOCALEDIR='"$(localedir)"' -DSVGDIR='"$(svgdir)"' -D__GIT_VERSION='"$(GITVERSION)"' \ + -DCONFIGURE_OPTIONS='"@CONFIGURE_OPTIONS@"' -DDATADIR='"$(datadir)/games/xboard"' $(headers) ACLOCAL_AMFLAGS = -I m4 @@ -84,24 +85,26 @@ sysconf_DATA = xboard.conf ### icon files -icondir = $(datadir)/icons/hicolor/48x48/apps +icondir = @ICONSDIR@ dist_icon_DATA = xboard.png -svgicondir = $(datadir)/icons/hicolor/scalable/apps +svgicondir = @SVGICONSDIR@ dist_svgicon_DATA = xboard.svg ### desktop files for KDE and gnome -Applicationsdir = $(datadir)/applications +Applicationsdir = @DESKTOPDIR@ Applications_DATA = xboard.desktop xboard-fen-viewer.desktop xboard-pgn-viewer.desktop xboard-tourney.desktop xboard-config.desktop ### mime file -mimedir = $(datadir)/mime/packages +mimedir = @MIMEDIR@ mime_DATA = xboard.xml +gamedatadir = @GAMEDATADIR@ + ### directory and files for svgs -svgdir = $(datadir)/games/xboard/themes/default +svgdir = $(gamedatadir)/themes/default dist_svg_DATA = svg/icon_white.svg svg/icon_black.svg \ svg/BlackAdvisor.svg svg/WhiteAdvisor.svg \ svg/BlackArchbishop.svg svg/WhiteArchbishop.svg \ @@ -129,12 +132,25 @@ dist_svg_DATA = svg/icon_white.svg svg/icon_black.svg \ svg/BlackQueen.svg svg/WhiteQueen.svg \ svg/BlackRook.svg svg/WhiteRook.svg \ svg/BlackUnicorn.svg svg/WhiteUnicorn.svg \ + svg/BlackSword.svg svg/WhiteSword.svg \ + svg/BlackHSword.svg svg/WhiteHSword.svg \ + svg/BlackLeopard.svg svg/WhiteLeopard.svg \ + svg/BlackLion.svg svg/WhiteLion.svg \ + svg/BlackPromoBishop.svg svg/WhitePromoBishop.svg \ + svg/BlackPromoRook.svg svg/WhitePromoRook.svg \ + svg/BlackPromoHorse.svg svg/WhitePromoHorse.svg \ + svg/BlackPromoDragon.svg svg/WhitePromoDragon.svg \ + svg/BlackPromoSword.svg svg/WhitePromoSword.svg \ + svg/BlackPromoHSword.svg svg/WhitePromoHSword.svg \ + svg/BlackHCrown.svg svg/WhiteHCrown.svg \ + svg/BlackDolphin.svg svg/WhiteDolphin.svg \ + svg/BlackClaw.svg svg/WhiteClaw.svg \ svg/eo_Analyzing.svg svg/eo_Black.svg \ svg/eo_Clear.svg svg/eo_Ponder.svg \ svg/eo_Thinking.svg svg/eo_Unknown.svg \ svg/eo_White.svg -shogidir = $(datadir)/games/xboard/themes/shogi +shogidir = $(gamedatadir)/themes/shogi dist_shogi_DATA = \ themes/shogi/WhiteGold.svg themes/shogi/WhiteCrownedBishop.svg\ themes/shogi/WhiteBishop.svg themes/shogi/WhiteKing.svg\ @@ -151,7 +167,7 @@ dist_shogi_DATA = \ themes/shogi/BlackRook.svg themes/shogi/BlackCrownedRook.svg\ themes/shogi/BlackAdvisor.svg themes/shogi/BlackGoldSilver.svg -xiangqidir = $(datadir)/games/xboard/themes/xiangqi +xiangqidir = $(gamedatadir)/themes/xiangqi dist_xiangqi_DATA = themes/xiangqi/BlackAdvisor.svg themes/xiangqi/WhiteAdvisor.svg \ themes/xiangqi/BlackCanon.svg themes/xiangqi/WhiteCanon.svg \ themes/xiangqi/BlackElephant.svg themes/xiangqi/WhiteElephant.svg \ @@ -160,22 +176,27 @@ dist_xiangqi_DATA = themes/xiangqi/BlackAdvisor.svg themes/xiangqi/WhiteAdvisor themes/xiangqi/BlackPawn.svg themes/xiangqi/WhitePawn.svg \ themes/xiangqi/BlackRook.svg themes/xiangqi/WhiteRook.svg +### directory and files for themes (and other) configuration files + +themesdir = $(datadir)/games/xboard/themes/conf +dist_themes_DATA = conf/shogi conf/xq conf/chu conf/ics conf/mini conf/mini.fen conf/sho conf/sho.fen + ### directory and files for pixmaps -pixmapsdir = $(datadir)/games/xboard/pixmaps/textures -dist_pixmaps_DATA = pixmaps/cross32.xpm pixmaps/cross48.xpm pixmaps/board32.xpm pixmaps/board48.xpm pixmaps/ini32.xpm pixmaps/ini48.xpm +pixmapsdir = $(gamedatadir)/pixmaps/textures +dist_pixmaps_DATA = pixmaps/cross32.png pixmaps/cross48.png pixmaps/board32.png pixmaps/board48.png pixmaps/ini32.png pixmaps/ini48.png ### directory and files for pngs -pngdir = $(datadir)/games/xboard/themes/textures +pngdir = $(gamedatadir)/themes/textures dist_png_DATA = png/hatch.png png/wood_d.png png/wood_l.png png/xqboard.png ### directory and files for sound files -soundsdir = $(datadir)/games/xboard/sounds +soundsdir = $(gamedatadir)/sounds dist_sounds_DATA = \ sounds/cymbal.wav sounds/pop2.wav sounds/slap.wav sounds/ding1.wav sounds/laser.wav \ - sounds/woodthunk.wav sounds/gong.wav sounds/penalty.wav sounds/honkhonk.wav sounds/phone.wav + sounds/woodthunk.wav sounds/gong.wav sounds/penalty.wav sounds/honkhonk.wav sounds/phone.wav sounds/roar.wav ### set correct dir in xboard.conf @@ -210,12 +231,12 @@ if ENABLE_UPDATE_MIMEDB $(XDG_DESKTOP_MENU) install --mode system --novendor xboard-fen-viewer.desktop;\ $(XDG_DESKTOP_MENU) install --mode system --novendor xboard-tourney.desktop;\ $(XDG_DESKTOP_MENU) install --mode system --novendor xboard-config.desktop;\ - $(XDG_ICON_RESOURCE) install --context mimetypes --size 32 pixmaps/board32.xpm application-x-chess-pgn;\ - $(XDG_ICON_RESOURCE) install --context mimetypes --size 32 pixmaps/cross32.xpm application-x-xboard-trn;\ - $(XDG_ICON_RESOURCE) install --context mimetypes --size 32 pixmaps/ini32.xpm application-x-xboard-opt;\ - $(XDG_ICON_RESOURCE) install --context mimetypes --size 48 pixmaps/board48.xpm application-x-chess-pgn;\ - $(XDG_ICON_RESOURCE) install --context mimetypes --size 48 pixmaps/cross48.xpm application-x-xboard-trn;\ - $(XDG_ICON_RESOURCE) install --context mimetypes --size 48 pixmaps/ini48.xpm application-x-xboard-opt;\ + $(XDG_ICON_RESOURCE) install --context mimetypes --size 32 pixmaps/board32.png application-x-chess-pgn;\ + $(XDG_ICON_RESOURCE) install --context mimetypes --size 32 pixmaps/cross32.png application-x-xboard-trn;\ + $(XDG_ICON_RESOURCE) install --context mimetypes --size 32 pixmaps/ini32.png application-x-xboard-opt;\ + $(XDG_ICON_RESOURCE) install --context mimetypes --size 48 pixmaps/board48.png application-x-chess-pgn;\ + $(XDG_ICON_RESOURCE) install --context mimetypes --size 48 pixmaps/cross48.png application-x-xboard-trn;\ + $(XDG_ICON_RESOURCE) install --context mimetypes --size 48 pixmaps/ini48.png application-x-xboard-opt;\ fi endif @@ -227,11 +248,11 @@ if ENABLE_UPDATE_MIMEDB $(XDG_DESKTOP_MENU) uninstall --mode system --novendor xboard-fen-viewer.desktop;\ $(XDG_DESKTOP_MENU) uninstall --mode system --novendor xboard-tourney.desktop;\ $(XDG_DESKTOP_MENU) uninstall --mode system --novendor xboard-config.desktop;\ - $(XDG_ICON_RESOURCE) uninstall --context mimetypes --size 32 board32.xpm application-x-chess-pgn;\ - $(XDG_ICON_RESOURCE) uninstall --context mimetypes --size 32 cross32.xpm application-x-xboard-trn;\ - $(XDG_ICON_RESOURCE) uninstall --context mimetypes --size 32 ini32.xpm application-x-xboard-opt;\ - $(XDG_ICON_RESOURCE) uninstall --context mimetypes --size 48 board48.xpm application-x-chess-pgn;\ - $(XDG_ICON_RESOURCE) uninstall --context mimetypes --size 48 cross48.xpm application-x-xboard-trn;\ - $(XDG_ICON_RESOURCE) uninstall --context mimetypes --size 48 ini48.xpm application-x-xboard-opt;\ + $(XDG_ICON_RESOURCE) uninstall --context mimetypes --size 32 board32.png application-x-chess-pgn;\ + $(XDG_ICON_RESOURCE) uninstall --context mimetypes --size 32 cross32.png application-x-xboard-trn;\ + $(XDG_ICON_RESOURCE) uninstall --context mimetypes --size 32 ini32.png application-x-xboard-opt;\ + $(XDG_ICON_RESOURCE) uninstall --context mimetypes --size 48 board48.png application-x-chess-pgn;\ + $(XDG_ICON_RESOURCE) uninstall --context mimetypes --size 48 cross48.png application-x-xboard-trn;\ + $(XDG_ICON_RESOURCE) uninstall --context mimetypes --size 48 ini48.png application-x-xboard-opt;\ fi endif diff --git a/args.h b/args.h index 660e271..91de0bf 100644 --- a/args.h +++ b/args.h @@ -60,7 +60,7 @@ typedef enum { ArgString, ArgInt, ArgFloat, ArgBoolean, ArgTrue, ArgFalse, ArgNone, ArgColor, ArgAttribs, ArgFilename, ArgBoardSize, ArgFont, ArgCommSettings, - ArgSettingsFilename, ArgBackupSettingsFile, ArgTwo, + ArgSettingsFilename, ArgBackupSettingsFile, ArgTwo, ArgInstall, ArgMaster, ArgX, ArgY, ArgZ // [HGM] placement: for window-placement options stored relative to main window } ArgType; @@ -102,7 +102,10 @@ typedef struct { IcsTextMenuEntry icsTextMenuEntry[ICS_TEXT_MENU_SIZE]; int junk; +unsigned int saveDate; +unsigned int dateStamp; Boolean singleList; +Boolean autoClose; char *homeDir; char *firstEngineLine; char *secondEngineLine; @@ -149,6 +152,9 @@ ArgDescriptor argDescriptors[] = { { "loadGameFile", ArgFilename, (void *) &appData.loadGameFile, FALSE, INVALID }, { "", ArgNone, NULL, FALSE, INVALID }, /* keyword arguments */ + { "saveDate", ArgInt, (void *) &saveDate, TRUE, 0 }, + { "date", ArgInt, (void *) &dateStamp, FALSE, 0 }, + { "autoClose", ArgTrue, (void *) &autoClose, FALSE, FALSE }, JAWS_ARGS { "whitePieceColor", ArgColor, (void *) 0, TRUE, (ArgIniType) WHITE_PIECE_COLOR }, { "wpc", ArgColor, (void *) 0, FALSE, INVALID }, @@ -468,6 +474,7 @@ ArgDescriptor argDescriptors[] = { { "soundSeek", ArgFilename, (void *) &appData.soundSeek, TRUE, (ArgIniType) "" }, { "soundMove", ArgFilename, (void *) &appData.soundMove, TRUE, (ArgIniType) "" }, { "soundBell", ArgFilename, (void *) &appData.soundBell, TRUE, (ArgIniType) SOUND_BELL }, + { "soundRoar", ArgFilename, (void *) &appData.soundRoar, TRUE, (ArgIniType) "" }, { "soundIcsWin", ArgFilename, (void *) &appData.soundIcsWin, TRUE, (ArgIniType) "" }, { "soundIcsLoss", ArgFilename, (void *) &appData.soundIcsLoss, TRUE, (ArgIniType) "" }, { "soundIcsDraw", ArgFilename, (void *) &appData.soundIcsDraw, TRUE, (ArgIniType) "" }, @@ -505,7 +512,9 @@ ArgDescriptor argDescriptors[] = { TRUE, (ArgIniType) FCP_NAMES }, { "secondChessProgramNames", ArgString, (void *) &secondChessProgramNames, !XBOARD, (ArgIniType) SCP_NAMES }, - { "themeNames", ArgString, (void *) &appData.themeNames, !XBOARD, (ArgIniType) "native -upf false -ub false -ubt false -pid \"\"\n" }, + { "themeNames", ArgString, (void *) &appData.themeNames, TRUE, (ArgIniType) "native -upf false -ub false -ubt false -pid \"\"\n" }, + { "addMasterOption", ArgMaster, NULL, FALSE, INVALID }, + { "installEngine", ArgInstall, (void *) &firstChessProgramNames, FALSE, (ArgIniType) "" }, { "initialMode", ArgString, (void *) &appData.initialMode, FALSE, (ArgIniType) "" }, { "mode", ArgString, (void *) &appData.initialMode, FALSE, INVALID }, { "variant", ArgString, (void *) &appData.variant, FALSE, (ArgIniType) "normal" }, @@ -549,6 +558,7 @@ ArgDescriptor argDescriptors[] = { { "pgnEventHeader", ArgString, (void *) &appData.pgnEventHeader, TRUE, (ArgIniType) "Computer Chess Game" }, { "defaultFrcPosition", ArgInt, (void *) &appData.defaultFrcPosition, TRUE, (ArgIniType) -1 }, { "shuffleOpenings", ArgTrue, (void *) &shuffleOpenings, FALSE, INVALID }, + { "fischerCastling", ArgTrue, (void *) &appData.fischerCastling, FALSE, INVALID }, { "gameListTags", ArgString, (void *) &appData.gameListTags, TRUE, (ArgIniType) GLT_DEFAULT_TAGS }, { "saveOutOfBookInfo", ArgBoolean, (void *) &appData.saveOutOfBookInfo, TRUE, (ArgIniType) TRUE }, { "showEvalInMoveHistory", ArgBoolean, (void *) &appData.showEvalInMoveHistory, TRUE, (ArgIniType) TRUE }, @@ -597,6 +607,8 @@ ArgDescriptor argDescriptors[] = { { "useBorder", ArgBoolean, (void *) &appData.useBorder, TRUE, (ArgIniType) FALSE }, { "ub", ArgBoolean, (void *) &appData.useBorder, FALSE, INVALID }, { "border", ArgFilename, (void *) &appData.border, TRUE, (ArgIniType) "" }, + { "finger", ArgFilename, (void *) &appData.finger, FALSE, (ArgIniType) "" }, + { "inscriptions", ArgString, (void *) &appData.inscriptions, XBOARD, (ArgIniType) "" }, // [HGM] tournament options { "tourneyFile", ArgFilename, (void *) &appData.tourneyFile, FALSE, (ArgIniType) "" }, @@ -669,6 +681,8 @@ ArgDescriptor argDescriptors[] = { { "scoreWhite", ArgBoolean, (void *) &appData.scoreWhite, TRUE, FALSE }, { "evalZoom", ArgInt, (void *) &appData.zoom, TRUE, (ArgIniType) 1 }, { "evalThreshold", ArgInt, (void *) &appData.evalThreshold, TRUE, (ArgIniType) 25 }, + { "firstPseudo", ArgTrue, (void *) &appData.pseudo[0], FALSE, FALSE }, + { "secondPseudo", ArgTrue, (void *) &appData.pseudo[1], FALSE, FALSE }, { "fSAN", ArgTrue, (void *) &appData.pvSAN[0], FALSE, FALSE }, { "sSAN", ArgTrue, (void *) &appData.pvSAN[1], FALSE, FALSE }, { "pairingEngine", ArgFilename, (void *) &appData.pairingEngine, TRUE, "" }, @@ -687,6 +701,9 @@ ArgDescriptor argDescriptors[] = { { "topLevel", ArgBoolean, (void *) &appData.topLevel, XBOARD, (ArgIniType) TOPLEVEL }, { "dialogColor", ArgString, (void *) &appData.dialogColor, XBOARD, (ArgIniType) "" }, { "buttonColor", ArgString, (void *) &appData.buttonColor, XBOARD, (ArgIniType) "" }, + { "firstDrawDepth", ArgInt, (void *) &appData.drawDepth[0], FALSE, (ArgIniType) 0 }, + { "secondDrawDepth", ArgInt, (void *) &appData.drawDepth[1], FALSE, (ArgIniType) 0 }, + { "memoHeaders", ArgBoolean, (void *) &appData.headers, TRUE, (ArgIniType) FALSE }, #if ZIPPY { "zippyTalk", ArgBoolean, (void *) &appData.zippyTalk, FALSE, (ArgIniType) ZIPPY_TALK }, @@ -757,6 +774,7 @@ ArgDescriptor argDescriptors[] = { { "winHeight", ArgInt, (void *) &wpMain.height, TRUE, INVALID }, // for attaching auxiliary windows to them { "x", ArgInt, (void *) &wpMain.x, TRUE, (ArgIniType) CW_USEDEFAULT }, { "y", ArgInt, (void *) &wpMain.y, TRUE, (ArgIniType) CW_USEDEFAULT }, + { "icsUp", ArgBoolean, (void *) &wpConsole.visible, XBOARD, (ArgIniType) FALSE }, { "icsX", ArgX, (void *) &wpConsole.x, TRUE, (ArgIniType) CW_USEDEFAULT }, { "icsY", ArgY, (void *) &wpConsole.y, TRUE, (ArgIniType) CW_USEDEFAULT }, { "icsW", ArgInt, (void *) &wpConsole.width, TRUE, (ArgIniType) CW_USEDEFAULT }, @@ -822,6 +840,30 @@ ExitArgError(char *msg, char *badArg, Boolean quit) exit(2); } +void +AppendToSettingsFile (char *line) +{ + char buf[MSG_SIZ]; + FILE *f; + int c; + if(f = fopen(SETTINGS_FILE, "r")) { + do { + int i = 0; + while((buf[i] = c = fgetc(f)) != '\n' && c != EOF) if(i < MSG_SIZ-1) i++; + buf[i] = NULLCHAR; + if(!strcmp(line, buf)) return; // line occurs + } while(c != EOF); + // line did not occur; add it + fclose(f); + if(f = fopen(SETTINGS_FILE, "a")) { + TimeMark now; + GetTimeMark(&now); + fprintf(f, "-date %10lu\n%s\n", now.sec, line); + fclose(f); + } + } +} + int ValidateInt(char *s) { @@ -873,6 +915,19 @@ ParseSettingsFile(char *name, char **addr) } if (ok) { f = fopen(fullname, "r"); +#ifdef DATADIR + if(f == NULL && *fullname != '/' && !addr) { // when a relative name did not work + char buf[MSG_SIZ]; + snprintf(buf, MSG_SIZ, "~/.xboard/themes/conf/%s", name); + MySearchPath(installDir, buf, fullname); // first look in user's own files + f = fopen(fullname, "r"); + if(f == NULL) { + snprintf(buf, MSG_SIZ, "%s/themes/conf", DATADIR); + MySearchPath(buf, name, fullname); // also look in standard place + f = fopen(fullname, "r"); + } + } +#endif if (f != NULL) { if (addr != NULL) { ASSIGN(*addr, fullname); @@ -1065,13 +1120,13 @@ ParseArgs(GetFunc get, void *cl) if(posflag) { // positional argument: the argName was implied, and per default set as -lgf int len = strlen(argValue) - 4; // start of filename extension if(len < 0) len = 0; - if(!strcasecmp(argValue + len, ".trn")) { + if(!StrCaseCmp(argValue + len, ".trn")) { ad = &argDescriptors[2]; // correct implied type to -tf appData.tourney = TRUE; // let it parse -tourneyOptions later - } else if(!strcasecmp(argValue + len, ".fen") || !strcasecmp(argValue + len, ".epd")) { + } else if(!StrCaseCmp(argValue + len, ".fen") || !StrCaseCmp(argValue + len, ".epd")) { ad = &argDescriptors[1]; // correct implied type to -lpf appData.viewer = TRUE; - } else if(!strcasecmp(argValue + len, ".ini") || !strcasecmp(argValue + len, ".xop")) { + } else if(!StrCaseCmp(argValue + len, ".ini") || !StrCaseCmp(argValue + len, ".xop")) { ad = &argDescriptors[0]; // correct implied type to -opt } else if(GetEngineLine(argValue, 11)) { ad = &argDescriptors[3]; // correct implied type to -is @@ -1166,6 +1221,20 @@ ParseArgs(GetFunc get, void *cl) ParseCommPortSettings(argValue); break; + case ArgMaster: + AppendToSettingsFile(argValue); + break; + + case ArgInstall: + q = *(char **) ad->argLoc; + if((saveDate == 0 || saveDate - dateStamp < 0) && !strstr(q, argValue) ) { + int l = strlen(q) + strlen(argValue); + *(char **) ad->argLoc = malloc(l+2); + snprintf(*(char **) ad->argLoc, l+2, "%s%s\n", q, argValue); + free(q); + } + break; + case ArgNone: ExitArgError(_("Unrecognized argument %s"), argValue, TRUE); break; @@ -1334,6 +1403,8 @@ InitAppData(char *lpCmdLine) appData.NrRanks > BOARD_RANKS ) DisplayFatalError("Recompile with BOARD_RANKS or BOARD_FILES, to support this size", 0, 2); + if(!*appData.secondChessProgram) { ASSIGN(appData.secondChessProgram, appData.firstChessProgram); } // [HGM] scp defaults to fcp + /* [HGM] After parsing the options from the .ini file, and overruling them * with options from the command line, we now make an even higher priority * overrule by WB options attached to the engine command line. This so that @@ -1401,6 +1472,11 @@ InitAppData(char *lpCmdLine) appData.savePositionFile = strdup(buf); } + if(autoClose) { // was called for updating settingsfile only + if(saveSettingsOnExit) SaveSettings(settingsFileName); + exit(0); + } + /* Finish initialization for fonts and sounds */ CreateFonts(); @@ -1431,8 +1507,11 @@ SaveSettings(char* name) ArgDescriptor *ad; char dir[MSG_SIZ], buf[MSG_SIZ]; int mps = appData.movesPerSession; + TimeMark now; + + if (!MainWindowUp() && !autoClose) return; - if (!MainWindowUp()) return; + GetTimeMark(&now); saveDate = now.sec; GetCurrentDirectory(MSG_SIZ, dir); if(MySearchPath(installDir, name, buf)) { @@ -1532,10 +1611,17 @@ SaveSettings(char* name) break; case ArgFilename: if(*(char**)ad->argLoc == NULL) break; // just in case - if (strchr(*(char **)ad->argLoc, '\"')) { - fprintf(f, OPTCHAR "%s" SEPCHAR "'%s'\n", ad->argName, *(char **)ad->argLoc); - } else { - fprintf(f, OPTCHAR "%s" SEPCHAR "\"%s\"\n", ad->argName, *(char **)ad->argLoc); + { char buf[MSG_SIZ]; + snprintf(buf, MSG_SIZ, "%s", *(char**)ad->argLoc); +#ifdef __APPLE__ + if(strstr(buf, DATADIR) == buf) + snprintf(buf, MSG_SIZ, "~~%s", *(char**)ad->argLoc + strlen(DATADIR)); +#endif + if (strchr(buf, '\"')) { + fprintf(f, OPTCHAR "%s" SEPCHAR "'%s'\n", ad->argName, buf); + } else { + fprintf(f, OPTCHAR "%s" SEPCHAR "\"%s\"\n", ad->argName, buf); + } } break; case ArgBoardSize: @@ -1550,6 +1636,8 @@ SaveSettings(char* name) case ArgNone: case ArgBackupSettingsFile: case ArgSettingsFilename: ; + case ArgMaster: ; + case ArgInstall: ; } } fclose(f); diff --git a/backend.c b/backend.c index 2744609..0ef05b0 100644 --- a/backend.c +++ b/backend.c @@ -55,14 +55,32 @@ #ifdef WIN32 #include -int flock(int f, int code); -#define LOCK_EX 2 -#define SLASH '\\' + int flock(int f, int code); +# define LOCK_EX 2 +# define SLASH '\\' + +# ifdef ARC_64BIT +# define EGBB_NAME "egbbdll64.dll" +# else +# define EGBB_NAME "egbbdll.dll" +# endif #else -#include -#define SLASH '/' +# include +# define SLASH '/' + +# include +# ifdef ARC_64BIT +# define EGBB_NAME "egbbso64.so" +# else +# define EGBB_NAME "egbbso.so" +# endif + // kludge to allow Windows code in back-end by converting it to corresponding Linux code +# define CDECL +# define HMODULE void * +# define LoadLibrary(x) dlopen(x, RTLD_LAZY) +# define GetProcAddress dlsym #endif @@ -130,6 +148,7 @@ extern int gettimeofday(struct timeval *, struct timezone *); #endif #include "backendz.h" #include "evalgraph.h" +#include "engineoutput.h" #include "gettext.h" #ifdef ENABLE_NLS @@ -225,14 +244,13 @@ void DisplayTwoMachinesTitle P(()); static void ExcludeClick P((int index)); void ToggleSecond P((void)); void PauseEngine P((ChessProgramState *cps)); -static int NonStandardBoardSize P((void)); +static int NonStandardBoardSize P((VariantClass v, int w, int h, int s)); #ifdef WIN32 extern void ConsoleCreate(); #endif ChessProgramState *WhitePlayer(); -void InsertIntoMemo P((int which, char *text)); // [HGM] kibitz: in engineo.c int VerifyDisplayMode P(()); char *GetInfoFromComment( int, char * ); // [HGM] PV time: returns stripped comment @@ -269,11 +287,14 @@ char chatPartner[MAX_CHAT][MSG_SIZ]; /* [HGM] chat: list of chatting partners */ extern int chatCount; int chattingPartner; char marker[BOARD_RANKS][BOARD_FILES]; /* [HGM] marks for target squares */ +char legal[BOARD_RANKS][BOARD_FILES]; /* [HGM] legal target squares */ char lastMsg[MSG_SIZ]; +char lastTalker[MSG_SIZ]; ChessSquare pieceSweep = EmptySquare; ChessSquare promoSweep = EmptySquare, defaultPromoChoice; int promoDefaultAltered; int keepInfo = 0; /* [HGM] to protect PGN tags in auto-step game analysis */ +static int initPing = -1; /* States for ics_getting_history */ #define H_FALSE 0 @@ -388,12 +409,19 @@ PosFlags (index) case VariantShatranj: case VariantCourier: case VariantMakruk: + case VariantASEAN: case VariantGrand: flags &= ~F_ALL_CASTLE_OK; break; + case VariantChu: + case VariantChuChess: + case VariantLion: + flags |= F_NULL_MOVE; + break; default: break; } + if(appData.fischerCastling) flags |= F_FRC_TYPE_CASTLING, flags &= ~F_ALL_CASTLE_OK; // [HGM] fischer return flags; } @@ -557,6 +585,20 @@ ChessSquare makrukArray[2][BOARD_FILES] = { /* [HGM] (movGen knows about Shatran BlackKing, BlackMan, BlackKnight, BlackRook } }; +ChessSquare aseanArray[2][BOARD_FILES] = { /* [HGM] (movGen knows about Shatranj Q and P) */ + { WhiteRook, WhiteKnight, WhiteMan, WhiteFerz, + WhiteKing, WhiteMan, WhiteKnight, WhiteRook }, + { BlackRook, BlackKnight, BlackMan, BlackFerz, + BlackKing, BlackMan, BlackKnight, BlackRook } +}; + +ChessSquare lionArray[2][BOARD_FILES] = { + { WhiteRook, WhiteLion, WhiteBishop, WhiteQueen, + WhiteKing, WhiteBishop, WhiteKnight, WhiteRook }, + { BlackRook, BlackLion, BlackBishop, BlackQueen, + BlackKing, BlackBishop, BlackKnight, BlackRook } +}; + #if (BOARD_FILES>=10) ChessSquare ShogiArray[2][BOARD_FILES] = { @@ -601,6 +643,13 @@ ChessSquare GrandArray[2][BOARD_FILES] = { BlackMarshall, BlackAngel, BlackBishop, BlackKnight, EmptySquare } }; +ChessSquare ChuChessArray[2][BOARD_FILES] = { + { WhiteMan, WhiteKnight, WhiteBishop, WhiteCardinal, WhiteLion, + WhiteQueen, WhiteDragon, WhiteBishop, WhiteKnight, WhiteMan }, + { BlackMan, BlackKnight, BlackBishop, BlackDragon, BlackQueen, + BlackLion, BlackCardinal, BlackBishop, BlackKnight, BlackMan } +}; + #ifdef GOTHIC ChessSquare GothicArray[2][BOARD_FILES] = { { WhiteRook, WhiteKnight, WhiteBishop, WhiteQueen, WhiteMarshall, @@ -637,8 +686,23 @@ ChessSquare CourierArray[2][BOARD_FILES] = { { BlackRook, BlackKnight, BlackAlfil, BlackBishop, BlackMan, BlackKing, BlackFerz, BlackWazir, BlackBishop, BlackAlfil, BlackKnight, BlackRook } }; +ChessSquare ChuArray[6][BOARD_FILES] = { + { WhiteLance, WhiteUnicorn, WhiteMan, WhiteFerz, WhiteWazir, WhiteKing, + WhiteAlfil, WhiteWazir, WhiteFerz, WhiteMan, WhiteUnicorn, WhiteLance }, + { BlackLance, BlackUnicorn, BlackMan, BlackFerz, BlackWazir, BlackAlfil, + BlackKing, BlackWazir, BlackFerz, BlackMan, BlackUnicorn, BlackLance }, + { WhiteCannon, EmptySquare, WhiteBishop, EmptySquare, WhiteNightrider, WhiteMarshall, + WhiteAngel, WhiteNightrider, EmptySquare, WhiteBishop, EmptySquare, WhiteCannon }, + { BlackCannon, EmptySquare, BlackBishop, EmptySquare, BlackNightrider, BlackAngel, + BlackMarshall, BlackNightrider, EmptySquare, BlackBishop, EmptySquare, BlackCannon }, + { WhiteFalcon, WhiteSilver, WhiteRook, WhiteCardinal, WhiteDragon, WhiteLion, + WhiteQueen, WhiteDragon, WhiteCardinal, WhiteRook, WhiteSilver, WhiteFalcon }, + { BlackFalcon, BlackSilver, BlackRook, BlackCardinal, BlackDragon, BlackQueen, + BlackLion, BlackDragon, BlackCardinal, BlackRook, BlackSilver, BlackFalcon } +}; #else // !(BOARD_FILES>=12) #define CourierArray CapablancaArray +#define ChuArray CapablancaArray #endif // !(BOARD_FILES>=12) @@ -720,8 +784,7 @@ UnloadEngine (ChessProgramState *cps) ExitAnalyzeMode(); DoSleep( appData.delayBeforeQuit ); SendToProgram("quit\n", cps); - DoSleep( appData.delayAfterQuit ); - DestroyChildProcess(cps->pr, cps->useSigterm); + DestroyChildProcess(cps->pr, 4 + cps->useSigterm); } cps->pr = NoProc; if(appData.debugMode) fprintf(debugFP, "Unload %s\n", cps->which); @@ -789,6 +852,7 @@ InitEngine (ChessProgramState *cps, int n) cps->analyzing = FALSE; cps->initDone = FALSE; cps->reload = FALSE; + cps->pseudo = appData.pseudo[n]; /* New features added by Tord: */ cps->useFEN960 = FALSE; @@ -806,6 +870,7 @@ InitEngine (ChessProgramState *cps, int n) /* [HGM] debug */ cps->debug = FALSE; + cps->drawDepth = appData.drawDepth[n]; cps->supportsNPS = UNKNOWN; cps->memSize = FALSE; cps->maxCores = FALSE; @@ -817,6 +882,7 @@ InitEngine (ChessProgramState *cps, int n) cps->scoreIsAbsolute = appData.scoreIsAbsolute[n]; /* [AS] */ cps->isUCI = appData.isUCI[n]; /* [AS] */ cps->hasOwnBookUCI = appData.hasOwnBookUCI[n]; /* [AS] */ + cps->highlight = 0; if (appData.protocolVersion[n] > PROTOVER || appData.protocolVersion[n] < 1) @@ -915,7 +981,7 @@ char *insert, *wbOptions; // point in ChessProgramNames were we should insert ne void Load (ChessProgramState *cps, int i) { - char *p, *q, buf[MSG_SIZ], command[MSG_SIZ], buf2[MSG_SIZ]; + char *p, *q, buf[MSG_SIZ], command[MSG_SIZ], buf2[MSG_SIZ], buf3[MSG_SIZ], jar; if(engineLine && engineLine[0]) { // an engine was selected from the combo box snprintf(buf, MSG_SIZ, "-fcp %s", engineLine); SwapEngines(i); // kludge to parse -f* / -first* like it is -s* / -second* @@ -939,11 +1005,13 @@ Load (ChessProgramState *cps, int i) p[-1] = SLASH; if(SLASH == '/' && p - engineName > 1) *(p -= 2) = '.'; // for XBoard use ./exeName as command after split! } else { ASSIGN(appData.directory[i], "."); } + jar = (strstr(p, ".jar") == p + strlen(p) - 4); if(params[0]) { if(strchr(p, ' ') && !strchr(p, '"')) snprintf(buf2, MSG_SIZ, "\"%s\"", p), p = buf2; // quote if it contains spaces snprintf(command, MSG_SIZ, "%s %s", p, params); p = command; } + if(jar) { snprintf(buf3, MSG_SIZ, "java -jar %s", p); p = buf3; } ASSIGN(appData.chessProgram[i], p); appData.isUCI[i] = isUCI; appData.protocolVersion[i] = v1 ? 1 : PROTOVER; @@ -1138,6 +1206,7 @@ InitBackEnd1 () case VariantCapablanca: /* [HGM] should work */ case VariantCourier: /* [HGM] initial forced moves not implemented */ case VariantShogi: /* [HGM] could still mate with pawn drop */ + case VariantChu: /* [HGM] experimental */ case VariantKnightmate: /* [HGM] should work */ case VariantCylinder: /* [HGM] untested */ case VariantFalcon: /* [HGM] untested */ @@ -1158,6 +1227,7 @@ InitBackEnd1 () case Variant3Check: /* should work except for win condition */ case VariantShatranj: /* should work except for all win conditions */ case VariantMakruk: /* should work except for draw countdown */ + case VariantASEAN : /* should work except for draw countdown */ case VariantBerolina: /* might work if TestLegality is off */ case VariantCapaRandom: /* should work */ case VariantJanus: /* should work */ @@ -1166,6 +1236,8 @@ InitBackEnd1 () case VariantSChess: /* S-Chess, should work */ case VariantGrand: /* should work */ case VariantSpartan: /* should work */ + case VariantLion: /* should work */ + case VariantChuChess: /* should work */ break; } } @@ -1485,7 +1557,7 @@ MatchEvent (int mode) NextTourneyGame(-1, &dummy); ReserveGame(-1, 0); if(nextGame <= appData.matchGames) { - DisplayNote(_("You restarted an already completed tourney\nOne more cycle will now be added to it\nGames commence in 10 sec")); + DisplayNote(_("You restarted an already completed tourney.\nOne more cycle will now be added to it.\nGames commence in 10 sec.")); matchMode = mode; ScheduleDelayedEvent(NextMatchGame, 10000); return; @@ -1518,6 +1590,23 @@ InitBackEnd3 P((void)) char buf[MSG_SIZ]; int err, len; + if(!appData.icsActive && !appData.noChessProgram && !appData.matchMode && // mode involves only first engine + !strcmp(appData.variant, "normal") && // no explicit variant request + appData.NrRanks == -1 && appData.NrFiles == -1 && appData.holdingsSize == -1 && // no size overrides requested + !SupportedVariant(first.variants, VariantNormal, 8, 8, 0, first.protocolVersion, "") && // but 'normal' won't work with engine + !SupportedVariant(first.variants, VariantFischeRandom, 8, 8, 0, first.protocolVersion, "") ) { // nor will Chess960 + char c, *q = first.variants, *p = strchr(q, ','); + if(p) *p = NULLCHAR; + if(StringToVariant(q) != VariantUnknown) { // the engine can play a recognized variant, however + int w, h, s; + if(sscanf(q, "%dx%d+%d_%c", &w, &h, &s, &c) == 4) // get size overrides the engine needs with it (if any) + appData.NrFiles = w, appData.NrRanks = h, appData.holdingsSize = s, q = strchr(q, '_') + 1; + ASSIGN(appData.variant, q); // fake user requested the first variant played by the engine + Reset(TRUE, FALSE); // and re-initialize + } + if(p) *p = ','; + } + InitChessProgram(&first, startedFromSetupPosition); if(!appData.noChessProgram) { /* [HGM] tidy: redo program version to use name from myname feature */ @@ -1995,10 +2084,12 @@ StripHighlight (char *s) return retbuf; } +char engineVariant[MSG_SIZ]; char *variantNames[] = VARIANT_NAMES; char * VariantName (VariantClass v) { + if(v == VariantUnknown || *engineVariant) return engineVariant; return variantNames[v]; } @@ -2028,7 +2119,8 @@ StringToVariant (char *e) found = TRUE; } else for (i=0; i= VariantShogi && isalpha(p[strlen(variantNames[i])])) continue; v = (VariantClass) i; found = TRUE; break; @@ -2744,7 +2836,7 @@ read_from_ics (InputSourceRef isr, VOIDSTAR closure, char *data, int count, int int backup; /* [DM] For zippy color lines */ char *p; char talker[MSG_SIZ]; // [HGM] chat - int channel; + int channel, collective=0; connectionAlive = TRUE; // [HGM] alive: I think, therefore I am... @@ -2986,8 +3078,18 @@ read_from_ics (InputSourceRef isr, VOIDSTAR closure, char *data, int count, int char mess[MSG_SIZ]; snprintf(mess, MSG_SIZ, "%s%s", talker, parse); OutputChatMessage(chattingPartner, mess); + if(collective == 1) { // broadcasted talk also goes to private chatbox of talker + int p; + talker[strlen(talker+1)-1] = NULLCHAR; // strip closing delimiter + for(p=0; p= 0) // channel broadcast; look if there is a chatbox for this channel for(p=0; p= '0' && chatPartner[p][0] <= '9' && channel == atoi(chatPartner[p])) { talker[0] = '['; strcat(talker, "] "); - Colorize(channel == 1 ? ColorChannel1 : ColorChannel, FALSE); + Colorize((channel == 1 ? ColorChannel1 : ColorChannel), FALSE); chattingPartner = p; break; } } else if(buf[i-3] == 'e') // kibitz; look if there is a KIBITZ chatbox for(p=0; p') {// shout, c-shout or it; look if there is a 'shouts' chatbox if(buf[i-8] == '-' && buf[i-3] == 't') for(p=0; p') { talker[0] = '<'; strcat(talker, "> "); Colorize(ColorShout, FALSE); } else if(buf[i-8] == '-') { talker[0] = '('; strcat(talker, ") "); Colorize(ColorSShout, FALSE); } @@ -3245,18 +3354,23 @@ read_from_ics (InputSourceRef isr, VOIDSTAR closure, char *data, int count, int } if(chattingPartner<0) // if not, look if there is a chatbox for this indivdual for(p=0; p 0 && buf[oldi-1] == '\n') oldi--; - if (oldi > next_out) SendToPlayer(&buf[next_out], oldi - next_out); started = STARTED_COMMENT; parse_pos = 0; parse[0] = NULLCHAR; savingComment = 3 + chattingPartner; // counts as TRUE - suppressKibitz = TRUE; - continue; + if(collective == 3) i = oldi; else { + suppressKibitz = TRUE; + if(oldi > 0 && buf[oldi-1] == '\n') oldi--; + if (oldi > next_out) SendToPlayer(&buf[next_out], oldi - next_out); + continue; + } } } // [HGM] chat: end of patch @@ -3340,7 +3454,7 @@ read_from_ics (InputSourceRef isr, VOIDSTAR closure, char *data, int count, int parse[parse_pos] = NULLCHAR; started = STARTED_COMMENT; savingComment = TRUE; - } else { + } else if(collective != 3) { started = STARTED_CHATTER; savingComment = FALSE; } @@ -4745,7 +4859,7 @@ ParseBoard12 (char *string) default: break; case MT_CHECK: - if(gameInfo.variant != VariantShogi) + if(!IS_SHOGI(gameInfo.variant)) strcat(parseList[moveNum - 1], "+"); break; case MT_CHECKMATE: @@ -4975,6 +5089,11 @@ SendMoveToProgram (int moveNum, ChessProgramState *cps) char buf[MSG_SIZ]; if(moveList[moveNum][1] == '@' && moveList[moveNum][0] == '@') { + if(gameInfo.variant == VariantLion || gameInfo.variant == VariantChuChess || gameInfo.variant == VariantChu) { + sprintf(buf, "%s@@@@\n", cps->useUsermove ? "usermove " : ""); + SendToProgram(buf, cps); + return; + } // null move in variant where engine does not understand it (for analysis purposes) SendBoard(cps, moveNum + 1); // send position after move in stead. return; @@ -5002,8 +5121,7 @@ SendMoveToProgram (int moveNum, ChessProgramState *cps) /* Added by Tord: Send castle moves in "O-O" in FRC games if required by * the engine. It would be nice to have a better way to identify castle * moves here. */ - if((gameInfo.variant == VariantFischeRandom || gameInfo.variant == VariantCapaRandom) - && cps->useOOCastle) { + if(appData.fischerCastling && cps->useOOCastle) { int fromX = moveList[moveNum][0] - AAA; int fromY = moveList[moveNum][1] - ONE; int toX = moveList[moveNum][2] - AAA; @@ -5017,6 +5135,13 @@ SendMoveToProgram (int moveNum, ChessProgramState *cps) } else SendToProgram(moveList[moveNum], cps); } else + if(moveList[moveNum][4] == ';') { // [HGM] lion: move is double-step over intermediate square + snprintf(buf, MSG_SIZ, "%c%d%c%d,%c%d%c%d\n", moveList[moveNum][0], moveList[moveNum][1] - '0', // convert to two moves + moveList[moveNum][5], moveList[moveNum][6] - '0', + moveList[moveNum][5], moveList[moveNum][6] - '0', + moveList[moveNum][2], moveList[moveNum][3] - '0'); + SendToProgram(buf, cps); + } else if(BOARD_HEIGHT > 10) { // [HGM] big: convert ranks to double-digit where needed if(moveList[moveNum][1] == '@' && (BOARD_HEIGHT < 16 || moveList[moveNum][0] <= 'Z')) { // drop move if(moveList[moveNum][0]== '@') snprintf(buf, MSG_SIZ, "@@@@\n"); else @@ -5090,7 +5215,8 @@ SendMoveToICS (ChessMove moveType, int fromX, int fromY, int toX, int toY, char break; case WhitePromotion: case BlackPromotion: - if(gameInfo.variant == VariantShatranj || gameInfo.variant == VariantCourier || gameInfo.variant == VariantMakruk) + if(gameInfo.variant == VariantShatranj || gameInfo.variant == VariantCourier || + gameInfo.variant == VariantMakruk || gameInfo.variant == VariantASEAN) snprintf(user_move, MSG_SIZ, "%c%c%c%c=%c\n", AAA + fromX, ONE + fromY, AAA + toX, ONE + toY, PieceToChar(WhiteFerz)); @@ -5154,7 +5280,7 @@ UploadGameEvent () SendToICS(ics_prefix); SendToICS(buf); if(startedFromSetupPosition || backwardMostMove != 0) { - fen = PositionToFEN(backwardMostMove, NULL); + fen = PositionToFEN(backwardMostMove, NULL, 1); if(ics_type == ICS_ICC) { // on ICC we can simply send a complete FEN to set everything snprintf(buf, MSG_SIZ,"loadfen %s\n", fen); SendToICS(buf); @@ -5196,6 +5322,8 @@ UploadGameEvent () SendToICS(ics_type == ICS_ICC ? "tag result Game in progress\n" : "commit\n"); } +int killX = -1, killY = -1; // [HGM] lion: used for passing e.p. capture square to MakeMove + void CoordsToComputerAlgebraic (int rf, int ff, int rt, int ft, char promoChar, char move[7]) { @@ -5207,6 +5335,7 @@ CoordsToComputerAlgebraic (int rf, int ff, int rt, int ft, char promoChar, char if (promoChar == 'x' || promoChar == NULLCHAR) { sprintf(move, "%c%c%c%c\n", AAA + ff, ONE + rf, AAA + ft, ONE + rt); + if(killX >= 0 && killY >= 0) sprintf(move+4, ";%c%c\n", AAA + killX, ONE + killY); } else { sprintf(move, "%c%c%c%c%c\n", AAA + ff, ONE + rf, AAA + ft, ONE + rt, promoChar); @@ -5227,27 +5356,43 @@ ProcessICSInitScript (FILE *f) } -static int lastX, lastY, selectFlag, dragging; +static int lastX, lastY, lastLeftX, lastLeftY, selectFlag; +int dragging; +static ClickType lastClickType; + +int +Partner (ChessSquare *p) +{ // change piece into promotion partner if one shogi-promotes to the other + int stride = gameInfo.variant == VariantChu ? 22 : 11; + ChessSquare partner; + partner = (*p/stride & 1 ? *p - stride : *p + stride); + if(PieceToChar(*p) != '+' && PieceToChar(partner) != '+') return 0; + *p = partner; + return 1; +} void Sweep (int step) { ChessSquare king = WhiteKing, pawn = WhitePawn, last = promoSweep; + static int toggleFlag; if(gameInfo.variant == VariantKnightmate) king = WhiteUnicorn; if(gameInfo.variant == VariantSuicide || gameInfo.variant == VariantGiveaway) king = EmptySquare; if(promoSweep >= BlackPawn) king = WHITE_TO_BLACK king, pawn = WHITE_TO_BLACK pawn; if(gameInfo.variant == VariantSpartan && pawn == BlackPawn) pawn = BlackLance, king = EmptySquare; - if(fromY != BOARD_HEIGHT-2 && fromY != 1) pawn = EmptySquare; + if(fromY != BOARD_HEIGHT-2 && fromY != 1 && gameInfo.variant != VariantChuChess) pawn = EmptySquare; + if(!step) toggleFlag = Partner(&last); // piece has shogi-promotion do { - promoSweep -= step; + if(step && !(toggleFlag && Partner(&promoSweep))) promoSweep -= step; if(promoSweep == EmptySquare) promoSweep = BlackPawn; // wrap else if((int)promoSweep == -1) promoSweep = WhiteKing; else if(promoSweep == BlackPawn && step < 0) promoSweep = WhitePawn; else if(promoSweep == WhiteKing && step > 0) promoSweep = BlackKing; if(!step) step = -1; } while(PieceToChar(promoSweep) == '.' || PieceToChar(promoSweep) == '~' || promoSweep == pawn || - appData.testLegality && (promoSweep == king || - gameInfo.variant == VariantShogi && promoSweep != PROMOTED last && last != PROMOTED promoSweep && last != promoSweep)); + !toggleFlag && PieceToChar(promoSweep) == '+' || // skip promoted versions of other + appData.testLegality && (promoSweep == king || gameInfo.variant != VariantChuChess && + (promoSweep == WhiteLion || promoSweep == BlackLion))); if(toX >= 0) { int victim = boards[currentMove][toY][toX]; boards[currentMove][toY][toX] = promoSweep; @@ -5351,6 +5496,7 @@ ParseOneMove (char *move, int moveNum, ChessMove *moveType, int *fromX, int *fro case WhiteNonPromotion: case BlackNonPromotion: case NormalMove: + case FirstLeg: case WhiteCapturesEnPassant: case BlackCapturesEnPassant: case WhiteKingSideCastle: @@ -5384,7 +5530,8 @@ ParseOneMove (char *move, int moveNum, ChessMove *moveType, int *fromX, int *fro if (appData.testLegality) { return (*moveType != IllegalMove); } else { - return !(*fromX == *toX && *fromY == *toY) && boards[moveNum][*fromY][*fromX] != EmptySquare && + return !(*fromX == *toX && *fromY == *toY && killX < 0) && boards[moveNum][*fromY][*fromX] != EmptySquare && + // [HGM] lion: if this is a double move we are less critical WhiteOnMove(moveNum) == (boards[moveNum][*fromY][*fromX] < BlackPawn); } @@ -5527,10 +5674,13 @@ LoadMultiPV (int x, int y, char *buf, int index, int *start, int *end, int pane) } else if(strstr(buf+lineStart, "exclude:") == buf+lineStart) { // exclude moves clicked ExcludeClick(origIndex - lineStart); return FALSE; + } else if(!strncmp(buf+lineStart, "dep\t", 4)) { // column headers clicked + Collapse(origIndex - lineStart); + return FALSE; } ParsePV(buf+startPV, FALSE, gameMode != AnalyzeMode); *start = startPV; *end = index-1; - extendGame = (gameMode == AnalyzeMode && appData.autoExtend); + extendGame = (gameMode == AnalyzeMode && appData.autoExtend && origIndex - startPV < 5); return TRUE; } @@ -5842,13 +5992,13 @@ void InitPosition (int redraw) { ChessSquare (* pieces)[BOARD_FILES]; - int i, j, pawnRow, overrule, + int i, j, pawnRow=1, pieceRows=1, overrule, oldx = gameInfo.boardWidth, oldy = gameInfo.boardHeight, oldh = gameInfo.holdingsWidth; static int oldv; - if(appData.icsActive) shuffleOpenings = FALSE; // [HGM] shuffle: in ICS mode, only shuffle on ICS request + if(appData.icsActive) shuffleOpenings = appData.fischerCastling = FALSE; // [HGM] shuffle: in ICS mode, only shuffle on ICS request /* [AS] Initialize pv info list [HGM] and game status */ { @@ -5889,6 +6039,7 @@ InitPosition (int redraw) switch (gameInfo.variant) { case VariantFischeRandom: shuffleOpenings = TRUE; + appData.fischerCastling = TRUE; default: break; case VariantShatranj: @@ -5899,9 +6050,13 @@ InitPosition (int redraw) case VariantMakruk: pieces = makrukArray; nrCastlingRights = 0; - startedFromSetupPosition = TRUE; SetCharTable(pieceToChar, "PN.R.M....SKpn.r.m....sk"); break; + case VariantASEAN: + pieces = aseanArray; + nrCastlingRights = 0; + SetCharTable(pieceToChar, "PN.R.Q....BKpn.r.q....bk"); + break; case VariantTwoKings: pieces = twoKingsArray; break; @@ -5915,6 +6070,7 @@ InitPosition (int redraw) break; case VariantCapaRandom: shuffleOpenings = TRUE; + appData.fischerCastling = TRUE; case VariantCapablanca: pieces = CapablancaArray; gameInfo.boardWidth = 10; @@ -5962,6 +6118,14 @@ InitPosition (int redraw) nrCastlingRights = 0; SetCharTable(pieceToChar, "PNBRLS...G.++++++Kpnbrls...g.++++++k"); break; + case VariantChu: + pieces = ChuArray; pieceRows = 3; + gameInfo.boardWidth = 12; + gameInfo.boardHeight = 12; + nrCastlingRights = 0; + SetCharTable(pieceToChar, "P.BRQSEXOGCATHD.VMLIFN+.++.++++++++++.+++++K" + "p.brqsexogcathd.vmlifn+.++.++++++++++.+++++k"); + break; case VariantCourier: pieces = CourierArray; gameInfo.boardWidth = 12; @@ -5976,6 +6140,16 @@ InitPosition (int redraw) pieces = SpartanArray; SetCharTable(pieceToChar, "PNBRQ................K......lwg.....c...h..k"); break; + case VariantLion: + pieces = lionArray; + SetCharTable(pieceToChar, "PNBRQ................LKpnbrq................lk"); + break; + case VariantChuChess: + pieces = ChuChessArray; + gameInfo.boardWidth = 10; + gameInfo.boardHeight = 10; + SetCharTable(pieceToChar, "PNBRQ.....M.+++......LKpnbrq.....m.+++......lk"); + break; case VariantFairy: pieces = fairyArray; SetCharTable(pieceToChar, "PNBRQFEACWMOHIJGDVLSUKpnbrqfeacwmohijgdvlsuk"); @@ -6030,7 +6204,9 @@ InitPosition (int redraw) pawnRow = gameInfo.boardHeight - 7; /* seems to work in all common variants */ if(pawnRow < 1) pawnRow = 1; - if(gameInfo.variant == VariantMakruk || gameInfo.variant == VariantGrand) pawnRow = 2; + if(gameInfo.variant == VariantMakruk || gameInfo.variant == VariantASEAN || + gameInfo.variant == VariantGrand || gameInfo.variant == VariantChuChess) pawnRow = 2; + if(gameInfo.variant == VariantChu) pawnRow = 3; /* User pieceToChar list overrules defaults */ if(appData.pieceToCharTable != NULL) @@ -6044,7 +6220,7 @@ InitPosition (int redraw) initialPosition[i][j] = s; if(j < BOARD_LEFT || j >= BOARD_RGHT || overrule) continue; - initialPosition[gameInfo.variant == VariantGrand][j] = pieces[0][j-gameInfo.holdingsWidth]; + initialPosition[gameInfo.variant == VariantGrand || gameInfo.variant == VariantChuChess][j] = pieces[0][j-gameInfo.holdingsWidth]; initialPosition[pawnRow][j] = WhitePawn; initialPosition[BOARD_HEIGHT-pawnRow-1][j] = gameInfo.variant == VariantSpartan ? BlackLance : BlackPawn; if(gameInfo.variant == VariantXiangqi) { @@ -6057,14 +6233,24 @@ InitPosition (int redraw) } } } - if(gameInfo.variant == VariantGrand) { + if(gameInfo.variant == VariantChu) { + if(j == (BOARD_WIDTH-2)/3 || j == BOARD_WIDTH - (BOARD_WIDTH+1)/3) + initialPosition[pawnRow+1][j] = WhiteCobra, + initialPosition[BOARD_HEIGHT-pawnRow-2][j] = BlackCobra; + for(i=1; i=BOARD_RGHT-1) { initialPosition[0][j] = WhiteRook; initialPosition[BOARD_HEIGHT-1][j] = BlackRook; } } - initialPosition[BOARD_HEIGHT-1-(gameInfo.variant == VariantGrand)][j] = pieces[1][j-gameInfo.holdingsWidth]; + initialPosition[BOARD_HEIGHT-1-(gameInfo.variant == VariantGrand || gameInfo.variant == VariantChuChess)][j] = pieces[1][j-gameInfo.holdingsWidth]; } + if(gameInfo.variant == VariantChuChess) initialPosition[0][BOARD_WIDTH/2] = WhiteKing, initialPosition[BOARD_HEIGHT-1][BOARD_WIDTH/2-1] = BlackKing; if( (gameInfo.variant == VariantShogi) && !overrule ) { j=BOARD_LEFT+1; @@ -6139,7 +6325,7 @@ SendBoard (ChessProgramState *cps, int moveNum) char message[MSG_SIZ]; if (cps->useSetboard) { - char* fen = PositionToFEN(moveNum, cps->fenOverride); + char* fen = PositionToFEN(moveNum, cps->fenOverride, 1); snprintf(message, MSG_SIZ,"setboard %s\n", fen); SendToProgram(message, cps); free(fen); @@ -6322,7 +6508,8 @@ ChessSquare DefaultPromoChoice (int white) { ChessSquare result; - if(gameInfo.variant == VariantShatranj || gameInfo.variant == VariantCourier || gameInfo.variant == VariantMakruk) + if(gameInfo.variant == VariantShatranj || gameInfo.variant == VariantCourier || + gameInfo.variant == VariantMakruk || gameInfo.variant == VariantASEAN) result = WhiteFerz; // no choice else if(gameInfo.variant == VariantSuicide || gameInfo.variant == VariantGiveaway) result= WhiteKing; // in Suicide Q is the last thing we want @@ -6341,7 +6528,7 @@ HasPromotionChoice (int fromX, int fromY, int toX, int toY, char *promoChoice, i /* [HGM] rewritten IsPromotion to only flag promotions that offer a choice */ /* [HGM] add Shogi promotions */ int promotionZoneSize=1, highestPromotingPiece = (int)WhitePawn; - ChessSquare piece; + ChessSquare piece, partner; ChessMove moveType; Boolean premove; @@ -6353,15 +6540,19 @@ HasPromotionChoice (int fromX, int fromY, int toX, int toY, char *promoChoice, i return FALSE; piece = boards[currentMove][fromY][fromX]; - if(gameInfo.variant == VariantShogi) { + if(gameInfo.variant == VariantChu) { + int p = piece >= BlackPawn ? BLACK_TO_WHITE piece : piece; promotionZoneSize = BOARD_HEIGHT/3; - highestPromotingPiece = (int)WhiteFerz; - } else if(gameInfo.variant == VariantMakruk || gameInfo.variant == VariantGrand) { + highestPromotingPiece = (p >= WhiteLion || PieceToChar(piece + 22) == '.') ? WhitePawn : WhiteLion; + } else if(gameInfo.variant == VariantShogi || gameInfo.variant == VariantChuChess) { + promotionZoneSize = BOARD_HEIGHT/3; + highestPromotingPiece = (int)WhiteAlfil; + } else if(gameInfo.variant == VariantMakruk || gameInfo.variant == VariantGrand || gameInfo.variant == VariantChuChess) { promotionZoneSize = 3; } - // Treat Lance as Pawn when it is not representing Amazon - if(gameInfo.variant != VariantSuper) { + // Treat Lance as Pawn when it is not representing Amazon or Lance + if(gameInfo.variant != VariantSuper && gameInfo.variant != VariantChu) { if(piece == WhiteLance) piece = WhitePawn; else if(piece == BlackLance) piece = BlackPawn; } @@ -6370,10 +6561,13 @@ HasPromotionChoice (int fromX, int fromY, int toX, int toY, char *promoChoice, i if((int)piece >= BlackPawn) { if(toY >= promotionZoneSize && fromY >= promotionZoneSize) return FALSE; + if(fromY < promotionZoneSize && gameInfo.variant == VariantChuChess) return FALSE; highestPromotingPiece = WHITE_TO_BLACK highestPromotingPiece; } else { if( toY < BOARD_HEIGHT - promotionZoneSize && fromY < BOARD_HEIGHT - promotionZoneSize) return FALSE; + if(fromY >= BOARD_HEIGHT - promotionZoneSize && gameInfo.variant == VariantChuChess) + return FALSE; } if( (int)piece > highestPromotingPiece ) return FALSE; // non-promoting piece @@ -6407,8 +6601,13 @@ HasPromotionChoice (int fromX, int fromY, int toX, int toY, char *promoChoice, i } // we either have a choice what to promote to, or (in Shogi) whether to promote - if(gameInfo.variant == VariantShatranj || gameInfo.variant == VariantCourier || gameInfo.variant == VariantMakruk) { - *promoChoice = PieceToChar(BlackFerz); // no choice + if(gameInfo.variant == VariantShatranj || gameInfo.variant == VariantCourier || + gameInfo.variant == VariantMakruk || gameInfo.variant == VariantASEAN) { + ChessSquare p=BlackFerz; // no choice + while(p < EmptySquare) { //but make sure we use piece that exists + *promoChoice = PieceToChar(p++); + if(*promoChoice != '.') break; + } return FALSE; } // no sense asking what we must promote to if it is going to explode... @@ -6418,7 +6617,9 @@ HasPromotionChoice (int fromX, int fromY, int toX, int toY, char *promoChoice, i } // give caller the default choice even if we will not make it *promoChoice = ToLower(PieceToChar(defaultPromoChoice)); - if(gameInfo.variant == VariantShogi) *promoChoice = (defaultPromoChoice == piece ? '=' : '+'); + partner = piece; // pieces can promote if the pieceToCharTable says so + if(IS_SHOGI(gameInfo.variant)) *promoChoice = (defaultPromoChoice == piece && sweepSelect ? '=' : '+'); // obsolete? + else if(Partner(&partner)) *promoChoice = (defaultPromoChoice == piece && sweepSelect ? NULLCHAR : '+'); if( sweepSelect && gameInfo.variant != VariantGreat && gameInfo.variant != VariantGrand && gameInfo.variant != VariantSuper) return FALSE; @@ -6429,7 +6630,8 @@ HasPromotionChoice (int fromX, int fromY, int toX, int toY, char *promoChoice, i gameMode == IcsPlayingBlack && WhiteOnMove(currentMove); if(appData.testLegality && !premove) { moveType = LegalityTest(boards[currentMove], PosFlags(currentMove), - fromY, fromX, toY, toX, gameInfo.variant == VariantShogi ? '+' : NULLCHAR); + fromY, fromX, toY, toX, IS_SHOGI(gameInfo.variant) || gameInfo.variant == VariantChuChess ? '+' : NULLCHAR); + if(moveType == IllegalMove) *promoChoice = NULLCHAR; // could be the fact we promoted was illegal if(moveType != WhitePromotion && moveType != BlackPromotion) return FALSE; } @@ -6620,6 +6822,7 @@ int lastLoadGameUseList = FALSE; char lastLoadGameTitle[MSG_SIZ], lastLoadPositionTitle[MSG_SIZ]; ChessMove lastLoadGameStart = EndOfFile; int doubleClick; +Boolean addToBookFlag; void UserMoveEvent(int fromX, int fromY, int toX, int toY, int promoChar) @@ -6742,6 +6945,13 @@ UserMoveEvent(int fromX, int fromY, int toX, int toY, int promoChar) DrawPosition(FALSE, boards[currentMove]); return; } else if (toX >= 0 && toY >= 0) { + if(!appData.pieceMenu && toX == fromX && toY == fromY && boards[0][rf][ff] != EmptySquare) { + ChessSquare q, p = boards[0][rf][ff]; + if(p >= BlackPawn) p = BLACK_TO_WHITE p; + if(CHUPROMOTED p < BlackPawn) p = q = CHUPROMOTED boards[0][rf][ff]; + else p = CHUDEMOTED (q = boards[0][rf][ff]); + if(PieceToChar(q) == '+') gatingPiece = p; + } boards[0][toY][toX] = boards[0][fromY][fromX]; if(fromX == BOARD_LEFT-2) { // handle 'moves' out of holdings if(boards[0][fromY][0] != EmptySquare) { @@ -6762,7 +6972,7 @@ UserMoveEvent(int fromX, int fromY, int toX, int toY, int promoChar) return; } - if(toX < 0 || toY < 0) return; + if((toX < 0 || toY < 0) && (fromY != DROP_RANK || fromX != EmptySquare)) return; pup = boards[currentMove][toY][toX]; /* [HGM] If move started in holdings, it means a drop. Convert to standard form */ @@ -6782,7 +6992,7 @@ UserMoveEvent(int fromX, int fromY, int toX, int toY, int promoChar) moveType = LegalityTest(boards[currentMove], PosFlags(currentMove), fromY, fromX, toY, toX, promoChar); - if(fromY == DROP_RANK && fromX == EmptySquare && (gameMode == AnalyzeMode || gameMode == EditGame)) moveType = NormalMove; + if(fromY == DROP_RANK && fromX == EmptySquare && (gameMode == AnalyzeMode || gameMode == EditGame || PosFlags(0) & F_NULL_MOVE)) moveType = NormalMove; /* [HGM] but possibly ignore an IllegalMove result */ if (appData.testLegality) { @@ -6799,6 +7009,16 @@ UserMoveEvent(int fromX, int fromY, int toX, int toY, int promoChar) return; } + if(addToBookFlag) { // adding moves to book + char buf[MSG_SIZ], move[MSG_SIZ]; + CoordsToAlgebraic(boards[currentMove], PosFlags(currentMove), fromY, fromX, toY, toX, promoChar, move); + snprintf(buf, MSG_SIZ, " 0.0%% 1 %s\n", move); + AddBookMove(buf); + addToBookFlag = FALSE; + ClearHighlights(); + return; + } + FinishMove(moveType, fromX, fromY, toX, toY, promoChar); } @@ -6998,27 +7218,66 @@ FinishMove (ChessMove moveType, int fromX, int fromY, int toX, int toY, int prom } void +MarkByFEN(char *fen) +{ + int r, f; + if(!appData.markers || !appData.highlightDragging) return; + for(r=0; r= 'A' && *fen <= 'Z') legal[r][f] = 1; else + if(*fen >= 'a' && *fen <= 'z') *fen += 'A' - 'a'; + if(*fen == '/' && f > BOARD_LEFT) f = BOARD_LEFT, r--; else + if(*fen == 'T') marker[r][f++] = 0; else + if(*fen == 'Y') marker[r][f++] = 1; else + if(*fen == 'G') marker[r][f++] = 3; else + if(*fen == 'B') marker[r][f++] = 4; else + if(*fen == 'C') marker[r][f++] = 5; else + if(*fen == 'M') marker[r][f++] = 6; else + if(*fen == 'W') marker[r][f++] = 7; else + if(*fen == 'D') marker[r][f++] = 8; else + if(*fen == 'R') marker[r][f++] = 2; else { + while(*fen <= '9' && *fen >= '0') s = 10*s + *fen++ - '0'; + f += s; fen -= s>0; + } + while(f >= BOARD_RGHT) f -= BOARD_RGHT - BOARD_LEFT, r--; + if(r < 0) break; + fen++; + } + DrawPosition(TRUE, NULL); +} + +static char baseMarker[BOARD_RANKS][BOARD_FILES], baseLegal[BOARD_RANKS][BOARD_FILES]; + +void Mark (Board board, int flags, ChessMove kind, int rf, int ff, int rt, int ft, VOIDSTAR closure) { typedef char Markers[BOARD_RANKS][BOARD_FILES]; Markers *m = (Markers *) closure; - if(rf == fromY && ff == fromX) + if(rf == fromY && ff == fromX && (killX < 0 && !(rt == rf && ft == ff) || abs(ft-killX) < 2 && abs(rt-killY) < 2)) (*m)[rt][ft] = 1 + (board[rt][ft] != EmptySquare || kind == WhiteCapturesEnPassant - || kind == BlackCapturesEnPassant); + || kind == BlackCapturesEnPassant) + 3*(kind == FirstLeg && killX < 0); else if(flags & F_MANDATORY_CAPTURE && board[rt][ft] != EmptySquare) (*m)[rt][ft] = 3; } +static int hoverSavedValid; + void MarkTargetSquares (int clear) { - int x, y; - if(clear) // no reason to ever suppress clearing - for(x=0; x1) capt++; @@ -7048,19 +7307,59 @@ ChessSquare gatingPiece = EmptySquare; // exported to front-end, for dragging int CanPromote (ChessSquare piece, int y) { + int zone = (gameInfo.variant == VariantChuChess ? 3 : 1); if(gameMode == EditPosition) return FALSE; // no promotions when editing position // some variants have fixed promotion piece, no promotion at all, or another selection mechanism - if(gameInfo.variant == VariantShogi || gameInfo.variant == VariantXiangqi || + if(IS_SHOGI(gameInfo.variant) || gameInfo.variant == VariantXiangqi || gameInfo.variant == VariantSuper || gameInfo.variant == VariantGreat || gameInfo.variant == VariantShatranj || gameInfo.variant == VariantCourier || - gameInfo.variant == VariantMakruk) return FALSE; - return (piece == BlackPawn && y == 1 || - piece == WhitePawn && y == BOARD_HEIGHT-2 || + gameInfo.variant == VariantMakruk || gameInfo.variant == VariantASEAN) return FALSE; + return (piece == BlackPawn && y <= zone || + piece == WhitePawn && y >= BOARD_HEIGHT-1-zone || piece == BlackLance && y == 1 || piece == WhiteLance && y == BOARD_HEIGHT-2 ); } void +HoverEvent (int xPix, int yPix, int x, int y) +{ + static int oldX = -1, oldY = -1, oldFromX = -1, oldFromY = -1; + int r, f; + if(!first.highlight) return; + if(fromX != oldFromX || fromY != oldFromY) oldX = oldY = -1; // kludge to fake entry on from-click + if(x == oldX && y == oldY) return; // only do something if we enter new square + oldFromX = fromX; oldFromY = fromY; + if(oldX == -1 && oldY == -1 && x == fromX && y == fromY) { // record markings after from-change + for(r=0; r= BOARD_RGHT) return; } - if (clickType == Release && x == fromX && y == fromY) { + if (clickType == Release && x == fromX && y == fromY && killX < 0) { DragPieceEnd(xPix, yPix); dragging = 0; if(clearFlag) { // a deferred attempt to click-click move an empty square on top of a piece @@ -7270,26 +7574,42 @@ LeftClick (ClickType clickType, int xPix, int yPix) clearFlag = 0; + if(gameMode != EditPosition && !appData.testLegality && !legal[y][x] && (x != killX || y != killY) && !sweepSelecting) { + if(dragging) DragPieceEnd(xPix, yPix), dragging = 0; + DisplayMessage(_("only marked squares are legal"),""); + DrawPosition(TRUE, NULL); + return; // ignore to-click + } + /* we now have a different from- and (possibly off-board) to-square */ /* Completed move */ if(!sweepSelecting) { toX = x; toY = y; - } else sweepSelecting = 0; // this must be the up-click corresponding to the down-click that started the sweep + } + + piece = boards[currentMove][fromY][fromX]; saveAnimate = appData.animate; if (clickType == Press) { + if(gameInfo.variant == VariantChuChess && piece != WhitePawn && piece != BlackPawn) defaultPromoChoice = piece; if(gameMode == EditPosition && boards[currentMove][fromY][fromX] == EmptySquare) { // must be Edit Position mode with empty-square selected fromX = x; fromY = y; DragPieceBegin(xPix, yPix, FALSE); dragging = 1; // consider this a new attempt to drag if(x >= BOARD_LEFT && x < BOARD_RGHT) clearFlag = 1; // and defer click-click move of empty-square to up-click return; } - if(HasPromotionChoice(fromX, fromY, toX, toY, &promoChoice, FALSE)) { + if(dragging == 2) { // [HGM] lion: just turn buttonless drag into normal drag, and let release to the job + return; + } + if(x == killX && y == killY) { // second click on this square, which was selected as first-leg target + killX = killY = -1; // this informs us no second leg is coming, so treat as to-click without intermediate + } else + if(marker[y][x] == 5) return; // [HGM] lion: to-click on cyan square; defer action to release + if(legal[y][x] == 2 || HasPromotionChoice(fromX, fromY, toX, toY, &promoChoice, FALSE)) { if(appData.sweepSelect) { - ChessSquare piece = boards[currentMove][fromY][fromX]; promoSweep = defaultPromoChoice; - if(PieceToChar(PROMOTED piece) == '+') promoSweep = PROMOTED piece; + if(gameInfo.variant != VariantChuChess && PieceToChar(CHUPROMOTED piece) == '+') promoSweep = CHUPROMOTED piece; selectFlag = 0; lastX = xPix; lastY = yPix; Sweep(0); // Pawn that is going to promote: preview promotion piece sweepSelecting = 1; @@ -7304,6 +7624,13 @@ LeftClick (ClickType clickType, int xPix, int yPix) } else { ClearHighlights(); } + } else if(sweepSelecting) { // this must be the up-click corresponding to the down-click that started the sweep + sweepSelecting = 0; appData.animate = FALSE; // do not animate, a selected piece already on to-square + if (appData.animate || appData.highlightLastMove) { + SetHighlights(fromX, fromY, toX, toY); + } else { + ClearHighlights(); + } } else { #if 0 // [HGM] this must be done after the move is made, as with arrow it could lead to a board redraw with piece still on from square @@ -7314,6 +7641,18 @@ LeftClick (ClickType clickType, int xPix, int yPix) ClearHighlights(); } #endif + if(gameInfo.variant == VariantChuChess && piece != WhitePawn && piece != BlackPawn) defaultPromoChoice = piece; + if(marker[y][x] == 5) { // [HGM] lion: this was the release of a to-click or drag on a cyan square + dragging *= 2; // flag button-less dragging if we are dragging + MarkTargetSquares(1); + if(x == killX && y == killY) killX = killY = -1; else { + killX = x; killY = y; //remeber this square as intermediate + ReportClick("put", x, y); // and inform engine + ReportClick("lift", x, y); + MarkTargetSquares(0); + return; + } + } DragPieceEnd(xPix, yPix); dragging = 0; /* Don't animate move and drag both */ appData.animate = FALSE; @@ -7349,6 +7688,7 @@ LeftClick (ClickType clickType, int xPix, int yPix) // off-board moves should not be highlighted if(x < 0 || y < 0) ClearHighlights(); + else ReportClick("put", x, y); if(gatingPiece != EmptySquare && gameInfo.variant == VariantSChess) promoChoice = ToLower(PieceToChar(gatingPiece)); @@ -7368,7 +7708,7 @@ LeftClick (ClickType clickType, int xPix, int yPix) DisplayMessage("Click in holdings to choose piece", ""); return; } - PromotionPopUp(); + PromotionPopUp(promoChoice); } else { int oldMove = currentMove; UserMoveEvent(fromX, fromY, toX, toY, promoChoice); @@ -8001,11 +8341,66 @@ Adjudicate (ChessProgramState *cps) return 0; } +typedef int (CDECL *PPROBE_EGBB) (int player, int *piece, int *square); +typedef int (CDECL *PLOAD_EGBB) (char *path, int cache_size, int load_options); +static int egbbCode[] = { 6, 5, 4, 3, 2, 1 }; + +static int +BitbaseProbe () +{ + int pieces[10], squares[10], cnt=0, r, f, res; + static int loaded; + static PPROBE_EGBB probeBB; + if(!appData.testLegality) return 10; + if(BOARD_HEIGHT != 8 || BOARD_RGHT-BOARD_LEFT != 8) return 12; + if(gameInfo.holdingsSize && gameInfo.variant != VariantSuper && gameInfo.variant != VariantSChess) return 12; + if(loaded == 2 && forwardMostMove < 2) loaded = 0; // retry on new game + for(r=0; r= BlackPawn); + int type = piece - black*BlackPawn; + if(piece == EmptySquare) continue; + if(type != WhiteKing && type > WhiteQueen) return 12; // unorthodox piece + if(type == WhiteKing) type = WhiteQueen + 1; + type = egbbCode[type]; + squares[cnt] = r*(BOARD_RGHT - BOARD_LEFT) + f - BOARD_LEFT; + pieces[cnt] = type + black*6; + if(++cnt > 5) return 11; + } + pieces[cnt] = squares[cnt] = 0; + // probe EGBB + if(loaded == 2) return 13; // loading failed before + if(loaded == 0) { + char *p, *path = strstr(appData.egtFormats, "scorpio:"), buf[MSG_SIZ]; + HMODULE lib; + PLOAD_EGBB loadBB; + loaded = 2; // prepare for failure + if(!path) return 13; // no egbb installed + strncpy(buf, path + 8, MSG_SIZ); + if(p = strchr(buf, ',')) *p = NULLCHAR; else p = buf + strlen(buf); + snprintf(p, MSG_SIZ - strlen(buf), "%c%s", SLASH, EGBB_NAME); + lib = LoadLibrary(buf); + if(!lib) { DisplayError(_("could not load EGBB library"), 0); return 13; } + loadBB = (PLOAD_EGBB) GetProcAddress(lib, "load_egbb_xmen"); + probeBB = (PPROBE_EGBB) GetProcAddress(lib, "probe_egbb_xmen"); + if(!loadBB || !probeBB) { DisplayError(_("wrong EGBB version"), 0); return 13; } + p[1] = NULLCHAR; loadBB(buf, 64*1028, 2); // 2 = SMART_LOAD + loaded = 1; // success! + } + res = probeBB(forwardMostMove & 1, pieces, squares); + return res > 0 ? 1 : res < 0 ? -1 : 0; +} + char * SendMoveToBookUser (int moveNr, ChessProgramState *cps, int initial) { // [HGM] book: this routine intercepts moves to simulate book replies char *bookHit = NULL; + if(cps->drawDepth && BitbaseProbe() == 0) { // [HG} egbb: reduce depth in drawn position + char buf[MSG_SIZ]; + snprintf(buf, MSG_SIZ, "sd %d\n", cps->drawDepth); + SendToProgram(buf, cps); + } //first determine if the incoming move brings opponent into his book if(appData.usePolyglotBook && (cps == &first ? !appData.firstHasOwnBookUCI : !appData.secondHasOwnBookUCI)) bookHit = ProbeBook(moveNr+1, appData.polyglotBook); // returns move @@ -8088,11 +8483,12 @@ static char stashedInputMove[MSG_SIZ]; void HandleMachineMove (char *message, ChessProgramState *cps) { + static char firstLeg[20]; char machineMove[MSG_SIZ], buf1[MSG_SIZ*10], buf2[MSG_SIZ]; char realname[MSG_SIZ]; int fromX, fromY, toX, toY; ChessMove moveType; - char promoChar; + char promoChar, roar; char *p, *pv=buf1; int machineWhite, oldError; char *bookHit; @@ -8230,14 +8626,32 @@ FakeBookMove: // [HGM] book: we jump here to simulate machine moves after book h } if(cps->alphaRank) AlphaRank(machineMove, 4); + + // [HGM] lion: (some very limited) support for Alien protocol + killX = killY = -1; + if(machineMove[strlen(machineMove)-1] == ',') { // move ends in coma: non-final leg of composite move + safeStrCpy(firstLeg, machineMove, 20); // just remember it for processing when second leg arrives + return; + } else if(firstLeg[0]) { // there was a previous leg; + // only support case where same piece makes two step (and don't even test that!) + char buf[20], *p = machineMove+1, *q = buf+1, f; + safeStrCpy(buf, machineMove, 20); + while(isdigit(*q)) q++; // find start of to-square + safeStrCpy(machineMove, firstLeg, 20); + while(isdigit(*p)) p++; + safeStrCpy(p, q, 20); // glue to-square of second leg to from-square of first, to process over-all move + sscanf(buf, "%c%d", &f, &killY); killX = f - AAA; killY -= ONE - '0'; // pass intermediate square to MakeMove in global + firstLeg[0] = NULLCHAR; + } + if (!ParseOneMove(machineMove, forwardMostMove, &moveType, &fromX, &fromY, &toX, &toY, &promoChar)) { /* Machine move could not be parsed; ignore it. */ snprintf(buf1, MSG_SIZ*10, _("Illegal move \"%s\" from %s machine"), machineMove, _(cps->which)); DisplayMoveError(buf1); - snprintf(buf1, MSG_SIZ*10, "Xboard: Forfeit due to invalid move: %s (%c%c%c%c) res=%d", - machineMove, fromX+AAA, fromY+ONE, toX+AAA, toY+ONE, moveType); + snprintf(buf1, MSG_SIZ*10, "Xboard: Forfeit due to invalid move: %s (%c%c%c%c via %c%c) res=%d", + machineMove, fromX+AAA, fromY+ONE, toX+AAA, toY+ONE, killX+AAA, killY+ONE, moveType); if (gameMode == TwoMachinesPlay) { GameEnds(machineWhite ? BlackWins : WhiteWins, buf1, GE_XBOARD); @@ -8260,7 +8674,7 @@ FakeBookMove: // [HGM] book: we jump here to simulate machine moves after book h GameEnds(machineWhite ? BlackWins : WhiteWins, buf1, GE_XBOARD); return; - } else if(gameInfo.variant != VariantFischeRandom && gameInfo.variant != VariantCapaRandom) + } else if(!appData.fischerCastling) /* [HGM] Kludge to handle engines that send FRC-style castling when they shouldn't (like TSCP-Gothic) */ switch(moveType) { @@ -8292,8 +8706,19 @@ FakeBookMove: // [HGM] book: we jump here to simulate machine moves after book h MakeMove(fromX, fromY, toX, toY, promoChar);/*updates forwardMostMove*/ + /* Test suites abort the 'game' after one move */ + if(*appData.finger) { + static FILE *f; + char *fen = PositionToFEN(backwardMostMove, NULL, 0); // no counts in EPD + if(!f) f = fopen(appData.finger, "w"); + if(f) fprintf(f, "%s bm %s;\n", fen, parseList[backwardMostMove]), fflush(f); + else { DisplayFatalError("Bad output file", errno, 0); return; } + free(fen); + GameEnds(GameUnfinished, NULL, GE_XBOARD); + } + /* [AS] Adjudicate game if needed (note: remember that forwardMostMove now points past the last move) */ - if( gameMode == TwoMachinesPlay && adjudicateLossThreshold != 0 && forwardMostMove >= adjudicateLossPlies ) { + if( gameMode == TwoMachinesPlay && appData.adjudicateLossThreshold != 0 && forwardMostMove >= adjudicateLossPlies ) { int count = 0; while( count < adjudicateLossPlies ) { @@ -8302,8 +8727,8 @@ FakeBookMove: // [HGM] book: we jump here to simulate machine moves after book h if( count & 1 ) { score = -score; /* Flip score for winning side */ } - - if( score > adjudicateLossThreshold ) { +printf("score=%d count=%d\n",score,count); + if( score > appData.adjudicateLossThreshold ) { break; } @@ -8347,7 +8772,6 @@ FakeBookMove: // [HGM] book: we jump here to simulate machine moves after book h (unsigned int)programStats.nodes / (10*abs(programStats.time) + 1.), programStats.movelist); SendToICS(buf); -if(appData.debugMode) fprintf(debugFP, "nodes = %d, %lld\n", (int) programStats.nodes, programStats.nodes); } } #endif @@ -8379,10 +8803,12 @@ if(appData.debugMode) fprintf(debugFP, "nodes = %d, %lld\n", (int) programStats. cps->other->maybeThinking = TRUE; } + roar = (killX >= 0 && IS_LION(boards[forwardMostMove][toY][toX])); + ShowMove(fromX, fromY, toX, toY); /*updates currentMove*/ if (!pausing && appData.ringBellAfterMoves) { - RingBell(); + if(!roar) RingBell(); } /* @@ -8433,14 +8859,29 @@ if(appData.debugMode) fprintf(debugFP, "nodes = %d, %lld\n", (int) programStats. } if (!strncmp(message, "setup ", 6) && - (!appData.testLegality || gameInfo.variant == VariantFairy || NonStandardBoardSize()) + (!appData.testLegality || gameInfo.variant == VariantFairy || gameInfo.variant == VariantUnknown || + NonStandardBoardSize(gameInfo.variant, gameInfo.boardWidth, gameInfo.boardHeight, gameInfo.holdingsSize)) ) { // [HGM] allow first engine to define opening position - int dummy, s=6; char buf[MSG_SIZ]; + int dummy, w, h, hand, s=6; char buf[MSG_SIZ], varName[MSG_SIZ]; if(appData.icsActive || forwardMostMove != 0 || cps != &first) return; - if(sscanf(message, "setup (%s", buf) == 1) s = 8 + strlen(buf), buf[s-9] = NULLCHAR, SetCharTable(pieceToChar, buf); + *buf = NULLCHAR; + if(sscanf(message, "setup (%s", buf) == 1) { + s = 8 + strlen(buf), buf[s-9] = NULLCHAR, SetCharTable(pieceToChar, buf); + ASSIGN(appData.pieceToCharTable, buf); + } if(startedFromSetupPosition) return; - if(sscanf(message+s, "%dx%d+%d", &dummy, &dummy, &dummy) == 3) while(message[s] && message[s++] != ' '); // for compatibility with Alien Edition - ParseFEN(boards[0], &dummy, message+s); + dummy = sscanf(message+s, "%dx%d+%d_%s", &w, &h, &hand, varName); + if(dummy >= 3) { + while(message[s] && message[s++] != ' '); + if(BOARD_HEIGHT != h || BOARD_WIDTH != w + 4*(hand != 0) || gameInfo.holdingsSize != hand || + dummy == 4 && gameInfo.variant != StringToVariant(varName) ) { // engine wants to change board format or variant + appData.NrFiles = w; appData.NrRanks = h; appData.holdingsSize = hand; + if(dummy == 4) gameInfo.variant = StringToVariant(varName); // parent variant + InitPosition(1); // calls InitDrawingSizes to let new parameters take effect + if(*buf) SetCharTable(pieceToChar, buf); // do again, for it was spoiled by InitPosition + } + } + ParseFEN(boards[0], &dummy, message+s, FALSE); DrawPosition(TRUE, boards[0]); startedFromSetupPosition = TRUE; return; @@ -8453,7 +8894,7 @@ if(appData.debugMode) fprintf(debugFP, "nodes = %d, %lld\n", (int) programStats. GameEnds(GameUnfinished, "Engine aborts game", GE_XBOARD); - if (!ParseFEN(initial_position, &blackPlaysFirst, message + 9)) { + if (!ParseFEN(initial_position, &blackPlaysFirst, message + 9, FALSE)) { DisplayError(_("Bad FEN received from engine"), 0); return ; } else { @@ -8553,6 +8994,36 @@ if(appData.debugMode) fprintf(debugFP, "nodes = %d, %lld\n", (int) programStats. } } if (sscanf(message, "pong %d", &cps->lastPong) == 1) { + if(initPing == cps->lastPong) { + if(gameInfo.variant == VariantUnknown) { + DisplayError(_("Engine did not send setup for non-standard variant"), 0); + *engineVariant = NULLCHAR; appData.variant = VariantNormal; // back to normal as error recovery? + GameEnds(GameUnfinished, NULL, GE_XBOARD); + } + initPing = -1; + } + return; + } + if(!strncmp(message, "highlight ", 10)) { + if(appData.testLegality && appData.markers) return; + MarkByFEN(message+10); // [HGM] alien: allow engine to mark board squares + return; + } + if(!strncmp(message, "click ", 6)) { + char f, c=0; int x, y; // [HGM] alien: allow engine to finish user moves (i.e. engine-driven one-click moving) + if(appData.testLegality || !appData.oneClick) return; + sscanf(message+6, "%c%d%c", &f, &y, &c); + x = f - 'a' + BOARD_LEFT, y -= ONE - '0'; + if(flipView) x = BOARD_WIDTH-1 - x; else y = BOARD_HEIGHT-1 - y; + x = x*squareSize + (x+1)*lineGap + squareSize/2; + y = y*squareSize + (y+1)*lineGap + squareSize/2; + f = first.highlight; first.highlight = 0; // kludge to suppress lift/put in response to own clicks + if(lastClickType == Press) // if button still down, fake release on same square, to be ready for next click + LeftClick(Release, lastLeftX, lastLeftY); + controlKey = (c == ','); + LeftClick(Press, x, y); + LeftClick(Release, x, y); + first.highlight = f; return; } /* @@ -8678,6 +9149,10 @@ if(appData.debugMode) fprintf(debugFP, "nodes = %d, %lld\n", (int) programStats. Don't use it. */ cps->sendTime = 0; } + if (cps->pseudo) { // [HGM] pseudo-engine, granted unusual powers + if (sscanf(message, "wtime %ld\n", &whiteTimeRemaining) == 1 || // adjust clock times + sscanf(message, "btime %ld\n", &blackTimeRemaining) == 1 ) return; + } /* * If chess program startup fails, exit with an error message. @@ -8895,7 +9370,7 @@ if(appData.debugMode) fprintf(debugFP, "nodes = %d, %lld\n", (int) programStats. DisplayInformation(_("Machine accepts your draw offer")); GameEnds(GameIsDrawn, "Draw agreed", GE_XBOARD); } else { - DisplayInformation(_("Machine offers a draw\nSelect Action / Draw to agree")); + DisplayInformation(_("Machine offers a draw.\nSelect Action / Draw to accept.")); } } } @@ -8946,6 +9421,9 @@ if(appData.debugMode) fprintf(debugFP, "nodes = %d, %lld\n", (int) programStats. if (sscanf(message, "%d%c %d %d " u64Display " %[^\n]\n", &plylev, &plyext, &curscore, &time, &nodes, buf1) >= 5) { + if(nodes>>32 == u64Const(0xFFFFFFFF)) // [HGM] negative node count read + nodes += u64Const(0x100000000); + if (plyext != ' ' && plyext != '\t') { time *= 100; } @@ -8974,7 +9452,10 @@ if(appData.debugMode) fprintf(debugFP, "nodes = %d, %lld\n", (int) programStats. if(f = fopen(buf, "w")) { // export PV to applicable PV file fprintf(f, "%5.2f/%-2d %s", curscore/100., plylev, pv); fclose(f); - } else DisplayError(_("failed writing PV"), 0); + } + else + /* TRANSLATORS: PV = principal variation, the variation the chess engine thinks is the best for everyone */ + DisplayError(_("failed writing PV"), 0); } tempStats.depth = plylev; @@ -9237,6 +9718,7 @@ ParseGameHistory (char *game) case WhiteNonPromotion: case BlackNonPromotion: case NormalMove: + case FirstLeg: case WhiteCapturesEnPassant: case BlackCapturesEnPassant: case WhiteKingSideCastle: @@ -9360,7 +9842,7 @@ ParseGameHistory (char *game) default: break; case MT_CHECK: - if(gameInfo.variant != VariantShogi) + if(!IS_SHOGI(gameInfo.variant)) strcat(parseList[boardIndex - 1], "+"); break; case MT_CHECKMATE: @@ -9377,7 +9859,7 @@ void ApplyMove (int fromX, int fromY, int toX, int toY, int promoChar, Board board) { ChessSquare captured = board[toY][toX], piece, king; int p, oldEP = EP_NONE, berolina = 0; - int promoRank = gameInfo.variant == VariantMakruk || gameInfo.variant == VariantGrand ? 3 : 1; + int promoRank = gameInfo.variant == VariantMakruk || gameInfo.variant == VariantGrand || gameInfo.variant == VariantChuChess ? 3 : 1; /* [HGM] compute & store e.p. status and castling rights for new position */ /* we can always do that 'in place', now pointers to these rights are passed to ApplyMove */ @@ -9394,10 +9876,22 @@ ApplyMove (int fromX, int fromY, int toX, int toY, int promoChar, Board board) } piece = board[toY][toX] = (ChessSquare) fromX; } else { +// ChessSquare victim; int i; - if( board[toY][toX] != EmptySquare ) + if( killX >= 0 && killY >= 0 ) // [HGM] lion: Lion trampled over something +// victim = board[killY][killX], + board[killY][killX] = EmptySquare, + board[EP_STATUS] = EP_CAPTURE; + + if( board[toY][toX] != EmptySquare ) { board[EP_STATUS] = EP_CAPTURE; + if( (fromX != toX || fromY != toY) && // not igui! + (captured == WhiteLion && board[fromY][fromX] != BlackLion || + captured == BlackLion && board[fromY][fromX] != WhiteLion ) ) { // [HGM] lion: Chu Lion-capture rules + board[EP_STATUS] = EP_IRON_LION; // non-Lion x Lion: no counter-strike allowed + } + } if( board[fromY][fromX] == WhiteLance || board[fromY][fromX] == BlackLance ) { if( gameInfo.variant != VariantSuper && gameInfo.variant != VariantShogi ) @@ -9485,7 +9979,7 @@ ApplyMove (int fromX, int fromY, int toX, int toY, int promoChar, Board board) board[toY][toX+1] = board[fromY][BOARD_LEFT]; board[fromY][BOARD_LEFT] = EmptySquare; } else if ((board[fromY][fromX] == WhitePawn && gameInfo.variant != VariantXiangqi || - board[fromY][fromX] == WhiteLance && gameInfo.variant != VariantSuper && gameInfo.variant != VariantShogi) + board[fromY][fromX] == WhiteLance && gameInfo.variant != VariantSuper && gameInfo.variant != VariantChu) && toY >= BOARD_HEIGHT-promoRank && promoChar // defaulting to Q is done elsewhere ) { /* white pawn promotion */ @@ -9546,7 +10040,7 @@ ApplyMove (int fromX, int fromY, int toX, int toY, int promoChar, Board board) board[fromY][0] = EmptySquare; board[toY][2] = BlackRook; } else if ((board[fromY][fromX] == BlackPawn && gameInfo.variant != VariantXiangqi || - board[fromY][fromX] == BlackLance && gameInfo.variant != VariantSuper && gameInfo.variant != VariantShogi) + board[fromY][fromX] == BlackLance && gameInfo.variant != VariantSuper && gameInfo.variant != VariantChu) && toY < promoRank && promoChar ) { /* black pawn promotion */ @@ -9579,8 +10073,9 @@ ApplyMove (int fromX, int fromY, int toX, int toY, int promoChar, Board board) board[fromY][fromX+1] = EmptySquare; } } else { - board[toY][toX] = board[fromY][fromX]; + ChessSquare piece = board[fromY][fromX]; // [HGM] lion: allow for igui (where from == to) board[fromY][fromX] = EmptySquare; + board[toY][toX] = piece; } } @@ -9658,12 +10153,15 @@ ApplyMove (int fromX, int fromY, int toX, int toY, int promoChar, Board board) board[toY][toX] = EmptySquare; } } + if(gameInfo.variant == VariantSChess && promoChar != NULLCHAR && promoChar != '=' && piece != WhitePawn && piece != BlackPawn) { board[fromY][fromX] = CharToPiece(piece < BlackPawn ? ToUpper(promoChar) : ToLower(promoChar)); // S-Chess gating } else if(promoChar == '+') { /* [HGM] Shogi-style promotions, to piece implied by original (Might overwrite ordinary Pawn promotion) */ - board[toY][toX] = (ChessSquare) (PROMOTED piece); + board[toY][toX] = (ChessSquare) (CHUPROMOTED piece); + if(gameInfo.variant == VariantChuChess && (piece == WhiteKnight || piece == BlackKnight)) + board[toY][toX] = piece + WhiteLion - WhiteKnight; // adjust Knight promotions to Lion } else if(!appData.testLegality && promoChar != NULLCHAR && promoChar != '=') { // without legality testing, unconditionally believe promoChar ChessSquare newPiece = CharToPiece(piece < BlackPawn ? ToUpper(promoChar) : ToLower(promoChar)); if((newPiece <= WhiteMan || newPiece >= BlackPawn && newPiece <= BlackMan) // unpromoted piece specified @@ -9682,19 +10180,24 @@ ApplyMove (int fromX, int fromY, int toX, int toY, int promoChar, Board board) board[BOARD_HEIGHT-1-k][0] = EmptySquare; } } - } /* Updates forwardMostMove */ void MakeMove (int fromX, int fromY, int toX, int toY, int promoChar) { + int x = toX, y = toY; + char *s = parseList[forwardMostMove]; + ChessSquare p = boards[forwardMostMove][toY][toX]; // forwardMostMove++; // [HGM] bare: moved downstream + if(killX >= 0 && killY >= 0) x = killX, y = killY; // [HGM] lion: make SAN move to intermediate square, if there is one (void) CoordsToAlgebraic(boards[forwardMostMove], PosFlags(forwardMostMove), - fromY, fromX, toY, toX, promoChar, - parseList[forwardMostMove]); + fromY, fromX, y, x, promoChar, + s); + if(killX >= 0 && killY >= 0) + sprintf(s + strlen(s), "%c%c%d", p == EmptySquare || toX == fromX && toY == fromY ? '-' : 'x', toX + AAA, toY + ONE - '0'); if(serverMoves != NULL) { /* [HGM] write moves on file for broadcasting (should be separate routine, really) */ int timeLeft; static int lastLoadFlag=0; int king, piece; @@ -9781,7 +10284,7 @@ MakeMove (int fromX, int fromY, int toX, int toY, int promoChar) default: break; case MT_CHECK: - if(gameInfo.variant != VariantShogi) + if(!IS_SHOGI(gameInfo.variant)) strcat(parseList[forwardMostMove - 1], "+"); break; case MT_CHECKMATE: @@ -9789,7 +10292,6 @@ MakeMove (int fromX, int fromY, int toX, int toY, int promoChar) strcat(parseList[forwardMostMove - 1], "#"); break; } - } /* Updates currentMove if not pausing */ @@ -9809,6 +10311,8 @@ ShowMove (int fromX, int fromY, int toX, int toY) currentMove = forwardMostMove; } + killX = killY = -1; // [HGM] lion: used up + if (instant) return; DisplayMove(currentMove - 1); @@ -9857,37 +10361,75 @@ SendEgtPath (ChessProgramState *cps) } static int -NonStandardBoardSize () -{ - /* [HGM] Awkward testing. Should really be a table */ - int overruled = gameInfo.boardWidth != 8 || gameInfo.boardHeight != 8 || gameInfo.holdingsSize != 0; - if( gameInfo.variant == VariantXiangqi ) - overruled = gameInfo.boardWidth != 9 || gameInfo.boardHeight != 10 || gameInfo.holdingsSize != 0; - if( gameInfo.variant == VariantShogi ) - overruled = gameInfo.boardWidth != 9 || gameInfo.boardHeight != 9 || gameInfo.holdingsSize != 7; - if( gameInfo.variant == VariantBughouse || gameInfo.variant == VariantCrazyhouse ) - overruled = gameInfo.boardWidth != 8 || gameInfo.boardHeight != 8 || gameInfo.holdingsSize != 5; - if( gameInfo.variant == VariantCapablanca || gameInfo.variant == VariantCapaRandom || - gameInfo.variant == VariantGothic || gameInfo.variant == VariantFalcon || gameInfo.variant == VariantJanus ) - overruled = gameInfo.boardWidth != 10 || gameInfo.boardHeight != 8 || gameInfo.holdingsSize != 0; - if( gameInfo.variant == VariantCourier ) - overruled = gameInfo.boardWidth != 12 || gameInfo.boardHeight != 8 || gameInfo.holdingsSize != 0; - if( gameInfo.variant == VariantSuper ) - overruled = gameInfo.boardWidth != 8 || gameInfo.boardHeight != 8 || gameInfo.holdingsSize != 8; - if( gameInfo.variant == VariantGreat ) - overruled = gameInfo.boardWidth != 10 || gameInfo.boardHeight != 8 || gameInfo.holdingsSize != 8; - if( gameInfo.variant == VariantSChess ) - overruled = gameInfo.boardWidth != 8 || gameInfo.boardHeight != 8 || gameInfo.holdingsSize != 7; - if( gameInfo.variant == VariantGrand ) - overruled = gameInfo.boardWidth != 10 || gameInfo.boardHeight != 10 || gameInfo.holdingsSize != 7; - return overruled; +NonStandardBoardSize (VariantClass v, int boardWidth, int boardHeight, int holdingsSize) +{ + int width = 8, height = 8, holdings = 0; // most common sizes + if( v == VariantUnknown || *engineVariant) return 0; // engine-defined name never needs prefix + // correct the deviations default for each variant + if( v == VariantXiangqi ) width = 9, height = 10; + if( v == VariantShogi ) width = 9, height = 9, holdings = 7; + if( v == VariantBughouse || v == VariantCrazyhouse) holdings = 5; + if( v == VariantCapablanca || v == VariantCapaRandom || + v == VariantGothic || v == VariantFalcon || v == VariantJanus ) + width = 10; + if( v == VariantCourier ) width = 12; + if( v == VariantSuper ) holdings = 8; + if( v == VariantGreat ) width = 10, holdings = 8; + if( v == VariantSChess ) holdings = 7; + if( v == VariantGrand ) width = 10, height = 10, holdings = 7; + if( v == VariantChuChess) width = 10, height = 10; + if( v == VariantChu ) width = 12, height = 12; + return boardWidth >= 0 && boardWidth != width || // -1 is default, + boardHeight >= 0 && boardHeight != height || // and thus by definition OK + holdingsSize >= 0 && holdingsSize != holdings; +} + +char variantError[MSG_SIZ]; + +char * +SupportedVariant (char *list, VariantClass v, int boardWidth, int boardHeight, int holdingsSize, int proto, char *engine) +{ // returns error message (recognizable by upper-case) if engine does not support the variant + char *p, *variant = VariantName(v); + static char b[MSG_SIZ]; + if(NonStandardBoardSize(v, boardWidth, boardHeight, holdingsSize)) { /* [HGM] make prefix for non-standard board size. */ + snprintf(b, MSG_SIZ, "%dx%d+%d_%s", boardWidth, boardHeight, + holdingsSize, variant); // cook up sized variant name + /* [HGM] varsize: try first if this deviant size variant is specifically known */ + if(StrStr(list, b) == NULL) { + // specific sized variant not known, check if general sizing allowed + if(proto != 1 && StrStr(list, "boardsize") == NULL) { + snprintf(variantError, MSG_SIZ, "Board size %dx%d+%d not supported by %s", + boardWidth, boardHeight, holdingsSize, engine); + return NULL; + } + /* [HGM] here we really should compare with the maximum supported board size */ + } + } else snprintf(b, MSG_SIZ,"%s", variant); + if(proto == 1) return b; // for protocol 1 we cannot check and hope for the best + p = StrStr(list, b); + while(p && (p != list && p[-1] != ',' || p[strlen(b)] && p[strlen(b)] != ',') ) p = StrStr(p+1, b); + if(p == NULL) { + // occurs not at all in list, or only as sub-string + snprintf(variantError, MSG_SIZ, _("Variant %s not supported by %s"), b, engine); + if(p = StrStr(list, b)) { // handle requesting parent variant when only size-overridden is supported + int l = strlen(variantError); + char *q; + while(p != list && p[-1] != ',') p--; + q = strchr(p, ','); + if(q) *q = NULLCHAR; + snprintf(variantError + l, MSG_SIZ - l, _(", but %s is"), p); + if(q) *q= ','; + } + return NULL; + } + return b; } void InitChessProgram (ChessProgramState *cps, int setup) /* setup needed to setup FRC opening position */ { - char buf[MSG_SIZ], b[MSG_SIZ]; + char buf[MSG_SIZ], *b; if (appData.noChessProgram) return; hintRequested = FALSE; bookRequested = FALSE; @@ -9905,37 +10447,20 @@ InitChessProgram (ChessProgramState *cps, int setup) SendToProgram(buf, cps); } + setboardSpoiledMachineBlack = FALSE; SendToProgram(cps->initString, cps); if (gameInfo.variant != VariantNormal && gameInfo.variant != VariantLoadable /* [HGM] also send variant if board size non-standard */ - || gameInfo.boardWidth != 8 || gameInfo.boardHeight != 8 || gameInfo.holdingsSize != 0 - ) { - char *v = VariantName(gameInfo.variant); - if (cps->protocolVersion != 1 && StrStr(cps->variants, v) == NULL) { - /* [HGM] in protocol 1 we have to assume all variants valid */ - snprintf(buf, MSG_SIZ, _("Variant %s not supported by %s"), v, cps->tidy); - DisplayFatalError(buf, 0, 1); + || gameInfo.boardWidth != 8 || gameInfo.boardHeight != 8 || gameInfo.holdingsSize != 0) { + + b = SupportedVariant(cps->variants, gameInfo.variant, gameInfo.boardWidth, + gameInfo.boardHeight, gameInfo.holdingsSize, cps->protocolVersion, cps->tidy); + if (b == NULL) { + DisplayFatalError(variantError, 0, 1); return; } - if(NonStandardBoardSize()) { /* [HGM] make prefix for non-standard board size. */ - snprintf(b, MSG_SIZ, "%dx%d+%d_%s", gameInfo.boardWidth, gameInfo.boardHeight, - gameInfo.holdingsSize, VariantName(gameInfo.variant)); // cook up sized variant name - /* [HGM] varsize: try first if this defiant size variant is specifically known */ - if(StrStr(cps->variants, b) == NULL) { - // specific sized variant not known, check if general sizing allowed - if (cps->protocolVersion != 1) { // for protocol 1 we cannot check and hope for the best - if(StrStr(cps->variants, "boardsize") == NULL) { - snprintf(buf, MSG_SIZ, "Board size %dx%d+%d not supported by %s", - gameInfo.boardWidth, gameInfo.boardHeight, gameInfo.holdingsSize, cps->tidy); - DisplayFatalError(buf, 0, 1); - return; - } - /* [HGM] here we really should compare with the maximum supported board size */ - } - } - } else snprintf(b, MSG_SIZ,"%s", VariantName(gameInfo.variant)); snprintf(buf, MSG_SIZ, "variant %s\n", b); SendToProgram(buf, cps); } @@ -9975,7 +10500,7 @@ InitChessProgram (ChessProgramState *cps, int setup) SendToProgram("easy\n", cps); } if (cps->usePing) { - snprintf(buf, MSG_SIZ, "ping %d\n", ++cps->lastPing); + snprintf(buf, MSG_SIZ, "ping %d\n", initPing = ++cps->lastPing); SendToProgram(buf, cps); } cps->initDone = TRUE; @@ -10334,7 +10859,9 @@ SwapEngines (int n) SWAP(fenOverride, p) SWAP(NPS, h) SWAP(accumulateTC, h) + SWAP(drawDepth, h) SWAP(host, p) + SWAP(pseudo, h) } int @@ -10615,7 +11142,7 @@ GameEnds (ChessMove result, char *resultDetails, int whosays) result, resultDetails ? resultDetails : "(null)", whosays); } - fromX = fromY = -1; // [HGM] abort any move the user is entering. + fromX = fromY = killX = killY = -1; // [HGM] abort any move the user is entering. // [HGM] lion if(pausing) PauseEvent(); // can happen when we abort a paused game (New Game or Quit) @@ -10837,6 +11364,7 @@ GameEnds (ChessMove result, char *resultDetails, int whosays) PlayIcsUnfinishedSound(); } } + if(appData.quitNext) { ExitEvent(0); return; } } else if (gameMode == EditGame || gameMode == PlayFromGameFile || gameMode == AnalyzeMode || @@ -10884,8 +11412,7 @@ GameEnds (ChessMove result, char *resultDetails, int whosays) ExitAnalyzeMode(); DoSleep( appData.delayBeforeQuit ); SendToProgram("quit\n", &first); - DoSleep( appData.delayAfterQuit ); - DestroyChildProcess(first.pr, first.useSigterm); + DestroyChildProcess(first.pr, 4 + first.useSigterm); first.reload = TRUE; } first.pr = NoProc; @@ -10910,8 +11437,7 @@ GameEnds (ChessMove result, char *resultDetails, int whosays) if (second.pr != NoProc) { DoSleep( appData.delayBeforeQuit ); SendToProgram("quit\n", &second); - DoSleep( appData.delayAfterQuit ); - DestroyChildProcess(second.pr, second.useSigterm); + DestroyChildProcess(second.pr, 4 + second.useSigterm); second.reload = TRUE; } second.pr = NoProc; @@ -11013,7 +11539,8 @@ FeedMovesToProgram (ChessProgramState *cps, int upto) if(currentlyInitializedVariant != gameInfo.variant) { char buf[MSG_SIZ]; // [HGM] variantswitch: make engine aware of new variant - if(cps->protocolVersion > 1 && StrStr(cps->variants, VariantName(gameInfo.variant)) == NULL) + if(!SupportedVariant(cps->variants, gameInfo.variant, gameInfo.boardWidth, + gameInfo.boardHeight, gameInfo.holdingsSize, cps->protocolVersion, "")) return; // [HGM] refrain from feeding moves altogether if variant is unsupported! snprintf(buf, MSG_SIZ, "variant %s\n", VariantName(gameInfo.variant)); SendToProgram(buf, cps); @@ -11096,6 +11623,7 @@ Reset (int redraw, int init) lastHint[0] = NULLCHAR; ClearGameInfo(&gameInfo); gameInfo.variant = StringToVariant(appData.variant); + if(gameInfo.variant == VariantNormal && strcmp(appData.variant, "normal")) gameInfo.variant = VariantUnknown; ics_user_moved = ics_clock_paused = FALSE; ics_getting_history = H_FALSE; ics_gamenum = -1; @@ -11109,6 +11637,7 @@ Reset (int redraw, int init) ClearPremoveHighlights(); gotPremove = FALSE; alarmSounded = FALSE; + killX = killY = -1; // [HGM] lion GameEnds(EndOfFile, NULL, GE_PLAYER); if(appData.serverMovesName != NULL) { @@ -11226,11 +11755,20 @@ AutoPlayOneMove () SetHighlights(-1, -1, toX, toY); } } else { + int viaX = moveList[currentMove][5] - AAA; + int viaY = moveList[currentMove][6] - ONE; fromX = moveList[currentMove][0] - AAA; fromY = moveList[currentMove][1] - ONE; HistorySet(parseList, backwardMostMove, forwardMostMove, currentMove); /* [AS] */ + if(moveList[currentMove][4] == ';') { // multi-leg + ChessSquare piece = boards[currentMove][viaY][viaX]; + AnimateMove(boards[currentMove], fromX, fromY, viaX, viaY); + boards[currentMove][viaY][viaX] = boards[currentMove][fromY][fromX]; + AnimateMove(boards[currentMove], fromX=viaX, fromY=viaY, toX, toY); + boards[currentMove][viaY][viaX] = piece; + } else AnimateMove(boards[currentMove], fromX, fromY, toX, toY); if (appData.highlightLastMove) { @@ -11289,6 +11827,7 @@ LoadGameOneMove (ChessMove readAhead) case WhiteNonPromotion: case BlackNonPromotion: case NormalMove: + case FirstLeg: case WhiteKingSideCastle: case WhiteQueenSideCastle: case BlackKingSideCastle: @@ -11310,6 +11849,7 @@ LoadGameOneMove (ChessMove readAhead) toX = currentMoveString[2] - AAA; toY = currentMoveString[3] - ONE; promoChar = currentMoveString[4]; + if(promoChar == ';') promoChar = NULLCHAR; break; case WhiteDrop: @@ -11476,6 +12016,7 @@ LoadGameOneMove (ChessMove readAhead) thinkOutput[0] = NULLCHAR; MakeMove(fromX, fromY, toX, toY, promoChar); + killX = killY = -1; // [HGM] lion: used up currentMove = forwardMostMove; return TRUE; } @@ -11835,12 +12376,26 @@ QuickCompare (Board board, int *minCounts, int *maxCounts) int QuickScan (Board board, Move *move) { // reconstruct game,and compare all positions in it - int cnt=0, stretch=0, total = MakePieceList(board, counts); + int cnt=0, stretch=0, found = -1, total = MakePieceList(board, counts); do { int piece = move->piece; int to = move->to, from = pieceList[piece]; + if(found < 0) { // if already found just scan to game end for final piece count + if(QuickCompare(soughtBoard, minSought, maxSought) || + appData.ignoreColors && QuickCompare(reverseBoard, minReverse, maxReverse) || + flipSearch && (QuickCompare(flipBoard, minSought, maxSought) || + appData.ignoreColors && QuickCompare(rotateBoard, minReverse, maxReverse)) + ) { + static int lastCounts[EmptySquare+1]; + int i; + if(stretch) for(i=0; i= appData.stretch)) found = cnt + 1 - stretch; + if(found >= 0 && !appData.minPieces) return found; + } if(piece <= Q_PROMO) { // special moves encoded by otherwise invalid piece numbers 1-4 - if(!piece) return -1; + if(!piece) return (appData.minPieces && (total < appData.minPieces || total > appData.maxPieces) ? -1 : found); if(piece == Q_PROMO) { // promotion, encoded as (Q_PROMO, to) + (piece, promoType) piece = (++move)->piece; from = pieceList[piece]; @@ -11865,23 +12420,12 @@ QuickScan (Board board, Move *move) } } if(appData.searchMode > 2) counts[pieceType[quickBoard[to]]]--; // account capture - if((total -= (quickBoard[to] != 0)) < soughtTotal) return -1; // piece count dropped below what we search for + if((total -= (quickBoard[to] != 0)) < soughtTotal && found < 0) return -1; // piece count dropped below what we search for quickBoard[from] = 0; aftercastle: quickBoard[to] = piece; pieceList[piece] = to; cnt++; turn ^= 3; - if(QuickCompare(soughtBoard, minSought, maxSought) || - appData.ignoreColors && QuickCompare(reverseBoard, minReverse, maxReverse) || - flipSearch && (QuickCompare(flipBoard, minSought, maxSought) || - appData.ignoreColors && QuickCompare(rotateBoard, minReverse, maxReverse)) - ) { - static int lastCounts[EmptySquare+1]; - int i; - if(stretch) for(i=0; i= appData.stretch)) return cnt + 1 - stretch; move++; } while(1); } @@ -11947,7 +12491,7 @@ GameContainsPosition (FILE *f, ListGame *lg) for(next = WhitePawn; next>8 ^ random()<<6 ^random()<<20; initDone = TRUE; } - if(lg->gameInfo.fen) ParseFEN(boards[scratch], &btm, lg->gameInfo.fen); + if(lg->gameInfo.fen) ParseFEN(boards[scratch], &btm, lg->gameInfo.fen, FALSE); else CopyBoard(boards[scratch], initialPosition); // default start position if(lg->moves) { turn = btm + 1; @@ -11991,6 +12535,7 @@ GameContainsPosition (FILE *f, ListGame *lg) case WhiteNonPromotion: case BlackNonPromotion: case NormalMove: + case FirstLeg: case WhiteKingSideCastle: case WhiteQueenSideCastle: case BlackKingSideCastle: @@ -12055,6 +12600,7 @@ LoadGame (FILE *f, int gameNumber, char *title, int useList) if (gameMode != BeginningOfGame) { Reset(FALSE, TRUE); } + killX = killY = -1; // [HGM] lion: in case we did not Reset gameFileFP = f; if (lastLoadGameFP != NULL && lastLoadGameFP != f) { @@ -12208,6 +12754,7 @@ LoadGame (FILE *f, int gameNumber, char *title, int useList) break; case NormalMove: + case FirstLeg: /* Only a NormalMove can be at the start of a game * without a position diagram. */ if (lastLoadGameStart == EndOfFile ) { @@ -12269,7 +12816,7 @@ LoadGame (FILE *f, int gameNumber, char *title, int useList) if (gameInfo.fen != NULL) { Board initial_position; startedFromSetupPosition = TRUE; - if (!ParseFEN(initial_position, &blackPlaysFirst, gameInfo.fen)) { + if (!ParseFEN(initial_position, &blackPlaysFirst, gameInfo.fen, TRUE)) { Reset(TRUE, TRUE); DisplayError(_("Bad FEN position in file"), 0); return FALSE; @@ -12475,6 +13022,15 @@ LoadGame (FILE *f, int gameNumber, char *title, int useList) AnalyzeFileEvent(); } + if(gameInfo.result == GameUnfinished && gameInfo.resultDetails && appData.clockMode) { + long int w, b; // [HGM] adjourn: restore saved clock times + char *p = strstr(gameInfo.resultDetails, "(Clocks:"); + if(p && sscanf(p+8, "%ld,%ld", &w, &b) == 2) { + timeRemaining[0][forwardMostMove] = whiteTimeRemaining = 1000*w + 500; + timeRemaining[1][forwardMostMove] = blackTimeRemaining = 1000*b + 500; + } + } + if(creatingBook) return TRUE; if (!matchMode && pos > 0) { ToNrEvent(pos); // [HGM] no autoplay if selected on position @@ -12597,7 +13153,7 @@ LoadPosition (FILE *f, int positionNumber, char *title) } if (fenMode) { - if (!ParseFEN(initial_position, &blackPlaysFirst, line)) { + if (!ParseFEN(initial_position, &blackPlaysFirst, line, TRUE)) { DisplayError(_("Bad FEN position in file"), 0); return FALSE; } @@ -12822,9 +13378,9 @@ GetOutOfBookInfo (char * buf) } } -/* Save game in PGN style and close the file */ -int -SaveGamePGN (FILE *f) +/* Save game in PGN style */ +static void +SaveGamePGN2 (FILE *f) { int i, offset, linelen, newblock; // char *movetext; @@ -12839,7 +13395,7 @@ SaveGamePGN (FILE *f) if(appData.numberTag && matchMode) fprintf(f, "[Number \"%d\"]\n", nextGame+1); // [HGM] number tag if (backwardMostMove > 0 || startedFromSetupPosition) { - char *fen = PositionToFEN(backwardMostMove, NULL); + char *fen = PositionToFEN(backwardMostMove, NULL, 1); fprintf(f, "[FEN \"%s\"]\n[SetUp \"1\"]\n", fen); fprintf(f, "\n{--------------\n"); PrintPosition(f, backwardMostMove); @@ -12976,12 +13532,21 @@ SaveGamePGN (FILE *f) /* Print result */ if (gameInfo.resultDetails != NULL && gameInfo.resultDetails[0] != NULLCHAR) { - fprintf(f, "{%s} %s\n\n", gameInfo.resultDetails, - PGNResult(gameInfo.result)); + char buf[MSG_SIZ], *p = gameInfo.resultDetails; + if(gameInfo.result == GameUnfinished && appData.clockMode && + (gameMode == MachinePlaysWhite || gameMode == MachinePlaysBlack || gameMode == TwoMachinesPlay)) // [HGM] adjourn: save clock settings + snprintf(buf, MSG_SIZ, "%s (Clocks: %ld, %ld)", p, whiteTimeRemaining/1000, blackTimeRemaining/1000), p = buf; + fprintf(f, "{%s} %s\n\n", p, PGNResult(gameInfo.result)); } else { fprintf(f, "%s\n\n", PGNResult(gameInfo.result)); } +} +/* Save game in PGN style and close the file */ +int +SaveGamePGN (FILE *f) +{ + SaveGamePGN2(f); fclose(f); lastSavedGame = GameCheckSum(); // [HGM] save: remember ID of last saved game to prevent double saving return TRUE; @@ -13108,7 +13673,7 @@ SavePosition (FILE *f, int dummy, char *dummy2) PrintPosition(f, currentMove); fprintf(f, "--------------]\n"); } else { - fen = PositionToFEN(currentMove, NULL); + fen = PositionToFEN(currentMove, NULL, 1); fprintf(f, "%s\n", fen); free(fen); } @@ -13460,6 +14025,7 @@ ExitEvent (int status) return; } + if (appData.icsActive) printf("\n"); // [HGM] end on new line after closing XBoard if (appData.icsActive && appData.colorize) Colorize(ColorNone, FALSE); if (telnetISR != NULL) { @@ -13486,14 +14052,12 @@ ExitEvent (int status) DoSleep( appData.delayBeforeQuit ); SendToProgram("quit\n", &first); - DoSleep( appData.delayAfterQuit ); - DestroyChildProcess(first.pr, 10 /* [AS] first.useSigterm */ ); + DestroyChildProcess(first.pr, 4 + first.useSigterm /* [AS] first.useSigterm */ ); } if (second.pr != NoProc) { DoSleep( appData.delayBeforeQuit ); SendToProgram("quit\n", &second); - DoSleep( appData.delayAfterQuit ); - DestroyChildProcess(second.pr, 10 /* [AS] second.useSigterm */ ); + DestroyChildProcess(second.pr, 4 + second.useSigterm /* [AS] second.useSigterm */ ); } if (first.isr != NULL) { RemoveInputSource(first.isr); @@ -14013,7 +14577,7 @@ TwoMachinesEvent P((void)) case MachinePlaysWhite: case MachinePlaysBlack: if (WhiteOnMove(forwardMostMove) == (gameMode == MachinePlaysWhite)) { - DisplayError(_("Wait until your turn,\nor select Move Now"), 0); + DisplayError(_("Wait until your turn,\nor select 'Move Now'."), 0); return; } /* fall through */ @@ -14048,7 +14612,8 @@ TwoMachinesEvent P((void)) } if(WaitForEngine(&second, TwoMachinesEventIfReady)) return; // (if needed:) started up second engine, so wait for features - if(second.protocolVersion >= 2 && !strstr(second.variants, VariantName(gameInfo.variant))) { + if(!SupportedVariant(second.variants, gameInfo.variant, gameInfo.boardWidth, + gameInfo.boardHeight, gameInfo.holdingsSize, second.protocolVersion, second.tidy)) { startingEngine = FALSE; DisplayError("second engine does not play this", 0); return; @@ -14450,11 +15015,15 @@ EditPositionMenuEvent (ChessSquare selection, int x, int y) { char buf[MSG_SIZ]; ChessSquare piece = boards[0][y][x]; + static Board erasedBoard, currentBoard, menuBoard, nullBoard; + static int lastVariant; if (gameMode != EditPosition && gameMode != IcsExamining) return; switch (selection) { case ClearBoard: + CopyBoard(currentBoard, boards[0]); + CopyBoard(menuBoard, initialPosition); if (gameMode == IcsExamining && ics_type == ICS_FICS) { SendToICS(ics_prefix); SendToICS("bsetup clear\n"); @@ -14462,6 +15031,7 @@ EditPositionMenuEvent (ChessSquare selection, int x, int y) SendToICS(ics_prefix); SendToICS("clearboard\n"); } else { + int nonEmpty = 0; for (x = 0; x < BOARD_WIDTH; x++) { ChessSquare p = EmptySquare; if(x == BOARD_LEFT-1 || x == BOARD_RGHT) p = (ChessSquare) 0; /* [HGM] holdings */ for (y = 0; y < BOARD_HEIGHT; y++) { @@ -14472,10 +15042,34 @@ EditPositionMenuEvent (ChessSquare selection, int x, int y) SendToICS(buf); } } else { + if(boards[0][y][x] != p) nonEmpty++; boards[0][y][x] = p; } } } + if(gameMode != IcsExamining) { // [HGM] editpos: cycle trough boards + int r; + for(r = 0; r < BOARD_HEIGHT; r++) { + for(x = BOARD_LEFT; x < BOARD_RGHT; x++) { // create 'menu board' by removing duplicates + ChessSquare p = menuBoard[r][x]; + for(y = x + 1; y < BOARD_RGHT; y++) if(menuBoard[r][y] == p) menuBoard[r][y] = EmptySquare; + } + } + DisplayMessage("Clicking clock again restores position", ""); + if(gameInfo.variant != lastVariant) lastVariant = gameInfo.variant, CopyBoard(erasedBoard, boards[0]); + if(!nonEmpty) { // asked to clear an empty board + CopyBoard(boards[0], menuBoard); + } else + if(CompareBoards(currentBoard, menuBoard)) { // asked to clear an empty board + CopyBoard(boards[0], initialPosition); + } else + if(CompareBoards(currentBoard, initialPosition) && !CompareBoards(currentBoard, erasedBoard) + && !CompareBoards(nullBoard, erasedBoard)) { + CopyBoard(boards[0], erasedBoard); + } else + CopyBoard(erasedBoard, currentBoard); + + } } if (gameMode == EditPosition) { DrawPosition(FALSE, boards[0]); @@ -14532,6 +15126,7 @@ EditPositionMenuEvent (ChessSquare selection, int x, int y) if(gameInfo.variant == VariantShatranj || gameInfo.variant == VariantXiangqi || gameInfo.variant == VariantCourier || + gameInfo.variant == VariantASEAN || gameInfo.variant == VariantMakruk ) selection = (ChessSquare)((int)selection - (int)WhiteQueen + (int)WhiteFerz); goto defaultlabel; @@ -14720,7 +15315,8 @@ ClockClick (int which) if (gameMode == EditPosition || gameMode == IcsExamining) { if(!appData.pieceMenu && blackPlaysFirst) EditPositionMenuEvent(ClearBoard, 0, 0); SetBlackToPlayEvent(); - } else if ((gameMode == AnalyzeMode || gameMode == EditGame) && !blackFlag && WhiteOnMove(currentMove)) { + } else if ((gameMode == AnalyzeMode || gameMode == EditGame || + gameMode == MachinePlaysBlack && PosFlags(0) & F_NULL_MOVE && !blackFlag && !shiftKey) && WhiteOnMove(currentMove)) { UserMoveEvent((int)EmptySquare, DROP_RANK, 0, 0, 0); // [HGM] multi-move: if not out of time, enters null move } else if (shiftKey) { AdjustClock(which, -1); @@ -14732,7 +15328,8 @@ ClockClick (int which) if (gameMode == EditPosition || gameMode == IcsExamining) { if(!appData.pieceMenu && !blackPlaysFirst) EditPositionMenuEvent(ClearBoard, 0, 0); SetWhiteToPlayEvent(); - } else if ((gameMode == AnalyzeMode || gameMode == EditGame) && !whiteFlag && !WhiteOnMove(currentMove)) { + } else if ((gameMode == AnalyzeMode || gameMode == EditGame || + gameMode == MachinePlaysWhite && PosFlags(0) & F_NULL_MOVE && !whiteFlag && !shiftKey) && !WhiteOnMove(currentMove)) { UserMoveEvent((int)EmptySquare, DROP_RANK, 0, 0, 0); // [HGM] multi-move } else if (shiftKey) { AdjustClock(which, -1); @@ -14896,9 +15493,18 @@ ForwardInner (int target) SetHighlights(-1, -1, toX, toY); } } else { + int viaX = moveList[target - 1][5] - AAA; + int viaY = moveList[target - 1][6] - ONE; fromX = moveList[target - 1][0] - AAA; fromY = moveList[target - 1][1] - ONE; if (target == currentMove + 1) { + if(moveList[target - 1][4] == ';') { // multi-leg + ChessSquare piece = boards[currentMove][viaY][viaX]; + AnimateMove(boards[currentMove], fromX, fromY, viaX, viaY); + boards[currentMove][viaY][viaX] = boards[currentMove][fromY][fromX]; + AnimateMove(boards[currentMove], viaX, viaY, toX, toY); + boards[currentMove][viaY][viaX] = piece; + } else AnimateMove(boards[currentMove], fromX, fromY, toX, toY); } if (appData.highlightLastMove) { @@ -15127,7 +15733,7 @@ RetractMoveEvent () case MachinePlaysWhite: case MachinePlaysBlack: if (WhiteOnMove(forwardMostMove) == (gameMode == MachinePlaysWhite)) { - DisplayError(_("Wait until your turn,\nor select Move Now"), 0); + DisplayError(_("Wait until your turn,\nor select 'Move Now'."), 0); return; } if (forwardMostMove < 2) return; @@ -15225,14 +15831,14 @@ HintEvent () switch (gameMode) { case MachinePlaysWhite: if (WhiteOnMove(forwardMostMove)) { - DisplayError(_("Wait until your turn"), 0); + DisplayError(_("Wait until your turn."), 0); return; } break; case BeginningOfGame: case MachinePlaysBlack: if (!WhiteOnMove(forwardMostMove)) { - DisplayError(_("Wait until your turn"), 0); + DisplayError(_("Wait until your turn."), 0); return; } break; @@ -15244,6 +15850,36 @@ HintEvent () hintRequested = TRUE; } +int +SaveSelected (FILE *g, int dummy, char *dummy2) +{ + ListGame * lg = (ListGame *) gameList.head; + int nItem, cnt=0; + FILE *f; + + if( !(f = GameFile()) || ((ListGame *) gameList.tailPred)->number <= 0 ) { + DisplayError(_("Game list not loaded or empty"), 0); + return 0; + } + + creatingBook = TRUE; // suppresses stuff during load game + + /* Get list size */ + for (nItem = 1; nItem <= ((ListGame *) gameList.tailPred)->number; nItem++){ + if(lg->position >= 0) { // selected? + LoadGame(f, nItem, "", TRUE); + SaveGamePGN2(g); // leaves g open + cnt++; DoEvents(); + } + lg = (ListGame *) lg->node.succ; + } + + fclose(g); + creatingBook = FALSE; + + return cnt; +} + void CreateBookEvent () { @@ -15269,8 +15905,11 @@ CreateBookEvent () /* Get list size */ for (nItem = 1; nItem <= ((ListGame *) gameList.tailPred)->number; nItem++){ - LoadGame(f, nItem, "", TRUE); - AddGameToBook(TRUE); + if(lg->position >= 0) { + LoadGame(f, nItem, "", TRUE); + AddGameToBook(TRUE); + DoEvents(); + } lg = (ListGame *) lg->node.succ; } @@ -15285,14 +15924,14 @@ BookEvent () switch (gameMode) { case MachinePlaysWhite: if (WhiteOnMove(forwardMostMove)) { - DisplayError(_("Wait until your turn"), 0); + DisplayError(_("Wait until your turn."), 0); return; } break; case BeginningOfGame: case MachinePlaysBlack: if (!WhiteOnMove(forwardMostMove)) { - DisplayError(_("Wait until your turn"), 0); + DisplayError(_("Wait until your turn."), 0); return; } break; @@ -15956,6 +16595,27 @@ SendTimeRemaining (ChessProgramState *cps, int machineWhite) SendToProgram(message, cps); } +char * +EngineDefinedVariant (ChessProgramState *cps, int n) +{ // return name of n-th unknown variant that engine supports + static char buf[MSG_SIZ]; + char *p, *s = cps->variants; + if(!s) return NULL; + do { // parse string from variants feature + VariantClass v; + p = strchr(s, ','); + if(p) *p = NULLCHAR; + v = StringToVariant(s); + if(v == VariantNormal && strcmp(s, "normal") && !strstr(s, "_normal")) v = VariantUnknown; // garbage is recognized as normal + if(v == VariantUnknown) { // non-standard variant in list of engine-supported variants + if(--n < 0) safeStrCpy(buf, s, MSG_SIZ); + } + if(p) *p++ = ','; + if(n < 0) return buf; + } while(s = p); + return NULL; +} + int BoolFeature (char **p, char *name, int *loc, ChessProgramState *cps) { @@ -16170,6 +16830,7 @@ ParseFeatures (char *args, ChessProgramState *cps) /* End of additions by Tord */ /* [HGM] added features: */ + if (BoolFeature(&p, "highlight", &cps->highlight, cps)) continue; if (BoolFeature(&p, "debug", &cps->debug, cps)) continue; if (BoolFeature(&p, "nps", &cps->supportsNPS, cps)) continue; if (IntFeature(&p, "level", &cps->maxNrOfSessions, cps)) continue; @@ -16323,7 +16984,7 @@ TypeInDoneEvent (char *move) ChessMove moveType; // [HGM] FENedit - if(gameMode == EditPosition && ParseFEN(board, &n, move) ) { + if(gameMode == EditPosition && ParseFEN(board, &n, move, TRUE) ) { EditPositionPasteFEN(move); return; } @@ -17025,7 +17686,7 @@ PGNDate () char * -PositionToFEN (int move, char *overrideCastling) +PositionToFEN (int move, char *overrideCastling, int moveCounts) { int i, j, fromX, fromY, toX, toY; int whiteToPlay; @@ -17055,12 +17716,12 @@ PositionToFEN (int move, char *overrideCastling) if(PieceToChar(piece) == '+') { /* [HGM] write promoted pieces as '+' (Shogi) */ *p++ = '+'; - piece = (ChessSquare)(DEMOTED piece); + piece = (ChessSquare)(CHUDEMOTED piece); } - *p++ = PieceToChar(piece); + *p++ = (piece == DarkSquare ? '*' : PieceToChar(piece)); if(p[-1] == '~') { /* [HGM] flag promoted pieces as '~' (Crazyhouse) */ - p[-1] = PieceToChar((ChessSquare)(DEMOTED piece)); + p[-1] = PieceToChar((ChessSquare)(CHUDEMOTED piece)); *p++ = '~'; } } @@ -17106,7 +17767,7 @@ PositionToFEN (int move, char *overrideCastling) } else { if(nrCastlingRights) { q = p; - if(gameInfo.variant == VariantFischeRandom || gameInfo.variant == VariantCapaRandom) { + if(appData.fischerCastling) { /* [HGM] write directly from rights */ if(boards[move][CASTLING][2] != NoRights && boards[move][CASTLING][0] != NoRights ) @@ -17155,7 +17816,8 @@ PositionToFEN (int move, char *overrideCastling) } if(gameInfo.variant != VariantShogi && gameInfo.variant != VariantXiangqi && - gameInfo.variant != VariantShatranj && gameInfo.variant != VariantCourier && gameInfo.variant != VariantMakruk ) { + gameInfo.variant != VariantShatranj && gameInfo.variant != VariantCourier && + gameInfo.variant != VariantMakruk && gameInfo.variant != VariantASEAN ) { /* En passant target square */ if (move > backwardMostMove) { fromX = moveList[move - 1][0] - AAA; @@ -17187,9 +17849,10 @@ PositionToFEN (int move, char *overrideCastling) } } - /* [HGM] find reversible plies */ + if(moveCounts) { int i = 0, j=move; + /* [HGM] find reversible plies */ if (appData.debugMode) { int k; fprintf(debugFP, "write FEN 50-move: %d %d %d\n", initialRulePlies, forwardMostMove, backwardMostMove); for(k=backwardMostMove; k<=forwardMostMove; k++) @@ -17201,62 +17864,72 @@ PositionToFEN (int move, char *overrideCastling) if( j == backwardMostMove ) i += initialRulePlies; sprintf(p, "%d ", i); p += i>=100 ? 4 : i >= 10 ? 3 : 2; - } - /* Fullmove number */ - sprintf(p, "%d", (move / 2) + 1); + + /* Fullmove number */ + sprintf(p, "%d", (move / 2) + 1); + } else *--p = NULLCHAR; return StrSave(buf); } Boolean -ParseFEN (Board board, int *blackPlaysFirst, char *fen) +ParseFEN (Board board, int *blackPlaysFirst, char *fen, Boolean autoSize) { - int i, j; + int i, j, k, w=0, subst=0, shuffle=0; char *p, c; int emptycount, virgin[BOARD_FILES]; ChessSquare piece; p = fen; - /* [HGM] by default clear Crazyhouse holdings, if present */ - if(gameInfo.holdingsWidth) { - for(i=0; i= 0; i--) { j = 0; for (;;) { - if (*p == '/' || *p == ' ' || (*p == '[' && i == 0) ) { - if (*p == '/') p++; + if (*p == '/' || *p == ' ' || *p == '[' ) { + if(j > w) w = j; emptycount = gameInfo.boardWidth - j; while (emptycount--) board[i][(j++)+gameInfo.holdingsWidth] = EmptySquare; + if (*p == '/') p++; + else if(autoSize) { // we stumbled unexpectedly into end of board + for(k=i; k= 10) +#if(BOARD_FILES >= 10)*0 } else if(*p=='x' || *p=='X') { /* [HGM] X means 10 */ p++; emptycount=10; if (j + emptycount > gameInfo.boardWidth) return FALSE; while (emptycount--) board[i][(j++)+gameInfo.holdingsWidth] = EmptySquare; #endif + } else if (*p == '*') { + board[i][(j++)+gameInfo.holdingsWidth] = DarkSquare; p++; } else if (isdigit(*p)) { emptycount = *p++ - '0'; while(isdigit(*p)) emptycount = 10*emptycount + *p++ - '0'; /* [HGM] allow > 9 */ if (j + emptycount > gameInfo.boardWidth) return FALSE; while (emptycount--) board[i][(j++)+gameInfo.holdingsWidth] = EmptySquare; + } else if (*p == '<') { + if(i == BOARD_HEIGHT-1) shuffle = 1; + else if (i != 0 || !shuffle) return FALSE; + p++; + } else if (shuffle && *p == '>') { + p++; // for now ignore closing shuffle range, and assume rank-end + } else if (*p == '?') { + if (j >= gameInfo.boardWidth) return FALSE; + if (i != 0 && i != BOARD_HEIGHT-1) return FALSE; // only on back-rank + board[i][(j++)+gameInfo.holdingsWidth] = ClearBoard; p++; subst++; // placeHolder } else if (*p == '+' || isalpha(*p)) { if (j >= gameInfo.boardWidth) return FALSE; if(*p=='+') { piece = CharToPiece(*++p); if(piece == EmptySquare) return FALSE; /* unknown piece */ - piece = (ChessSquare) (PROMOTED piece ); p++; + piece = (ChessSquare) (CHUPROMOTED piece ); p++; if(PieceToChar(piece) != '+') return FALSE; /* unpromotable piece */ } else piece = CharToPiece(*p++); @@ -17274,10 +17947,24 @@ ParseFEN (Board board, int *blackPlaysFirst, char *fen) } while (*p == '/' || *p == ' ') p++; + if(autoSize) appData.NrFiles = w, InitPosition(TRUE); + + /* [HGM] by default clear Crazyhouse holdings, if present */ + if(gameInfo.holdingsWidth) { + for(i=0; i= gameInfo.holdingsSize ) return FALSE; board[BOARD_HEIGHT-1-i][0] = piece; /* black holdings */ board[BOARD_HEIGHT-1-i][1]++; /* black counts */ + bcnt++; } else { i = (int)piece - (int)WhitePawn; i = PieceToNumber((ChessSquare)i); if( i >= gameInfo.holdingsSize ) return FALSE; board[i][BOARD_WIDTH-1] = piece; /* white holdings */ board[i][BOARD_WIDTH-2]++; /* black holdings */ + wcnt++; } } + if(subst) { // substitute back-rank question marks by holdings pieces + for(j=BOARD_LEFT; j= bcnt) n = rand() % bcnt; // use same randomization for black and white if possible + for(k=0, m=n; k= 'A' && *p <= 'Z' || *p >= 'a' && *p <= 'z' || *p=='-') { /* castling indicator present, so default becomes no castlings */ @@ -17350,7 +18066,7 @@ ParseFEN (Board board, int *blackPlaysFirst, char *fen) } } while(*p=='K' || *p=='Q' || *p=='k' || *p=='q' || *p=='-' || - (gameInfo.variant == VariantFischeRandom || gameInfo.variant == VariantCapaRandom || gameInfo.variant == VariantSChess) && + (appData.fischerCastling || gameInfo.variant == VariantSChess) && ( *p >= 'a' && *p < 'a' + gameInfo.boardWidth) || ( *p >= 'A' && *p < 'A' + gameInfo.boardWidth) ) { int c = *p++, whiteKingFile=NoRights, blackKingFile=NoRights; @@ -17372,6 +18088,7 @@ ParseFEN (Board board, int *blackPlaysFirst, char *fen) board[CASTLING][2] = whiteKingFile; if(board[CASTLING][0] != NoRights) virgin[board[CASTLING][0]] |= VIRGIN_W; if(board[CASTLING][2] != NoRights) virgin[board[CASTLING][2]] |= VIRGIN_W; + if(whiteKingFile != BOARD_WIDTH>>1|| i != BOARD_RGHT-1) fischer = 1; break; case'Q': for(i=BOARD_LEFT; i>1|| i != BOARD_LEFT) fischer = 1; break; case'k': for(i=BOARD_RGHT-1; board[BOARD_HEIGHT-1][i]!=BlackRook && i>blackKingFile; i--); @@ -17386,6 +18104,7 @@ ParseFEN (Board board, int *blackPlaysFirst, char *fen) board[CASTLING][5] = blackKingFile; if(board[CASTLING][3] != NoRights) virgin[board[CASTLING][3]] |= VIRGIN_B; if(board[CASTLING][5] != NoRights) virgin[board[CASTLING][5]] |= VIRGIN_B; + if(blackKingFile != BOARD_WIDTH>>1|| i != BOARD_RGHT-1) fischer = 1; break; case'q': for(i=BOARD_LEFT; i>1|| i != BOARD_LEFT) fischer = 1; case '-': break; default: /* FRC castlings */ @@ -17426,7 +18146,9 @@ ParseFEN (Board board, int *blackPlaysFirst, char *fen) } for(i=0; i= 16 bits */ } TimeMark; +extern TimeMark programStartTime; + void GetTimeMark P((TimeMark *)); long SubtractTimeMarks P((TimeMark *, TimeMark *)); diff --git a/board.c b/board.c index 5c55b4f..d0f6cfb 100644 --- a/board.c +++ b/board.c @@ -599,23 +599,31 @@ void AnimateMove (Board board, int fromX, int fromY, int toX, int toY) { ChessSquare piece; - int hop; + int hop, x = toX, y = toY; Pnt start, finish, mid; Pnt frames[kFactor * 2 + 1]; int nFrames, startColor, endColor; + if(killX >= 0 && IS_LION(board[fromY][fromX])) Roar(); + /* Are we animating? */ if (!appData.animate || appData.blindfold) return; if(board[toY][toX] == WhiteRook && board[fromY][fromX] == WhiteKing || - board[toY][toX] == BlackRook && board[fromY][fromX] == BlackKing) + board[toY][toX] == BlackRook && board[fromY][fromX] == BlackKing || + board[toY][toX] == WhiteKing && board[fromY][fromX] == WhiteRook || // [HGM] seirawan + board[toY][toX] == BlackKing && board[fromY][fromX] == BlackRook) return; // [HGM] FRC: no animtion of FRC castlings, as to-square is not true to-square if (fromY < 0 || fromX < 0 || toX < 0 || toY < 0) return; piece = board[fromY][fromX]; if (piece >= EmptySquare) return; + if(killX >= 0) toX = killX, toY = killY; // [HGM] lion: first to kill square + +again: + #if DONT_HOP hop = FALSE; #else @@ -653,6 +661,8 @@ AnimateMove (Board board, int fromX, int fromY, int toX, int toY) /* Be sure end square is redrawn */ damage[0][toY][toX] |= True; + + if(toX != x || toY != y) { fromX = toX; fromY = toY; toX = x; toY = y; goto again; } // second leg } void @@ -817,6 +827,7 @@ DrawSquare (int row, int column, ChessSquare piece, int do_flash) snprintf(tString, 3, "%d", piece); align = 4; // holdings count in upper-left corner } + if(piece == DarkSquare) square_color = 2; if(square_color == 2 || appData.blindfold) piece = EmptySquare; if (do_flash && piece != EmptySquare && appData.flashCount > 0) { diff --git a/book.c b/book.c index ec3f543..dc81458 100644 --- a/book.c +++ b/book.c @@ -28,6 +28,8 @@ * ------------------------------------------------------------------------ */ +#include "config.h" + #include #include #include @@ -792,6 +794,7 @@ DisplayBook (int moveNr) p = MovesToText(count, entries); EditTagsPopUp(p, NULL); free(p); + addToBookFlag = FALSE; return TRUE; } @@ -984,6 +987,15 @@ AddGameToBook (int always) } void +PlayBookMove(char *text, int index) +{ + char *start = text+index, *end = start; + while(start > text && start[-1] != ' ' && start[-1] != '\t') start--; + while(*end && *++end != ' ' && *end != '\n'); *end = NULLCHAR; // find clicked word + if(start != end) TypeInDoneEvent(start); // fake it was typed in move type-in +} + +void FlushBook () { FILE *f; diff --git a/common.h b/common.h index 861eefa..f2cb9e9 100644 --- a/common.h +++ b/common.h @@ -172,7 +172,7 @@ typedef char *String; outside world in ASCII. In a similar way, the different rank numbering systems (starting at rank 0 or 1) are implemented by redefining '1'. */ -#define BOARD_RANKS 11 /* [HGM] for in declarations */ +#define BOARD_RANKS 17 /* [HGM] for in declarations */ #define BOARD_FILES 16 /* [HGM] for in declarations */ #define BOARD_HEIGHT (gameInfo.boardHeight) /* [HGM] made user adjustable */ #define BOARD_WIDTH (gameInfo.boardWidth + 2*gameInfo.holdingsWidth) @@ -182,7 +182,7 @@ typedef char *String; #define VIRGIN (BOARD_RANKS-2) /* [HGM] pieces not moved */ #define EP_STATUS CASTLING][(BOARD_FILES-2) /* [HGM] in upper rank */ #define HOLDINGS_SET CASTLING][(BOARD_FILES-1) /* [HGM] in upper-right corner*/ -#define ONE ('1'-(BOARD_HEIGHT>9)) /* [HGM] foremost board rank */ +#define ONE ('1'-(BOARD_HEIGHT==10)) /* [HGM] foremost board rank */ #define AAA ('a'-BOARD_LEFT) /* [HGM] leftmost board file */ #define VIRGIN_W 1 /* [HGM] flags in Board[VIRGIN][X] */ #define VIRGIN_B 2 @@ -288,12 +288,20 @@ typedef enum { WhitePawn, WhiteKnight, WhiteBishop, WhiteRook, WhiteQueen, WhiteFerz, WhiteAlfil, WhiteAngel, WhiteMarshall, WhiteWazir, WhiteMan, WhiteCannon, WhiteNightrider, WhiteCardinal, WhiteDragon, WhiteGrasshopper, - WhiteSilver, WhiteFalcon, WhiteLance, WhiteCobra, WhiteUnicorn, WhiteKing, + WhiteSilver, WhiteFalcon, WhiteLance, WhiteCobra, WhiteUnicorn, WhiteLion, + WhiteTokin, WhiteDagger, WhitePCardinal, WhitePDragon, WhiteCat, + WhitePSword, WhiteMonarch, WhiteMother, WhiteNothing, WhitePRook, WhitePDagger, + WhiteDolphin, WhiteStag, WhiteHorned, WhiteEagle, WhiteSword, + WhiteCrown, WhiteHCrown, WhiteHorse, WhiteDrunk, WhitePBishop, WhiteKing, BlackPawn, BlackKnight, BlackBishop, BlackRook, BlackQueen, BlackFerz, BlackAlfil, BlackAngel, BlackMarshall, BlackWazir, BlackMan, BlackCannon, BlackNightrider, BlackCardinal, BlackDragon, BlackGrasshopper, - BlackSilver, BlackFalcon, BlackLance, BlackCobra, BlackUnicorn, BlackKing, - EmptySquare, + BlackSilver, BlackFalcon, BlackLance, BlackCobra, BlackUnicorn, BlackLion, + BlackTokin, BlackDagger, BlackPCardinal, BlackPDragon, BlackCat, + BlackPSword, BlackMonarch, BlackMother, BlackNothing, BlackPRook, BlackPDagger, + BlackDolphin, BlackStag, BlackHorned, BlackEagle, BlackSword, + BlackCrown, BlackHCrown, BlackHorse, BlackDrunk, BlackPBishop, BlackKing, + EmptySquare, DarkSquare, NoRights, // [HGM] gamestate: for castling rights hidden in board[CASTLING] ClearBoard, WhitePlay, BlackPlay, PromotePiece, DemotePiece /*for use on EditPosition menus*/ } ChessSquare; @@ -304,6 +312,10 @@ typedef enum { #define PROMOTED (int)WhiteDragon - (int)WhiteRook + (int) #define DEMOTED (int)WhiteRook - (int)WhiteDragon + (int) #define SHOGI (int)EmptySquare + (int) +#define CHUPROMOTED ((int)WhitePDragon - (int)WhiteDragon)*(gameInfo.variant == VariantChu) + PROMOTED +#define CHUDEMOTED ((int)WhiteDragon - (int)WhitePDragon)*(gameInfo.variant == VariantChu) + DEMOTED +#define IS_SHOGI(V) ((V) == VariantShogi || (V) == VariantChu) +#define IS_LION(V) ((V) == WhiteLion || (V) == BlackLion) typedef ChessSquare Board[BOARD_RANKS][BOARD_FILES]; @@ -319,7 +331,7 @@ typedef enum { WhitePromotion, WhiteNonPromotion, BlackPromotion, BlackNonPromotion, WhiteCapturesEnPassant, BlackCapturesEnPassant, - WhiteDrop, BlackDrop, + WhiteDrop, BlackDrop, FirstLeg, NormalMove, AmbiguousMove, IllegalMove, ImpossibleMove, WhiteWins, BlackWins, GameIsDrawn, GameUnfinished, GNUChessGame, XBoardGame, MoveNumberOne, Open, Close, Nothing, @@ -333,7 +345,7 @@ typedef enum { } ColorClass; typedef enum { - SoundMove, SoundBell, SoundAlarm, SoundIcsWin, SoundIcsLoss, + SoundMove, SoundBell, SoundRoar, SoundAlarm, SoundIcsWin, SoundIcsLoss, SoundIcsDraw, SoundIcsUnfinished, NSoundClasses } SoundClass; @@ -363,6 +375,7 @@ typedef enum { Variant35, /* Temporary name for possible future ICC wild 35 */ Variant36, /* Temporary name for possible future ICC wild 36 */ VariantShogi, /* [HGM] added variants */ + VariantChu, VariantXiangqi, VariantCourier, VariantGothic, @@ -378,9 +391,12 @@ typedef enum { VariantGreat, VariantTwilight, VariantMakruk, + VariantASEAN, VariantSChess, VariantGrand, VariantSpartan, + VariantLion, + VariantChuChess, VariantUnknown /* Catchall for other unknown variants */ } VariantClass; @@ -409,6 +425,7 @@ typedef enum { "wild35", \ "wild36", \ "shogi", \ + "chu", \ "xiangqi", \ "courier", \ "gothic", \ @@ -424,9 +441,12 @@ typedef enum { "great",\ "twilight",\ "makruk",\ + "asean",\ "seirawan",\ "grand",\ "spartan",\ + "lion",\ + "chuchess",\ "unknown" \ } @@ -493,6 +513,7 @@ typedef struct { char *loadPositionFile; int loadPositionIndex; /* position # within file */ char *savePositionFile; + Boolean fischerCastling;/* [HGM] fischer: allow Fischr castling in any variant */ Boolean matchMode; int matchGames; Boolean monoMode; @@ -508,15 +529,18 @@ typedef struct { char *clockFont; char *messageFont; /* WinBoard only */ char *coordFont; - char *font; /* xboard only: all other fonts */ - char *tagsFont; /* WinBoard only */ - char *commentFont; /* WinBoard only */ - char *icsFont; /* WinBoard only */ + char *font; /* xboard only */ + char *tagsFont; + char *commentFont; + char *historyFont; + char *gameListFont; + char *icsFont; Boolean ringBellAfterMoves; Boolean autoCallFlag; Boolean flipView; Boolean autoFlipView; char *cmailGameName; /* xboard only */ + Boolean headers; Boolean alwaysPromoteToQueen; Boolean oldSaveStyle; Boolean oneClick; @@ -562,6 +586,7 @@ typedef struct { char *soundSeek; char *soundMove; // [HGM] IMPORTANT: order must be as in SoundClass char *soundBell; + char *soundRoar; char *soundIcsAlarm; char *soundIcsWin; char *soundIcsLoss; @@ -609,6 +634,7 @@ typedef struct { int darkBackTextureMode; char * renderPiecesWithFont; /* Name of font for rendering chess pieces */ char * fontToPieceTable; /* Map to translate font character to chess pieces */ + char * inscriptions; /* text (kanji) to write on top of a piece */ int fontBackColorWhite; int fontForeColorWhite; int fontBackColorBlack; @@ -638,6 +664,7 @@ typedef struct { int adjudicateDrawMoves; Boolean autoDisplayComment; Boolean autoDisplayTags; + Boolean pseudo[ENGINES]; /* [HGM] pseudo-engines */ Boolean isUCI[ENGINES]; Boolean hasOwnBookUCI[ENGINES]; char * adapterCommand; @@ -691,13 +718,16 @@ typedef struct { int zippyShortGame; /* [HGM] aborter */ #endif Boolean lowTimeWarning; /* [HGM] low time */ + Boolean quitNext; char *lowTimeWarningColor; char *serverFileName; char *serverMovesName; + char *finger; Boolean suppressLoadMoves; int serverPause; int timeOdds[ENGINES]; + int drawDepth[ENGINES]; int timeOddsMode; int accumulateTC[ENGINES]; int NPS[ENGINES]; @@ -708,6 +738,8 @@ typedef struct { int dateThreshold; int searchMode; int stretch; + int minPieces; + int maxPieces; Boolean ignoreColors; Boolean findMirror; char *userName; @@ -831,6 +863,7 @@ extern WindowPlacement wpEvalGraph; extern WindowPlacement wpMoveHistory; extern WindowPlacement wpGameList; extern WindowPlacement wpTags; +extern WindowPlacement wpTextMenu; #define MAXENGINES 2000 diff --git a/conf/chu b/conf/chu new file mode 100644 index 0000000..45195ef --- /dev/null +++ b/conf/chu @@ -0,0 +1,42 @@ +; +; settings for oriental Chu-Shogi theme +; +-variant chu +; +; pieces: supplied chu-shogi svg's, and flip them in flipView +; +-pid ~~/themes/chu +-flipBlack true +-trueColors true +; +; board: no checkering (both w. and w.o. texture) +; +-liteBackTextureFile "~~/themes/textures/wood_l.png" +-darkBackTextureFile "~~/themes/textures/wood_l.png" +-lightSquareColor #FF8040 +-darkSquareColor #FF8040 +; +; detour under-promotion is less convenient when non-pawns promote +; +-sweepPromotions false +; +; legality testing must be on for double-moves to work, no adjudication +; +-testLegality true +-trivialDraws false +-materialDraws false +; +; make the Lion roar on double captures +; +-roarSound roar.wav +; +; redefine default engine +; +-fcp hachu +-scp hachu +; +; set up own persistence file, used for this theme only +; +-settingsFile ~/.xboard-chu-rc +-saveSettingsFile ~/.xboard-chu-rc + diff --git a/conf/ics b/conf/ics new file mode 100644 index 0000000..9823c73 --- /dev/null +++ b/conf/ics @@ -0,0 +1,10 @@ +; +; settings for Internet Chess Server client +; +-ics +; +; set up own persistence file, used for ICS play +; +-settingsFile ~/.xboard-ics-rc +-saveSettingsFile ~/.xboard-ics-rc + diff --git a/conf/judkins b/conf/judkins new file mode 100644 index 0000000..250369d --- /dev/null +++ b/conf/judkins @@ -0,0 +1,19 @@ +; +; additional settings for Judkins Shogi +; +-variant shogi +; +; size overrides +; +-boardWidth 6 +-boardHeight 6 +-holdingsSize 6 +; +; remove L from piece set +; +-pieceToCharTable "PNBR.S...G.++++.+Kpnbr.s...g.++++.+k" +; +; provide initial position +; +-loadPositionFile "~~/themes/conf/judkins.fen" + diff --git a/conf/judkins.fen b/conf/judkins.fen new file mode 100644 index 0000000..d805858 --- /dev/null +++ b/conf/judkins.fen @@ -0,0 +1,2 @@ +rbnsgk/6p/6/6/P5/KGSNBR w 0 1 + diff --git a/conf/mini b/conf/mini new file mode 100644 index 0000000..ee6fce6 --- /dev/null +++ b/conf/mini @@ -0,0 +1,24 @@ +; +; additional settings for mini-Shogi +; +-variant shogi +; +; size overrides +; +-boardWidth 5 +-boardHeight 5 +-holdingsSize 5 +; +; remove L and N from piece set +; +-pieceToCharTable "P.BR.S...G.+.++.+Kp.br.s...g.+.++.+k" +; +; redefine default engine +; +-fcp gnuminishogi +-scp gnuminishogi +; +; provide initial position +; +-loadPositionFile "~~/themes/conf/mini.fen" + diff --git a/conf/mini.fen b/conf/mini.fen new file mode 100644 index 0000000..7ddea3a --- /dev/null +++ b/conf/mini.fen @@ -0,0 +1,2 @@ +rbsgk/4p/5/P4/KGSBR w 0 1 + diff --git a/conf/sho b/conf/sho new file mode 100644 index 0000000..7b48f27 --- /dev/null +++ b/conf/sho @@ -0,0 +1,28 @@ +; +; additional settings for Sho Shogi +; +-variant shogi +; +; size overrides +; +-boardWidth 9 +-boardHeight 9 +-holdingsSize 0 +; +; add Elephant to piece set +; +-pieceToCharTable "PNBRLSE..G.+++++++Kpnbrlse..g.+++++++k" +; +; provide initial position +; +-loadPositionFile "~~/themes/conf/sho.fen" +; +; must play with legality testing off, for +E and mate +; +-testLegality false +; +; redefine default engine +; +-fcp hachu +-scp hachu + diff --git a/conf/sho.fen b/conf/sho.fen new file mode 100644 index 0000000..689e5a6 --- /dev/null +++ b/conf/sho.fen @@ -0,0 +1,2 @@ +lnsgkgsnl/1r2e2b1/ppppppppp/9/9/9/PPPPPPPPP/1B2E2R1/LNSGKGSNL w 0 1 + diff --git a/conf/shogi b/conf/shogi new file mode 100644 index 0000000..90cde91 --- /dev/null +++ b/conf/shogi @@ -0,0 +1,41 @@ +; +; settings for oriental Shogi theme +; +-variant shogi +; +; pieces: supplied shogi svg's, and flip them in flipView +; +-pid ~~/themes/shogi +-flipBlack true +-trueColors true +; +; board: no checkering (both w. and w.o. texture) +; +-liteBackTextureFile "~~/themes/textures/wood_l.png" +-darkBackTextureFile "~~/themes/textures/wood_l.png" +-lightSquareColor #FF8040 +-darkSquareColor #FF8040 +; +; detour under-promotion is less convenient when non-pawns promote +; +-sweepPromotions false +; +; no adjudication +; +-trivialDraws false +-materialDraws false +; +; common non-compliant notations +; +-colorNickNames "sg" +; +; redefine default engine +; +-fcp gnushogi +-scp gnushogi +; +; set up own persistence file, used for this theme only +; +-settingsFile ~/.xboard-shogi-rc +-saveSettingsFile ~/.xboard-shogi-rc + diff --git a/conf/xiangqi b/conf/xiangqi new file mode 100644 index 0000000..23aeb36 --- /dev/null +++ b/conf/xiangqi @@ -0,0 +1,30 @@ +; +; settings for oriental Xiangqi theme +; +-variant xiangqi +; +; pieces: supplied xiangqi svg's +; +-pid ~~/themes/xiangqi +-trueColors true +; +; board: supplied board bitmap +; +-liteBackTextureFile "~~/themes/textures/xqboard.png" +-darkBackTextureFile "~~/themes/textures/xqboard.png" +; +; suppress square boundaries and highlight with arrow instead +; +-overrideLineGap 0 +-highlightMovesWithArrow true +; +; define common non-compliant notations +; +-pieceNickNames ".N...MB..G..n...mb..g." +-colorNickNames "r." +; +; set up own persistence file, used for this theme only +; +-settingsFile ~/.xboard-xiangqi-rc +-saveSettingsFile ~/.xboard-xiangqi-rc + diff --git a/conf/xq b/conf/xq new file mode 100644 index 0000000..fe659ba --- /dev/null +++ b/conf/xq @@ -0,0 +1,36 @@ +; +; settings for oriental Xiangqi theme +; +-variant xiangqi +; +; pieces: supplied xiangqi svg's +; +-pid ~~/themes/xiangqi +-trueColors true +; +; board: supplied board bitmap +; +-useBoardTexture true +-liteBackTextureFile "~~/themes/textures/xqboard.png" +-darkBackTextureFile "~~/themes/textures/xqboard.png" +; +; suppress square boundaries and highlight with arrow instead +; +-overrideLineGap 0 +-highlightMoveWithArrow true +; +; define common non-compliant notations +; +-pieceNickNames ".N...MB..G..n...mb..g." +-colorNickNames "r." +; +; set default engines +; +-fcp maxqi +-scp maxqi +; +; set up own persistence file, used for this theme only +; +-settingsFile ~/.xboard-xiangqi-rc +-saveSettingsFile ~/.xboard-xiangqi-rc + diff --git a/configure.ac b/configure.ac index 73cd86b..4cc6890 100644 --- a/configure.ac +++ b/configure.ac @@ -28,7 +28,7 @@ dnl| to regenerate configure. Then submit your changes to be folded into dnl| the standard version of xboard. dnl| define second argument as VERSION.PATCHLEVEL. e.g. 4.4.0j -AC_INIT([xboard],[4.7.3],[bug-xboard@gnu.org]) +AC_INIT([xboard],[master-20140119],[bug-xboard@gnu.org]) dnl| need this to be able to compile some files in a subdir (filebrowser) AM_INIT_AUTOMAKE([subdir-objects]) @@ -56,7 +56,6 @@ AH_TEMPLATE([USE_PTYS],[template]) AH_TEMPLATE([X_WCHAR],[template]) AH_TEMPLATE([ATTENTION],[template]) AH_TEMPLATE([DEFINED_SYS_ERRLIST],[template]) -AH_TEMPLATE([HAVE_LIBXPM],[template]) AH_TEMPLATE([USE_XAW3D],[template]) AH_TEMPLATE([X_LOCALE],[template]) @@ -138,24 +137,61 @@ FRONTEND_LIBS="" AC_ARG_WITH([gtk], [AS_HELP_STRING([--with-gtk],[use GTK front-end (experimental)])], - [with_GTK=yes], - [with_GTK=no]) + [with_GTK=$withval], + [with_GTK="no"]) AC_ARG_WITH([Xaw3d], [AS_HELP_STRING([--with-Xaw3d],[use Xaw3d front-end (not fully supported anymore)])], - [with_Xaw3d=yes], - [with_Xaw3d=no]) + [with_Xaw3d="$withval"], + [with_Xaw3d="no"]) AC_ARG_WITH([Xaw], [AS_HELP_STRING([--with-Xaw],[use Xaw front-end (default)])], - [with_Xaw=yes], - [with_Xaw=no]) + [with_Xaw="$withval"], + [with_Xaw="yes"]) + +AC_ARG_WITH([iconsdir], + [AS_HELP_STRING([--with-iconsdir=DIR], + [path where icons get installed (default: $datadir/icons/hicolor/48x48/apps)])], + [ICONSDIR="$withval"], + [ICONSDIR='$(datadir)/icons/hicolor/48x48/apps']) + +AC_ARG_WITH([svgiconsdir], + [AS_HELP_STRING([--with-svgiconsdir=DIR], + [path where svg icons get installed (default: $datadir/icons/hicolor/scalable/apps)])], + [SVGICONSDIR="$withval"], + [SVGICONSDIR='$(datadir)/icons/hicolor/scalable/apps']) + +AC_ARG_WITH([desktopdir], + [AS_HELP_STRING([--with-desktopdir=DIR], + [path where desktop files get installed (default: $datadir/applications)])], + [DESKTOPDIR="$withval"], + [DESKTOPDIR='$(datadir)/applications']) + +AC_ARG_WITH([mimedir], + [AS_HELP_STRING([--with-mimedir=DIR], + [path where mime files get installed (default: $datadir/mime/packages)])], + [MIMEDIR="$withval"], + [MIMEDIR='$(datadir)/mime/packages']) + +AC_ARG_WITH([gamedatadir], + [AS_HELP_STRING([--with-gamedatadir=DIR], + [path where game data files get installed (default: $datadir/games/xboard)])], + [GAMEDATADIR="$withval"], + [GAMEDATADIR='$(datadir)/games/xboard']) + +AC_SUBST(ICONSDIR) +AC_SUBST(SVGICONSDIR) +AC_SUBST(DESKTOPDIR) +AC_SUBST(MIMEDIR) +AC_SUBST(GAMEDATADIR) dnl | check for libraries if test x"$with_GTK" = x"yes" ; then PKG_CHECK_MODULES([GTK], [ gtk+-2.0 >= 2.16.0 gmodule-2.0 ]) FRONTEND_CFLAGS=$GTK_CFLAGS FRONTEND_LIBS=$GTK_LIBS + with_Xaw="no" fi if test x"$with_GTK" = x"no" ; then @@ -212,12 +248,7 @@ fi dnl | make results available in Makefile.am AM_CONDITIONAL([withGTK], [test x"$with_GTK" = x"yes"]) -AM_CONDITIONAL([withXaw], [test x"$with_Xaw3d" = x"yes"]) -AM_CONDITIONAL([withXaw], [test x"$with_Xaw" = x"yes"]) - - -AC_SUBST(FRONTEND_CFLAGS) -AC_SUBST(FRONTEND_LIBS) +AM_CONDITIONAL([withXaw], [test x"$with_Xaw3d" = x"yes" || test x"$with_Xaw" = x"yes"]) dnl | end Front-end check @@ -397,32 +428,28 @@ dnl| USE_PTYS=1 dnl| add some libs for OS X *-apple-* ) + AC_MSG_WARN([Apple support is experimental, please report any problems to bug-xboard@gnu.org]) + AC_PATH_PROG(SW_VERS, sw_vers) + if test "x$SW_VERS" != "x"; then + AC_MSG_CHECKING(Mac OS X version) + MACOSX_VERSION=`$SW_VERS -productVersion` + AC_MSG_RESULT([$MACOSX_VERSION]) + fi + case "$MACOSX_VERSION" in + 10.0*|10.1|10.1.*|10.2*|10.3*|10.4*|10.5*|10.6*) + FRONTEND_LIBS= "$FRONTEND_LIBS -lgtkmacintegration -headerpad_max_install_names mmacosx-version-min=10.6 -isysroot /Developer/SDKs/MacOSX10.6.sdk" + ;; + *) + FRONTEND_LIBS = "$FRONTEND_LIBS -lgtkmacintegration -headerpad_max_install_names" + ;; + esac + ;; esac -AC_ARG_ENABLE( [xpm], - [AS_HELP_STRING([--enable-xpm],[libXpm will be used if found (default)])], - [enable_xpm="$enableval"], - [enable_xpm="yes"]) - -if test x"$enable_xpm" != "xno"; then - save_cflags="$CFLAGS" - save_cppflags="$CPPFLAGS" - CFLAGS="$CFLAGS $X_CFLAGS" - CPPFLAGS="$CPPFLAGS $X_CFLAGS" - AC_CHECK_HEADERS(X11/xpm.h) - CFLAGS="$save_cflags" - CPPFLAGS="$save_cppflags" - if test "$ac_cv_header_X11_xpm_h" = "yes"; then - save_ldflags="$LDFLAGS" - LDFLAGS="$LDFLAGS $X_LIBS" - AC_CHECK_LIB(Xpm, XpmReadFileToPixmap, - [X_PRE_LIBS="-lXpm $X_PRE_LIBS"; AC_DEFINE(HAVE_LIBXPM)], [], - [$X_PRE_LIBS -lX11 $X_EXTRA_LIBS]) - LDFLAGS="$save_ldflags" - fi -fi +AC_SUBST(FRONTEND_CFLAGS) +AC_SUBST(FRONTEND_LIBS) AC_SUBST(PRE_XMULIB) AC_SUBST(POST_XMULIB) AC_SUBST(CONF_CFLAGS) @@ -501,6 +528,17 @@ if test x"$enable_mimedb" = "xyes"; then AC_SUBST(XDG_ICON_RESOURCE) fi +dnl create a string with configure options that can be passed to the +dnl program, good for bug reports and version printout, see output below +CONFIGURE_OPTIONS="prefix=$prefix; datarootdir=$datarootdir; \ +datadir=$datadir; gamedatadir=$GAMEDATADIR; desktopdir=$DESKTOPDIR; \ +mimedir=$MIMEDIR; iconsdir=$ICONSDIR; svgiconsdir=$SVGICONSDIR; infodir=$infodir; \ +sysconfigdir=$sysconfigdir; update_mimedb=$enable_mimedb; NLS=$USE_NLS; \ +GKT=$with_GTK; Xaw3d=$with_Xaw3d; Xaw=$with_Xaw; \ +ptys=$enable_ptys; zippy=$enable_zippy; sigint=$enable_sigint" + +AC_SUBST(CONFIGURE_OPTIONS) + dnl | output Makefile AC_CONFIG_FILES([Makefile cmail po/Makefile.in]) AC_CONFIG_COMMANDS([test-stamp-h],[test -z "$CONFIG_HEADERS" || date > stamp-h]) @@ -515,8 +553,12 @@ echo " Configurations summary:" echo "" echo " prefix: $prefix " echo " datarootdir: $datarootdir " -echo " datadir: $datadir (icons will go in \$datadir/icons/hicolor/...)" -echo " (bitmaps will go in \$datadir/games/xboard/...)" +echo " datadir: $datadir " +echo " gamedatadir: $GAMEDATADIR " +echo " desktopdir: $DESKTOPDIR " +echo " mimedir: $MIMEDIR " +echo " iconsdir: $ICONSDIR " +echo " svgiconsdir: $SVGICONSDIR " echo " infodir: $infodir (info files will go here)" echo " sysconfdir: $sysconfdir (xboard.conf will go here)" echo "" @@ -528,7 +570,6 @@ echo " GTK: $with_GTK" echo " Xaw3d: $with_Xaw3d" echo " Xaw: $with_Xaw" echo "" -echo " xpm: $enable_xpm" echo " ptys: $enable_ptys" echo " zippy: $enable_zippy" echo " sigint: $enable_sigint" diff --git a/dialogs.c b/dialogs.c index bb98b3f..8da6557 100644 --- a/dialogs.c +++ b/dialogs.c @@ -184,12 +184,14 @@ GenericReadout (Option *opts, int selected) if(x < opts[i].min) x = opts[i].min; if(opts[i].type == Fractional) *(float*) opts[i].target = x; // engines never have float options! - else if(opts[i].value != x) { - opts[i].value = x; + else { if(currentCps) { + if(opts[i].value != x) { // only to engine if changed snprintf(buf, MSG_SIZ, "option %s=%.0f\n", opts[i].name, x); SendToProgram(buf, currentCps); + } } else *(int*) opts[i].target = x; + opts[i].value = x; } break; case CheckBox: @@ -218,7 +220,7 @@ GenericReadout (Option *opts, int selected) } break; case EndMark: - if(opts[i].target) // callback for implementing necessary actions on OK (like redraw) + if(opts[i].target && selected != -2) // callback for implementing necessary actions on OK (like redraw) res = ((OKCallback*) opts[i].target)(i); break; default: @@ -228,6 +230,7 @@ GenericReadout (Option *opts, int selected) case SaveButton: case Label: case Break: + case Skip: break; } if(opts[i].type == EndMark) break; @@ -244,23 +247,43 @@ static void AddToTourney P((int n, int sel)); static void CloneTourney P((void)); static void ReplaceParticipant P((void)); static void UpgradeParticipant P((void)); +static void PseudoOK P((void)); static int MatchOK (int n) { ASSIGN(appData.participants, engineName); if(!CreateTourney(tfName) || matchMode) return matchMode || !appData.participants[0]; - PopDown(TransientDlg); // early popdown to prevent FreezeUI called through MatchEvent from causing XtGrab warning + PopDown(MasterDlg); // early popdown to prevent FreezeUI called through MatchEvent from causing XtGrab warning MatchEvent(2); // start tourney return FALSE; // no double PopDown! } +static void +DoTimeControl(int n) +{ + TimeControlProc(); +} + +static void +DoCommonEngine(int n) +{ + UciMenuProc(); +} + +static void +DoGeneral(int n) +{ + OptionsProc(); +} + +#define PARTICIPANTS 6 /* This MUST be the number of the Option for &engineName!*/ + static Option matchOptions[] = { { 0, 0, 0, NULL, (void*) &tfName, ".trn", NULL, FileName, N_("Tournament file: ") }, +{ 0, 0, 0, NULL, NULL, "", NULL, Label, N_("For concurrent playing of tourney with multiple XBoards:") }, { 0, 0, 0, NULL, (void*) &appData.roundSync, "", NULL, CheckBox, N_("Sync after round") }, -{ 0, SAME_ROW|LL, 0, NULL, NULL, "", NULL, Label, N_(" (for concurrent playing of a single") }, { 0, 0, 0, NULL, (void*) &appData.cycleSync, "", NULL, CheckBox, N_("Sync after cycle") }, -{ 0, SAME_ROW|LL, 0, NULL, NULL, "", NULL, Label, N_(" tourney with multiple XBoards)") }, { 0, LR, 175, NULL, NULL, "", NULL, Label, N_("Tourney participants:") }, { 0, SAME_ROW|RR, 175, NULL, NULL, "", NULL, Label, N_("Select Engine:") }, { 150, T_VSCRL | T_FILL | T_WRAP, @@ -281,6 +304,10 @@ static Option matchOptions[] = { { 0, -2, 1000000000, NULL, (void*) &appData.loadPositionIndex, "", NULL, Spin, N_("Position Number (-1 or -2 = Auto-Increment):") }, { 0, 0, 1000000000, NULL, (void*) &appData.rewindIndex, "", NULL, Spin, N_("Rewind Index after this many Games (0 = never):") }, { 0, 0, 0, NULL, (void*) &appData.defNoBook, "", NULL, CheckBox, N_("Disable own engine books by default") }, +{ 0, 0, 0, NULL, (void*) &DoTimeControl, NULL, NULL, Button, N_("Time Control") }, +{ 0, SAME_ROW, 0, NULL, (void*) &DoCommonEngine, NULL, NULL, Button, N_("Common Engine") }, +{ 0, SAME_ROW, 0, NULL, (void*) &DoGeneral, NULL, NULL, Button, N_("General Options") }, +{ 0, SAME_ROW, 0, NULL, (void*) &PseudoOK, NULL, NULL, Button, N_("Continue Later") }, { 0, 0, 0, NULL, (void*) &ReplaceParticipant, NULL, NULL, Button, N_("Replace Engine") }, { 0, SAME_ROW, 0, NULL, (void*) &UpgradeParticipant, NULL, NULL, Button, N_("Upgrade Engine") }, { 0, SAME_ROW, 0, NULL, (void*) &CloneTourney, NULL, NULL, Button, N_("Clone Tourney") }, @@ -290,18 +317,26 @@ static Option matchOptions[] = { static void ReplaceParticipant () { - GenericReadout(matchOptions, 7); + GenericReadout(matchOptions, PARTICIPANTS); Substitute(strdup(engineName), True); } static void UpgradeParticipant () { - GenericReadout(matchOptions, 7); + GenericReadout(matchOptions, PARTICIPANTS); Substitute(strdup(engineName), False); } static void +PseudoOK () +{ + GenericReadout(matchOptions, -2); // read all, but suppress calling of MatchOK + ASSIGN(appData.participants, engineName); + PopDown(MasterDlg); // early popdown to prevent FreezeUI called through MatchEvent from causing XtGrab warning +} + +static void CloneTourney () { FILE *f; @@ -324,24 +359,28 @@ AddToTourney (int n, int sel) if(sel < 1) buf[0] = NULLCHAR; // back to top level else if(engineList[sel][0] == '#') safeStrCpy(buf, engineList[sel], MSG_SIZ); // group header, open group else { // normal line, select engine - AddLine(&matchOptions[7], engineMnemonic[sel]); + AddLine(&matchOptions[PARTICIPANTS], engineMnemonic[sel]); return; } nr = NamesToList(firstChessProgramNames, engineList, engineMnemonic, buf); // replace list by only the group contents ASSIGN(engineMnemonic[0], buf); - LoadListBox(&matchOptions[8], _("# no engines are installed"), -1, -1); - HighlightWithScroll(&matchOptions[8], 0, nr); + LoadListBox(&matchOptions[PARTICIPANTS+1], _("# no engines are installed"), -1, -1); + HighlightWithScroll(&matchOptions[PARTICIPANTS+1], 0, nr); } void MatchOptionsProc () { + if(matchOptions[PARTICIPANTS+1].type != ListBox) { + DisplayError(_("Internal error: PARTICIPANTS set wrong"), 0); + return; + } NamesToList(firstChessProgramNames, engineList, engineMnemonic, ""); matchOptions[9].min = -(appData.pairingEngine[0] != NULLCHAR); // with pairing engine, allow Swiss ASSIGN(tfName, appData.tourneyFile[0] ? appData.tourneyFile : MakeName(appData.defName)); ASSIGN(engineName, appData.participants); ASSIGN(engineMnemonic[0], ""); - GenericPopUp(matchOptions, _("Match Options"), TransientDlg, BoardWindow, MODAL, 0); + GenericPopUp(matchOptions, _("Tournament Options"), MasterDlg, BoardWindow, MODAL, 0); } // ------------------------------------------- General Options -------------------------------------------------- @@ -367,8 +406,10 @@ static Option generalOptions[] = { { 0, 0, 0, NULL, (void*) &appData.autoCallFlag, "", NULL, CheckBox, N_("Auto Flag") }, { 0, 0, 0, NULL, (void*) &appData.autoFlipView, "", NULL, CheckBox, N_("Auto Flip View") }, { 0, 0, 0, NULL, (void*) &appData.blindfold, "", NULL, CheckBox, N_("Blindfold") }, +/* TRANSLATORS: the drop menu is used to drop a piece, e.g. during bughouse or editing a position */ { 0, 0, 0, NULL, (void*) &appData.dropMenu, "", NULL, CheckBox, N_("Drop Menu") }, { 0, 0, 0, NULL, (void*) &appData.variations, "", NULL, CheckBox, N_("Enable Variation Trees") }, +{ 0, 0, 0, NULL, (void*) &appData.headers, "", NULL, CheckBox, N_("Headers in Engine Output Window") }, { 0, 0, 0, NULL, (void*) &appData.hideThinkingFromHuman, "", NULL, CheckBox, N_("Hide Thinking from Human") }, { 0, 0, 0, NULL, (void*) &appData.highlightLastMove, "", NULL, CheckBox, N_("Highlight Last Move") }, { 0, 0, 0, NULL, (void*) &appData.highlightMoveWithArrow, "", NULL, CheckBox, N_("Highlight with Arrow") }, @@ -405,47 +446,66 @@ OptionsProc () static void Pick P((int n)); static char warning[MSG_SIZ]; +static int ranksTmp, filesTmp, sizeTmp; static Option variantDescriptors[] = { -{ VariantNormal, 0, 135, NULL, (void*) &Pick, "#FFFFFF", NULL, Button, N_("normal")}, -{ VariantMakruk, SAME_ROW, 135, NULL, (void*) &Pick, "#FFFFFF", NULL, Button, N_("makruk")}, +{ VariantNormal, 0, 135, NULL, (void*) &Pick, "#FFFFFF", NULL, Button, N_("Normal")}, +{ VariantMakruk, SAME_ROW, 135, NULL, (void*) &Pick, "#FFFFFF", NULL, Button, N_("Makruk")}, { VariantFischeRandom, 0, 135, NULL, (void*) &Pick, "#FFFFFF", NULL, Button, N_("FRC")}, -{ VariantShatranj,SAME_ROW,135, NULL, (void*) &Pick, "#FFFFFF", NULL, Button, N_("shatranj")}, -{ VariantWildCastle, 0, 135, NULL, (void*) &Pick, "#FFFFFF", NULL, Button, N_("wild castle")}, -{ VariantKnightmate,SAME_ROW,135,NULL,(void*) &Pick, "#FFFFFF", NULL, Button, N_("knightmate")}, -{ VariantNoCastle, 0, 135, NULL, (void*) &Pick, "#FFFFFF", NULL, Button, N_("no castle")}, -{ VariantCylinder,SAME_ROW,135, NULL, (void*) &Pick, "#FFFFFF", NULL, Button, N_("cylinder *")}, +{ VariantShatranj,SAME_ROW,135, NULL, (void*) &Pick, "#FFFFFF", NULL, Button, N_("Shatranj")}, +{ VariantWildCastle, 0, 135, NULL, (void*) &Pick, "#FFFFFF", NULL, Button, N_("Wild castle")}, +{ VariantKnightmate,SAME_ROW,135,NULL,(void*) &Pick, "#FFFFFF", NULL, Button, N_("Knightmate")}, +{ VariantNoCastle, 0, 135, NULL, (void*) &Pick, "#FFFFFF", NULL, Button, N_("No castle")}, +{ VariantCylinder,SAME_ROW,135, NULL, (void*) &Pick, "#FFFFFF", NULL, Button, N_("Cylinder *")}, { Variant3Check, 0, 135, NULL, (void*) &Pick, "#FFFFFF", NULL, Button, N_("3-checks")}, { VariantBerolina,SAME_ROW,135, NULL, (void*) &Pick, "#FFFFFF", NULL, Button, N_("berolina *")}, { VariantAtomic, 0, 135, NULL, (void*) &Pick, "#FFFFFF", NULL, Button, N_("atomic")}, { VariantTwoKings,SAME_ROW,135, NULL, (void*) &Pick, "#FFFFFF", NULL, Button, N_("two kings")}, +{ -1, 0, 135, NULL, (void*) &Pick, "#FFFFFF", NULL, Button, N_(" ")}, // dummy, to have good alignment +{ VariantSpartan,SAME_ROW, 135, NULL, (void*) &Pick, "#FF0000", NULL, Button, N_("Spartan")}, { 0, 0, 0, NULL, NULL, NULL, NULL, Label, N_("Board size ( -1 = default for selected variant):")}, -{ 0, -1, BOARD_RANKS-1, NULL, (void*) &appData.NrRanks, "", NULL, Spin, N_("Number of Board Ranks:") }, -{ 0, -1, BOARD_FILES, NULL, (void*) &appData.NrFiles, "", NULL, Spin, N_("Number of Board Files:") }, -{ 0, -1, BOARD_RANKS-1, NULL, (void*) &appData.holdingsSize, "", NULL, Spin, N_("Holdings Size:") }, +{ 0, -1, BOARD_RANKS-1, NULL, (void*) &ranksTmp, "", NULL, Spin, N_("Number of Board Ranks:") }, +{ 0, -1, BOARD_FILES, NULL, (void*) &filesTmp, "", NULL, Spin, N_("Number of Board Files:") }, +{ 0, -1, BOARD_RANKS-1, NULL, (void*) &sizeTmp, "", NULL, Spin, N_("Holdings Size:") }, { 0, 0, 275, NULL, NULL, NULL, NULL, Label, warning }, -{ 0, 0, 275, NULL, NULL, NULL, NULL, Label, "Variants marked with * can only be played\nwith legality testing off"}, +{ 0, 0, 275, NULL, NULL, NULL, NULL, Label, N_("Variants marked with * can only be played\nwith legality testing off.")}, { 0, SAME_ROW, 0, NULL, NULL, NULL, NULL, Break, ""}, -{ VariantFairy, 0, 135, NULL, (void*) &Pick, "#BFBFBF", NULL, Button, N_("fairy")}, +{ VariantASEAN, 0, 135, NULL, (void*) &Pick, "#FFFFFF", NULL, Button, N_("ASEAN")}, { VariantGreat, SAME_ROW, 135, NULL, (void*) &Pick, "#BFBFFF", NULL, Button, N_("Great Shatranj (10x8)")}, { VariantSChess, 0, 135, NULL, (void*) &Pick, "#FFBFBF", NULL, Button, N_("Seirawan")}, -{ VariantFalcon, SAME_ROW, 135, NULL, (void*) &Pick, "#BFBFFF", NULL, Button, N_("falcon (10x8)")}, +{ VariantFalcon, SAME_ROW, 135, NULL, (void*) &Pick, "#BFBFFF", NULL, Button, N_("Falcon (10x8)")}, { VariantSuper, 0, 135, NULL, (void*) &Pick, "#FFBFBF", NULL, Button, N_("Superchess")}, { VariantCapablanca,SAME_ROW,135,NULL,(void*) &Pick, "#BFBFFF", NULL, Button, N_("Capablanca (10x8)")}, -{ VariantCrazyhouse, 0, 135, NULL, (void*) &Pick, "#FFBFBF", NULL, Button, N_("crazyhouse")}, +{ VariantCrazyhouse, 0, 135, NULL, (void*) &Pick, "#FFBFBF", NULL, Button, N_("Crazyhouse")}, { VariantGothic, SAME_ROW, 135, NULL, (void*) &Pick, "#BFBFFF", NULL, Button, N_("Gothic (10x8)")}, -{ VariantBughouse, 0, 135, NULL, (void*) &Pick, "#FFBFBF", NULL, Button, N_("bughouse")}, -{ VariantJanus, SAME_ROW, 135, NULL, (void*) &Pick, "#BFBFFF", NULL, Button, N_("janus (10x8)")}, -{ VariantSuicide, 0, 135, NULL, (void*) &Pick, "#FFFFBF", NULL, Button, N_("suicide")}, +{ VariantBughouse, 0, 135, NULL, (void*) &Pick, "#FFBFBF", NULL, Button, N_("Bughouse")}, +{ VariantJanus, SAME_ROW, 135, NULL, (void*) &Pick, "#BFBFFF", NULL, Button, N_("Janus (10x8)")}, +{ VariantSuicide, 0, 135, NULL, (void*) &Pick, "#FFFFBF", NULL, Button, N_("Suicide")}, { VariantCapaRandom,SAME_ROW,135,NULL,(void*) &Pick, "#BFBFFF", NULL, Button, N_("CRC (10x8)")}, { VariantGiveaway, 0, 135, NULL, (void*) &Pick, "#FFFFBF", NULL, Button, N_("give-away")}, { VariantGrand, SAME_ROW, 135, NULL, (void*) &Pick, "#5070FF", NULL, Button, N_("grand (10x10)")}, { VariantLosers, 0, 135, NULL, (void*) &Pick, "#FFFFBF", NULL, Button, N_("losers")}, { VariantShogi, SAME_ROW, 135, NULL, (void*) &Pick, "#BFFFFF", NULL, Button, N_("shogi (9x9)")}, -{ VariantSpartan, 0, 135, NULL, (void*) &Pick, "#FF0000", NULL, Button, N_("Spartan")}, +{ VariantFairy, 0, 135, NULL, (void*) &Pick, "#BFBFBF", NULL, Button, N_("fairy")}, { VariantXiangqi, SAME_ROW,135, NULL, (void*) &Pick, "#BFFFFF", NULL, Button, N_("xiangqi (9x10)")}, -{ -1, 0, 135, NULL, (void*) &Pick, "#FFFFFF", NULL, Button, N_(" ")}, // dummy, to have good alignment +{ VariantLion, 0, 135, NULL, (void*) &Pick, "#BFBFBF", NULL, Button, N_("mighty lion")}, { VariantCourier, SAME_ROW,135, NULL, (void*) &Pick, "#BFFFBF", NULL, Button, N_("courier (12x8)")}, +{ VariantChuChess, 0, 135, NULL, (void*) &Pick, "#BFBFBF", NULL, Button, N_("chu chess (10x10)")}, +{ VariantChu, SAME_ROW, 135, NULL, (void*) &Pick, "#BFFFBF", NULL, Button, N_("chu shogi (12x12)")}, +//{ -1, 0, 135, NULL, (void*) &Pick, "#FFFFFF", NULL, Button, N_(" ")}, // dummy, to have good alignment +// optional buttons for engine-defined variants +{ VariantUnknown, 0, 135, NULL, (void*) &Pick, "#FFFFFF", NULL, Skip, NULL }, +{ VariantUnknown, SAME_ROW,135, NULL, (void*) &Pick, "#FFFFFF", NULL, Skip, NULL }, +{ VariantUnknown, 0, 135, NULL, (void*) &Pick, "#FFFFFF", NULL, Skip, NULL }, +{ VariantUnknown, SAME_ROW,135, NULL, (void*) &Pick, "#FFFFFF", NULL, Skip, NULL }, +{ VariantUnknown, 0, 135, NULL, (void*) &Pick, "#FFFFFF", NULL, Skip, NULL }, +{ VariantUnknown, SAME_ROW,135, NULL, (void*) &Pick, "#FFFFFF", NULL, Skip, NULL }, +{ VariantUnknown, 0, 135, NULL, (void*) &Pick, "#FFFFFF", NULL, Skip, NULL }, +{ VariantUnknown, SAME_ROW,135, NULL, (void*) &Pick, "#FFFFFF", NULL, Skip, NULL }, +{ VariantUnknown, 0, 135, NULL, (void*) &Pick, "#FFFFFF", NULL, Skip, NULL }, +{ VariantUnknown, SAME_ROW,135, NULL, (void*) &Pick, "#FFFFFF", NULL, Skip, NULL }, +{ VariantUnknown, 0, 135, NULL, (void*) &Pick, "#FFFFFF", NULL, Skip, NULL }, +{ VariantUnknown, SAME_ROW,135, NULL, (void*) &Pick, "#FFFFFF", NULL, Skip, NULL }, { 0, NO_OK, 0, NULL, NULL, "", NULL, EndMark , "" } }; @@ -453,27 +513,30 @@ static void Pick (int n) { VariantClass v = variantDescriptors[n].value; + if(v == VariantUnknown) safeStrCpy(engineVariant, variantDescriptors[n].name, MSG_SIZ); else *engineVariant = NULLCHAR; + GenericReadout(variantDescriptors, -1); // read new ranks and file settings if(!appData.noChessProgram) { - char *name = VariantName(v), buf[MSG_SIZ]; - if (first.protocolVersion > 1 && StrStr(first.variants, name) == NULL) { - /* [HGM] in protocol 2 we check if variant is suported by engine */ - snprintf(buf, MSG_SIZ, _("Variant %s not supported by %s"), name, first.tidy); - DisplayError(buf, 0); + char buf[MSG_SIZ]; + if (!SupportedVariant(first.variants, v, filesTmp, ranksTmp, sizeTmp, first.protocolVersion, first.tidy)) { + DisplayError(variantError, 0); return; /* ignore OK if first engine does not support it */ } else - if (second.initDone && second.protocolVersion > 1 && StrStr(second.variants, name) == NULL) { - snprintf(buf, MSG_SIZ, _("Warning: second engine (%s) does not support this!"), second.tidy); + if (second.initDone && + !SupportedVariant(second.variants, v, filesTmp, ranksTmp, sizeTmp, second.protocolVersion, second.tidy)) { + snprintf(buf, MSG_SIZ, _("Warning: second engine (%s) does not support this!"), second.tidy); DisplayError(buf, 0); /* use of second engine is optional; only warn user */ } } - GenericReadout(variantDescriptors, -1); // make sure ranks and file settings are read - gameInfo.variant = v; appData.variant = VariantName(v); shuffleOpenings = FALSE; /* [HGM] shuffle: possible shuffle reset when we switch */ startedFromPositionFile = FALSE; /* [HGM] loadPos: no longer valid in new variant */ + appData.fischerCastling = FALSE; /* [HGM] fischer: no longer valid in new variant */ + appData.NrRanks = ranksTmp; + appData.NrFiles = filesTmp; + appData.holdingsSize = sizeTmp; appData.pieceToCharTable = NULL; appData.pieceNickNames = ""; appData.colorNickNames = ""; @@ -485,9 +548,30 @@ Pick (int n) void NewVariantProc () { - if(appData.noChessProgram) sprintf(warning, _("Only bughouse is not available in viewer mode")); else - sprintf(warning, _("All variants not supported by first engine\n(currently %s) are disabled"), first.tidy); + static int start; + int i, last; + char buf[MSG_SIZ]; + ranksTmp = filesTmp = sizeTmp = -1; // prefer defaults over actual settings + if(appData.noChessProgram) sprintf(warning, _("Only bughouse is not available in viewer mode.")); else + sprintf(warning, _("All variants not supported by the first engine\n(currently %s) are disabled."), first.tidy); + if(!start) while(variantDescriptors[start].type != Skip) start++; // locate first spare + last = -1; + for(i=0; variantDescriptors[start+i].type != EndMark; i++) { // create buttons for engine-defined variants + char *v = EngineDefinedVariant(&first, i); + if(v) { + last = i; + ASSIGN(variantDescriptors[start+i].name, v); + variantDescriptors[start+i].type = Button; + } else variantDescriptors[start+i].type = Skip; + } + if(!(last&1)) { // odd number, add filler + ASSIGN(variantDescriptors[start+last+1].name, " "); + variantDescriptors[start+last+1].type = Button; + variantDescriptors[start+last+1].value = Skip; + } + safeStrCpy(buf, engineVariant, MSG_SIZ); *engineVariant = NULLCHAR; // yeghh... GenericPopUp(variantDescriptors, _("New Variant"), TransientDlg, BoardWindow, MODAL, 0); + safeStrCpy(engineVariant, buf, MSG_SIZ); // must temporarily clear to avoid enabling all variant buttons } //------------------------------------------- Common Engine Options ------------------------------------- @@ -578,6 +662,7 @@ Option icsOptions[] = { { 0, 0, 0, NULL, (void*) &appData.seekGraph, "", NULL, CheckBox, N_("Seek Graph") }, { 0, 0, 0, NULL, (void*) &appData.autoRefresh, "", NULL, CheckBox, N_("Auto-Refresh Seek Graph") }, { 0, 0, 0, NULL, (void*) &appData.autoBox, "", NULL, CheckBox, N_("Auto-InputBox PopUp") }, +{ 0, 0, 0, NULL, (void*) &appData.quitNext, "", NULL, CheckBox, N_("Quit after game") }, { 0, 0, 0, NULL, (void*) &appData.premove, "", NULL, CheckBox, N_("Premove") }, { 0, 0, 0, NULL, (void*) &appData.premoveWhite, "", NULL, CheckBox, N_("Premove for White") }, { 0, 0, 0, NULL, (void*) &appData.premoveWhiteText, "", NULL, TextBox, N_("First White Move:") }, @@ -597,6 +682,7 @@ Option icsOptions[] = { { 0, 0, 0, NULL, (void*) &appData.colorChallenge, "", NULL, TextBox, N_("Challenge Text Colors:") }, { 0, 0, 0, NULL, (void*) &appData.colorRequest, "", NULL, TextBox, N_("Request Text Colors:") }, { 0, 0, 0, NULL, (void*) &appData.colorSeek, "", NULL, TextBox, N_("Seek Text Colors:") }, +{ 0, 0, 0, NULL, (void*) &appData.colorNormal, "", NULL, TextBox, N_("Other Text Colors:") }, { 0, 0, 0, NULL, (void*) &IcsOptionsOK, "", NULL, EndMark , "" } }; @@ -611,11 +697,14 @@ IcsOptionsProc () static char *modeNames[] = { N_("Exact position match"), N_("Shown position is subset"), N_("Same material with exactly same Pawn chain"), N_("Same material"), N_("Material range (top board half optional)"), N_("Material difference (optional stuff balanced)"), NULL }; static char *modeValues[] = { "1", "2", "3", "4", "5", "6" }; -static char *searchMode; +static char *searchMode, *countRange; static int LoadOptionsOK () { + appData.minPieces = appData.maxPieces = 0; + sscanf(countRange, "%d-%d", &appData.minPieces, &appData.maxPieces); + if(appData.maxPieces < appData.minPieces) appData.maxPieces = appData.minPieces; appData.searchMode = atoi(searchMode); return 1; } @@ -632,6 +721,7 @@ static Option loadOptions[] = { { 0, 0,5000, NULL, (void*) &appData.eloThreshold2, "", NULL, Spin, N_("Elo of weakest player at least:") }, { 0, 0,5000, NULL, (void*) &appData.dateThreshold, "", NULL, Spin, N_("No games before year:") }, { 0, 1,50, NULL, (void*) &appData.stretch, "", NULL, Spin, N_("Minimum nr consecutive positions:") }, +{ 0, 0,197, NULL, (void*) &countRange, "", NULL, TextBox, "Final nr of pieces" }, { 0, 0,205, NULL, (void*) &searchMode, (char*) modeValues, modeNames, ComboBox, N_("Search mode:") }, { 0, 0, 0, NULL, (void*) &appData.ignoreColors, "", NULL, CheckBox, N_("Also match reversed colors") }, { 0, 0, 0, NULL, (void*) &appData.findMirror, "", NULL, CheckBox, N_("Also match left-right flipped position") }, @@ -641,6 +731,7 @@ static Option loadOptions[] = { void LoadOptionsPopUp (DialogClass parent) { + ASSIGN(countRange, ""); ASSIGN(searchMode, modeValues[appData.searchMode-1]); GenericPopUp(loadOptions, _("Load Game Options"), TransientDlg, parent, MODAL, 0); } @@ -689,6 +780,7 @@ static char *soundNames[] = { N_("Penalty"), N_("Phone"), N_("Pop"), + N_("Roar"), N_("Slap"), N_("Wood Thunk"), NULL, @@ -707,6 +799,7 @@ static char *soundFiles[] = { // sound files corresponding to above names "penalty.wav", "phone.wav", "pop2.wav", + "roar.wav", "slap.wav", "woodthunk.wav", NULL, @@ -734,6 +827,7 @@ static Option soundOptions[] = { { 0, 0, 0, NULL, (void*) &appData.soundTell, (char*) soundFiles, soundNames, ComboBox, N_("Tell:") }, { 0, 0, 0, NULL, (void*) &appData.soundKibitz, (char*) soundFiles, soundNames, ComboBox, N_("Kibitz:") }, { 0, 0, 0, NULL, (void*) &appData.soundRequest, (char*) soundFiles, soundNames, ComboBox, N_("Request:") }, +{ 0, 0, 0, NULL, (void*) &appData.soundRoar, (char*) soundFiles, soundNames, ComboBox, N_("Lion roar:") }, { 0, 0, 0, NULL, (void*) &appData.soundSeek, (char*) soundFiles, soundNames, ComboBox, N_("Seek:") }, { 0, SAME_ROW, 0, NULL, NULL, "", NULL, EndMark , "" } }; @@ -757,20 +851,20 @@ SoundOptionsProc () static void DefColor P((int n)); static void AdjustColor P((int i)); +static void ThemeSel P((int n, int sel)); +static int BoardOptionsOK P((int n)); static char oldPieceDir[MSG_SIZ]; +extern char *engineLine, *nickName; // defined later on -static int -BoardOptionsOK (int n) -{ - if(appData.overrideLineGap >= 0) lineGap = appData.overrideLineGap; else lineGap = defaultLineGap; - InitDrawingParams(strcmp(oldPieceDir, appData.pieceDirectory)); - InitDrawingSizes(-1, 0); - DrawPosition(True, NULL); - return 1; -} +#define THEMELIST 1 static Option boardOptions[] = { +{ 0,LR|T2T, 0, NULL, NULL, NULL, NULL, Label, N_("Selectable themes:") }, +{ 300,LR|TB,200, NULL, (void*) engineMnemonic, (char*) &ThemeSel, NULL, ListBox, "" }, +{ 0,LR|T2T, 0, NULL, NULL, NULL, NULL, Label, N_("New name for current theme:") }, +{ 0, 0, 0, NULL, (void*) &nickName, ".png", NULL, TextBox, "" }, +{ 0,SAME_ROW, 0, NULL, NULL, NULL, NULL, Break, NULL }, { 0, 0, 70, NULL, (void*) &appData.whitePieceColor, "", NULL, TextBox, N_("White Piece Color:") }, { 1000, SAME_ROW, 0, NULL, (void*) &DefColor, NULL, (char**) "#FFFFCC", Button, " " }, /* TRANSLATORS: R = single letter for the color red */ @@ -814,7 +908,8 @@ static Option boardOptions[] = { { 0, 0, 0, NULL, (void*) &appData.upsideDown, "", NULL, CheckBox, N_("Flip Pieces Shogi Style (Colored buttons restore default)") }, //{ 0, 0, 0, NULL, (void*) &appData.allWhite, "", NULL, CheckBox, N_("Use Outline Pieces for Black") }, { 0, 0, 0, NULL, (void*) &appData.monoMode, "", NULL, CheckBox, N_("Mono Mode") }, -{ 0,-1, 5, NULL, (void*) &appData.overrideLineGap, "", NULL, Spin, N_("Line Gap ( -1 = default for board size):") }, +{ 0, 0, 200, NULL, (void*) &appData.logoSize, "", NULL, Spin, N_("Logo Size (0=off, requires restart):") }, +{ 0,-1, 5, NULL, (void*) &appData.overrideLineGap, "", NULL, Spin, N_("Line Gap (-1 = default for board size):") }, { 0, 0, 0, NULL, (void*) &appData.useBitmaps, "", NULL, CheckBox, N_("Use Board Textures") }, { 0, 0, 0, NULL, (void*) &appData.liteBackTextureFile, ".png", NULL, FileName, N_("Light-Squares Texture File:") }, { 0, 0, 0, NULL, (void*) &appData.darkBackTextureFile, ".png", NULL, FileName, N_("Dark-Squares Texture File:") }, @@ -823,6 +918,16 @@ static Option boardOptions[] = { { 0, 0, 0, NULL, (void*) &BoardOptionsOK, "", NULL, EndMark , "" } }; +static int +BoardOptionsOK (int n) +{ + if(n && (n = SelectedListBoxItem(&boardOptions[THEMELIST])) > 0 && *engineList[n] != '#') { // called by pressing OK, and theme selected + ASSIGN(engineLine, engineList[n]); + } + LoadTheme(); + return 1; +} + static void SetColorText (int n, char *buf) { @@ -866,9 +971,32 @@ AdjustColor (int i) } void +ThemeSel (int n, int sel) +{ + int nr; + char buf[MSG_SIZ]; + if(sel < 1) buf[0] = NULLCHAR; // back to top level + else if(engineList[sel][0] == '#') safeStrCpy(buf, engineList[sel], MSG_SIZ); // group header, open group + else { // normal line, select engine + ASSIGN(engineLine, engineList[sel]); + LoadTheme(); + PopDown(TransientDlg); + return; + } + nr = NamesToList(appData.themeNames, engineList, engineMnemonic, buf); // replace list by only the group contents + ASSIGN(engineMnemonic[0], buf); + LoadListBox(&boardOptions[THEMELIST], _("# no themes are defined"), -1, -1); + HighlightWithScroll(&boardOptions[THEMELIST], 0, nr); +} + +void BoardOptionsProc () { strncpy(oldPieceDir, appData.pieceDirectory, MSG_SIZ-1); // to see if it changed + ASSIGN(engineLine, ""); + ASSIGN(nickName, ""); + ASSIGN(engineMnemonic[0], ""); + NamesToList(appData.themeNames, engineList, engineMnemonic, ""); GenericPopUp(boardOptions, _("Board Options"), TransientDlg, BoardWindow, MODAL, 0); } @@ -876,24 +1004,42 @@ BoardOptionsProc () Option textOptions[100]; static void PutText P((char *text, int pos)); +static void NewChat P((char *name)); +static char clickedWord[MSG_SIZ], click; void SendString (char *p) { - char buf[MSG_SIZ], *q; + char buf[MSG_SIZ], buf2[MSG_SIZ], *q; + if(q = strstr(p, "$name")) { // in Xaw this is already intercepted + if(!shellUp[TextMenuDlg] || !clickedWord[0]) return; + strncpy(buf2, p, MSG_SIZ); + snprintf(buf2 + (q-p), MSG_SIZ -(q-p), "%s%s", clickedWord, q+5); + p = buf2; + } + if(!strcmp(p, "$copy")) { // special case for copy selection + CopySomething(clickedWord); + } else + if(!strcmp(p, "$chat")) { // special case for opening chat + NewChat(clickedWord); + } else if(q = strstr(p, "$input")) { if(!shellUp[TextMenuDlg]) return; strncpy(buf, p, MSG_SIZ); strncpy(buf + (q-p), q+6, MSG_SIZ-(q-p)); PutText(buf, q-p); - return; + } else { + snprintf(buf, MSG_SIZ, "%s\n", p); + SendToICS(buf); + } + if(click) { // popped up by memo click + click = clickedWord[0] = 0; + PopDown(TextMenuDlg); } - snprintf(buf, MSG_SIZ, "%s\n", p); - SendToICS(buf); } void -IcsTextProc () +IcsTextPopUp () { int i=0, j; char *p, *q, *r; @@ -925,6 +1071,13 @@ IcsTextProc () GenericPopUp(textOptions, _("ICS text menu"), TextMenuDlg, BoardWindow, NONMODAL, appData.topLevel); } +void +IcsTextProc () +{ + if(shellUp[TextMenuDlg]) PopDown(TextMenuDlg); + else IcsTextPopUp(); +} + //---------------------------------------------------- Edit Comment ----------------------------------- static char *commentText; @@ -943,7 +1096,7 @@ NewComCallback (int n) } Option commentOptions[] = { -{ 200, T_VSCRL | T_FILL | T_WRAP | T_TOP, 250, NULL, (void*) &commentText, "", (char **) &CommentClick, TextBox, "" }, +{ 200, T_VSCRL | T_FILL | T_WRAP | T_TOP, 250, NULL, (void*) &commentText, (char*) &appData.commentFont, (char **) &CommentClick, TextBox, "" }, { 0, 0, 50, NULL, (void*) &ClearComment, NULL, NULL, Button, N_("clear") }, { 0, SAME_ROW, 100, NULL, (void*) &SaveChanges, NULL, NULL, Button, N_("save changes") }, { 0, SAME_ROW, 0, NULL, (void*) &NewComCallback, "", NULL, EndMark , "" } @@ -1021,27 +1174,46 @@ EditCommentProc () //------------------------------------------------------ Edit Tags ---------------------------------- static void changeTags P((int n)); -static char *tagsText; +static char *tagsText, **resPtr; + +static int TagsClick P((Option *opt, int n, int x, int y, char *val, int index)); static int NewTagsCallback (int n) { + if(bookUp) SaveToBook(tagsText), DisplayBook(currentMove); else + if(resPtr) { ASSIGN(*resPtr, tagsText); } else ReplaceTags(tagsText, &gameInfo); return 1; } +static void +NewMove () +{ + addToBookFlag = !addToBookFlag; +} + static Option tagsOptions[] = { { 0, 0, 0, NULL, NULL, NULL, NULL, Label, NULL }, -{ 200, T_VSCRL | T_FILL | T_WRAP | T_TOP, 200, NULL, (void*) &tagsText, "", NULL, TextBox, "" }, -{ 0, 0, 100, NULL, (void*) &changeTags, NULL, NULL, Button, N_("save changes") }, +{ 200, T_VSCRL | T_FILL | T_WRAP | T_TOP, 200, NULL, (void*) &tagsText, (char*) &appData.tagsFont, (char **) &TagsClick, TextBox, "" }, +{ 0, 0, 100, NULL, (void*) &NewMove, NULL, NULL, Button, N_("add next move") }, +{ 0,SAME_ROW,100,NULL, (void*) &changeTags, NULL, NULL, Button, N_("save changes") }, { 0,SAME_ROW, 0, NULL, (void*) &NewTagsCallback, "", NULL, EndMark , "" } }; +static int TagsClick (Option *opt, int n, int x, int y, char *val, int index) +{ + if(!bookUp || n != 3) return FALSE; // only button-3 press in Edit Book is of interest + PlayBookMove(val, index); + return TRUE; +} + static void changeTags (int n) { GenericReadout(tagsOptions, 1); - if(bookUp) SaveToBook(tagsText); else + if(bookUp) SaveToBook(tagsText), DisplayBook(currentMove); else + if(resPtr) { ASSIGN(*resPtr, tagsText); } else ReplaceTags(tagsText, &gameInfo); } @@ -1050,6 +1222,8 @@ NewTagsPopup (char *text, char *msg) { char *title = bookUp ? _("Edit book") : _("Tags"); + tagsOptions[2].type = bookUp ? Button : Skip; + tagsOptions[3].min = bookUp ? SAME_ROW : 0; if(DialogExists(TagsDlg)) { // if already exists, alter title and content SetWidgetText(&tagsOptions[1], text, TagsDlg); SetDialogTitle(TagsDlg, title); @@ -1069,6 +1243,7 @@ TagsPopUp (char *tags, char *msg) void EditTagsPopUp (char *tags, char **dest) { // wrapper to preserve old name used in back-end + resPtr = dest; NewTagsPopup(tags, NULL); } @@ -1085,6 +1260,12 @@ EditTagsProc () if (bookUp || !PopDown(TagsDlg)) EditTagsEvent(); } +void +AddBookMove (char *text) +{ + AppendText(&tagsOptions[1], text); +} + //---------------------------------------------- ICS Input Box ---------------------------------- char *icsText; @@ -1134,6 +1315,8 @@ NextInHistory () } // end of borrowed code +#define INPUT 0 + Option boxOptions[] = { { 30, T_TOP, 400, NULL, (void*) &icsText, "", NULL, TextBox, "" }, { 0, NO_OK, 0, NULL, NULL, "", NULL, EndMark , "" } @@ -1144,10 +1327,10 @@ ICSInputSendText () { char *val; - GetWidgetText(&boxOptions[0], &val); + GetWidgetText(&boxOptions[INPUT], &val); SaveInHistory(val); SendMultiLineToICS(val); - SetWidgetText(&boxOptions[0], "", InputBoxDlg); + SetWidgetText(&boxOptions[INPUT], "", InputBoxDlg); } void @@ -1161,29 +1344,14 @@ IcsKey (int n) ICSInputSendText(); return; case 1: - GetWidgetText(&boxOptions[0], &val); + GetWidgetText(&boxOptions[INPUT], &val); val = PrevInHistory(val); break; case -1: val = NextInHistory(); } - SetWidgetText(&boxOptions[0], val = val ? val : "", InputBoxDlg); - SetInsertPos(&boxOptions[0], strlen(val)); -} - -static void -PutText (char *text, int pos) -{ - char buf[MSG_SIZ], *p; - - if(strstr(text, "$add ") == text) { - GetWidgetText(&boxOptions[0], &p); - snprintf(buf, MSG_SIZ, "%s%s", p, text+5); text = buf; - pos += strlen(p) - 5; - } - SetWidgetText(&boxOptions[0], text, TextMenuDlg); - SetInsertPos(&boxOptions[0], pos); - HardSetFocus(&boxOptions[0]); + SetWidgetText(&boxOptions[INPUT], val = val ? val : "", InputBoxDlg); + SetInsertPos(&boxOptions[INPUT], strlen(val)); } void @@ -1191,8 +1359,8 @@ ICSInputBoxPopUp () { MarkMenu("View.ICSInputBox", InputBoxDlg); if(GenericPopUp(boxOptions, _("ICS input box"), InputBoxDlg, BoardWindow, NONMODAL, 0)) - AddHandler(&boxOptions[0], InputBoxDlg, 3); - CursorAtEnd(&boxOptions[0]); + AddHandler(&boxOptions[INPUT], InputBoxDlg, 3); + CursorAtEnd(&boxOptions[INPUT]); } void @@ -1229,15 +1397,15 @@ PopUpMoveDialog (char firstchar) void BoxAutoPopUp (char *buf) -{ +{ // only used in Xaw. GTK calls ConsoleAutoPopUp in stead (when we type to board) if(!appData.autoBox) return; if(appData.icsActive) { // text typed to board in ICS mode: divert to ICS input box if(DialogExists(InputBoxDlg)) { // box already exists: append to current contents char *p, newText[MSG_SIZ]; - GetWidgetText(&boxOptions[0], &p); + GetWidgetText(&boxOptions[INPUT], &p); snprintf(newText, MSG_SIZ, "%s%c", p, *buf); - SetWidgetText(&boxOptions[0], newText, InputBoxDlg); - if(shellUp[InputBoxDlg]) HardSetFocus (&boxOptions[0]); //why??? + SetWidgetText(&boxOptions[INPUT], newText, InputBoxDlg); + if(shellUp[InputBoxDlg]) HardSetFocus (&boxOptions[INPUT], InputBoxDlg); //why??? } else icsText = buf; // box did not exist: make sure it pops up with char in it ICSInputBoxPopUp(); } else PopUpMoveDialog(*buf); @@ -1368,6 +1536,7 @@ ShuffleOK (int n) static Option shuffleOptions[] = { { 0, 0, 0, NULL, (void*) &shuffleOpenings, NULL, NULL, CheckBox, N_("shuffle") }, + { 0, 0, 0, NULL, (void*) &appData.fischerCastling, NULL, NULL, CheckBox, N_("Fischer castling") }, { 0,-1,2000000000, NULL, (void*) &appData.defaultFrcPosition, "", NULL, Spin, N_("Start-position number:") }, { 0, 0, 0, NULL, (void*) &SetRandom, NULL, NULL, Button, N_("randomize") }, { 0, SAME_ROW, 0, NULL, (void*) &SetRandom, NULL, NULL, Button, N_("pick fixed") }, @@ -1552,6 +1721,7 @@ PromoPick (int n) ClearHighlights(); return; } + if(promoChar == '=' && !IS_SHOGI(gameInfo.variant)) promoChar = NULLCHAR; UserMoveEvent(fromX, fromY, toX, toY, promoChar); if (!appData.highlightLastMove || gotPremove) ClearHighlights(); @@ -1568,11 +1738,11 @@ SetPromo (char *name, int nr, char promoChar) } void -PromotionPopUp () +PromotionPopUp (char choice) { // choice depends on variant: prepare dialog acordingly count = 8; - SetPromo(_("Cancel"), --count, 0); // Beware: GenericPopUp cannot handle user buttons named "cancel" (lowe case)! - if(gameInfo.variant != VariantShogi) { + SetPromo(_("Cancel"), --count, -1); // Beware: GenericPopUp cannot handle user buttons named "cancel" (lowe case)! + if(choice != '+') { if (!appData.testLegality || gameInfo.variant == VariantSuicide || gameInfo.variant == VariantSpartan && !WhiteOnMove(currentMove) || gameInfo.variant == VariantGiveaway) { @@ -1594,6 +1764,8 @@ PromotionPopUp () SetPromo(_("Chancellor"), --count, 'c'); } SetPromo(_("Queen"), --count, 'q'); + if(gameInfo.variant == VariantChuChess) + SetPromo(_("Lion"), --count, 'l'); } } else // [HGM] shogi { @@ -1606,23 +1778,130 @@ PromotionPopUp () //---------------------------- Chat Windows ---------------------------------------------- -static char *line, *memo, *partner, *texts[MAX_CHAT], dirty[MAX_CHAT]; +static char *line, *memo, *chatMemo, *partner, *texts[MAX_CHAT], dirty[MAX_CHAT], *inputs[MAX_CHAT], *icsLine, *tmpLine; static int activePartner; +int hidden = 1; void ChatSwitch P((int n)); int ChatOK P((int n)); +#define CHAT_ICS 6 +#define CHAT_PARTNER 8 +#define CHAT_OUT 11 +#define CHAT_PANE 12 +#define CHAT_IN 13 + +void PaneSwitch P((void)); +void ClearChat P((void)); + +WindowPlacement wpTextMenu; + +int +ContextMenu (Option *opt, int button, int x, int y, char *text, int index) +{ // callback for ICS-output clicks; handles button 3, passes on other events + int h; + if(button == -3) return TRUE; // supress default GTK context menu on up-click + if(button != 3) return FALSE; + if(index == -1) { // pre-existing selection in memo + strncpy(clickedWord, text, MSG_SIZ); + } else { // figure out what word was clicked + char *start, *end; + start = end = text + index; + while(isalnum(*end)) end++; + while(start > text && isalnum(start[-1])) start--; + clickedWord[0] = NULLCHAR; + if(end-start >= 80) end = start + 80; // intended for small words and numbers + strncpy(clickedWord, start, end-start); clickedWord[end-start] = NULLCHAR; + } + click = !shellUp[TextMenuDlg]; // request auto-popdown of textmenu when we popped it up + h = wpTextMenu.height; // remembered height of text menu + if(h <= 0) h = 65; // when not available, position w.r.t. top + GetPlacement(ChatDlg, &wpTextMenu); + if(opt->target == (void*) &chatMemo) wpTextMenu.y += (wpTextMenu.height - 30)/2; // click in chat + wpTextMenu.x += x - 50; wpTextMenu.y += y - h + 50; // request positioning + if(wpTextMenu.x < 0) wpTextMenu.x = 0; + if(wpTextMenu.y < 0) wpTextMenu.y = 0; + wpTextMenu.width = wpTextMenu.height = -1; + IcsTextPopUp(); + return TRUE; +} + Option chatOptions[] = { +{ 0, 0, 0, NULL, NULL, "", NULL, Label , N_("Chats:") }, +{ 1, SAME_ROW|TT, 75, NULL, (void*) &ChatSwitch, NULL, NULL, Button, N_("New Chat") }, +{ 2, SAME_ROW|TT, 75, NULL, (void*) &ChatSwitch, NULL, NULL, Button, N_("New Chat") }, +{ 3, SAME_ROW|TT, 75, NULL, (void*) &ChatSwitch, NULL, NULL, Button, N_("New Chat") }, +{ 4, SAME_ROW|TT, 75, NULL, (void*) &ChatSwitch, NULL, NULL, Button, N_("New Chat") }, +{ 5, SAME_ROW|TT, 75, NULL, (void*) &ChatSwitch, NULL, NULL, Button, N_("New Chat") }, +{ 250, T_VSCRL | T_FILL | T_WRAP | T_TOP, 510, NULL, (void*) &memo, NULL, (void*) &ContextMenu, TextBox, "" }, +{ 0, 0, 0, NULL, NULL, "", NULL, Break , "" }, { 0, T_TOP, 100, NULL, (void*) &partner, NULL, NULL, TextBox, N_("Chat partner:") }, -{ 1, SAME_ROW|TT, 75, NULL, (void*) &ChatSwitch, NULL, NULL, Button, "" }, -{ 2, SAME_ROW|TT, 75, NULL, (void*) &ChatSwitch, NULL, NULL, Button, "" }, -{ 3, SAME_ROW|TT, 75, NULL, (void*) &ChatSwitch, NULL, NULL, Button, "" }, -{ 4, SAME_ROW|TT, 75, NULL, (void*) &ChatSwitch, NULL, NULL, Button, "" }, -{ 100, T_VSCRL | T_FILL | T_WRAP | T_TOP, 510, NULL, (void*) &memo, NULL, NULL, TextBox, "" }, +{ 0, SAME_ROW, 0, NULL, (void*) &ClearChat, NULL, NULL, Button, N_("End Chat") }, +{ 0, SAME_ROW, 0, NULL, (void*) &PaneSwitch, NULL, NULL, Button, N_("Hide") }, +{ 250, T_VSCRL | T_FILL | T_WRAP | T_TOP, 510, NULL, (void*) &chatMemo, NULL, (void*) &ContextMenu, TextBox, "" }, +{ 0, 0, 0, NULL, NULL, "", NULL, Break , "" }, { 0, 0, 510, NULL, (void*) &line, NULL, NULL, TextBox, "" }, { 0, NO_OK|SAME_ROW, 0, NULL, (void*) &ChatOK, NULL, NULL, EndMark , "" } }; +static void +PutText (char *text, int pos) +{ + char buf[MSG_SIZ], *p; + DialogClass dlg = ChatDlg; + Option *opt = &chatOptions[CHAT_IN]; + + if(strstr(text, "$add ") == text) { + GetWidgetText(&boxOptions[INPUT], &p); + snprintf(buf, MSG_SIZ, "%s%s", p, text+5); text = buf; + pos += strlen(p) - 5; + } + if(shellUp[InputBoxDlg]) opt = &boxOptions[INPUT], dlg = InputBoxDlg; // for the benefit of Xaw give priority to ICS Input Box + SetWidgetText(opt, text, dlg); + SetInsertPos(opt, pos); + HardSetFocus(opt, dlg); + CursorAtEnd(opt); +} + +int +IcsHist (int n, Option *opt, DialogClass dlg) +{ // [HGM] input: let up-arrow recall previous line from history + char *val = NULL; // to suppress spurious warning + int chat, start; + + if(opt != &chatOptions[CHAT_IN] && !(opt == &chatOptions[CHAT_PARTNER] && n == 33)) return 0; + switch(n) { + case 33: // + if(hidden) BoardToTop(); + else PaneSwitch(); + break; + case 15: + NewChat(lastTalker); + break; + case 14: + for(chat=0; chat < MAX_CHAT; chat++) if(!chatPartner[chat][0]) break; + if(chat < MAX_CHAT) ChatSwitch(chat + 1); + break; + case 10: // + chat = start = (activePartner - hidden + MAX_CHAT) % MAX_CHAT; + while(!dirty[chat = (chat + 1)%MAX_CHAT]) if(chat == start) break; + if(!dirty[chat]) + while(!chatPartner[chat = (chat + 1)%MAX_CHAT][0]) if(chat == start) break; + if(chat == start && hidden) chat = 0; // if all unused, start left + ChatSwitch(chat + 1); + break; + case 1: + GetWidgetText(opt, &val); + val = PrevInHistory(val); + break; + case -1: + val = NextInHistory(); + } + SetWidgetText(opt, val = val ? val : "", dlg); + SetInsertPos(opt, strlen(val)); + return 1; +} + void OutputChatMessage (int partner, char *mess) { @@ -1633,11 +1912,11 @@ OutputChatMessage (int partner, char *mess) texts[partner] = (char*) malloc(len); snprintf(texts[partner], len, "%s%s", p ? p : "", mess); FREE(p); - if(partner == activePartner) { - AppendText(&chatOptions[5], mess); - SetInsertPos(&chatOptions[5], len-2); + if(partner == activePartner && !hidden) { + AppendText(&chatOptions[CHAT_OUT], mess); + SetInsertPos(&chatOptions[CHAT_OUT], len-2); } else { - SetColor("#FFC000", &chatOptions[partner + (partner < activePartner)]); + SetColor("#FFC000", &chatOptions[partner + 1]); dirty[partner] = 1; } } @@ -1647,17 +1926,19 @@ ChatOK (int n) { // can only be called through in chat-partner text-edit, as there is no OK button char buf[MSG_SIZ]; - if(!partner || strcmp(partner, chatPartner[activePartner])) { + if(!hidden && (!partner || strcmp(partner, chatPartner[activePartner]))) { safeStrCpy(chatPartner[activePartner], partner, MSG_SIZ); - SetWidgetText(&chatOptions[5], "", -1); // clear text if we alter partner - SetWidgetText(&chatOptions[6], "", ChatDlg); // clear text if we alter partner - HardSetFocus(&chatOptions[6]); + SetWidgetText(&chatOptions[CHAT_OUT], "", -1); // clear text if we alter partner + SetWidgetText(&chatOptions[CHAT_IN], "", ChatDlg); // clear text if we alter partner + SetWidgetLabel(&chatOptions[activePartner+1], chatPartner[activePartner][0] ? chatPartner[activePartner] : _("New Chat")); + HardSetFocus(&chatOptions[CHAT_IN], 0); } - if(line[0]) { // something was typed - SetWidgetText(&chatOptions[6], "", ChatDlg); + if(line[0] || hidden) { // something was typed (for ICS commands we also allow empty line!) + SetWidgetText(&chatOptions[CHAT_IN], "", ChatDlg); // from here on it could be back-end if(line[strlen(line)-1] == '\n') line[strlen(line)-1] = NULLCHAR; SaveInHistory(line); + if(hidden || !*chatPartner[activePartner]) snprintf(buf, MSG_SIZ, "%s\n", line); else // command for ICS if(!strcmp("whispers", chatPartner[activePartner])) snprintf(buf, MSG_SIZ, "whisper %s\n", line); // WHISPER box uses "whisper" to send else if(!strcmp("shouts", chatPartner[activePartner])) @@ -1676,31 +1957,125 @@ ChatOK (int n) } void +DelayedSetText () +{ + SetWidgetText(&chatOptions[CHAT_IN], tmpLine, -1); // leave focus on chat-partner field! + SetInsertPos(&chatOptions[CHAT_IN], strlen(tmpLine)); +} + +void +DelayedScroll () +{ // If we do this immediately it does it before shrinking the memo, so the lower half remains hidden (Ughh!) + SetInsertPos(&chatOptions[CHAT_ICS], 999999); + SetWidgetText(&chatOptions[CHAT_IN], tmpLine, ChatDlg); + SetInsertPos(&chatOptions[CHAT_IN], strlen(tmpLine)); +} + +void ChatSwitch (int n) { int i, j; - if(n <= activePartner) n--; - activePartner = n; + char *v; + if(chatOptions[CHAT_ICS].type == Skip) hidden = 0; // In Xaw there is no ICS pane we can hide behind + Show(&chatOptions[CHAT_PANE], 0); // show + if(hidden) ScheduleDelayedEvent(DelayedScroll, 50); // Awful! + else ScheduleDelayedEvent(DelayedSetText, 50); + GetWidgetText(&chatOptions[CHAT_IN], &v); + if(hidden) { ASSIGN(icsLine, v); } else { ASSIGN(inputs[activePartner], v); } + hidden = 0; + activePartner = --n; if(!texts[n]) texts[n] = strdup(""); dirty[n] = 0; - SetWidgetText(&chatOptions[5], texts[n], ChatDlg); - SetInsertPos(&chatOptions[5], strlen(texts[n])); - SetWidgetText(&chatOptions[0], chatPartner[n], ChatDlg); + SetWidgetText(&chatOptions[CHAT_OUT], texts[n], ChatDlg); + SetInsertPos(&chatOptions[CHAT_OUT], strlen(texts[n])); + SetWidgetText(&chatOptions[CHAT_PARTNER], chatPartner[n], ChatDlg); for(i=j=0; i