* zippy.c -- Implements Zippy the Pinhead chess player on ICS in XBoard\r
* $Id: zippy.c,v 2.2 2003/11/25 05:25:20 mann Exp $\r
*\r
- * Copyright 1991 by Digital Equipment Corporation, Maynard, Massachusetts.\r
- * Enhancements Copyright 1992-2001 Free Software Foundation, Inc.\r
+ * Copyright 1991 by Digital Equipment Corporation, Maynard,\r
+ * Massachusetts. Enhancements Copyright\r
+ * 1992-2001,2002,2003,2004,2005,2006,2007,2008,2009 Free Software\r
+ * Foundation, Inc.\r
*\r
* The following terms apply to Digital Equipment Corporation's copyright\r
* interest in XBoard:\r
* SOFTWARE.\r
* ------------------------------------------------------------------------\r
*\r
- * The following terms apply to the enhanced version of XBoard distributed\r
- * by the Free Software Foundation:\r
+ * The following terms apply to the enhanced version of XBoard\r
+ * distributed by the Free Software Foundation:\r
* ------------------------------------------------------------------------\r
- * This program is free software; you can redistribute it and/or modify\r
+ *\r
+ * GNU XBoard is free software: you can redistribute it and/or modify\r
* it under the terms of the GNU General Public License as published by\r
- * the Free Software Foundation; either version 2 of the License, or\r
- * (at your option) any later version.\r
+ * the Free Software Foundation, either version 3 of the License, or (at\r
+ * your option) any later version.\r
*\r
- * This program is distributed in the hope that it will be useful,\r
- * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
- * GNU General Public License for more details.\r
+ * GNU XBoard is distributed in the hope that it will be useful, but\r
+ * WITHOUT ANY WARRANTY; without even the implied warranty of\r
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\r
+ * General Public License for more details.\r
*\r
* You should have received a copy of the GNU General Public License\r
- * along with this program; if not, write to the Free Software\r
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\r
- * ------------------------------------------------------------------------\r
- */\r
+ * along with this program. If not, see http://www.gnu.org/licenses/.\r
+ *\r
+ *------------------------------------------------------------------------\r
+ ** See the file ChangeLog for a revision history. */\r
\r
#include "config.h"\r
\r
#include "backend.h"\r
#include "backendz.h"\r
\r
-char *SendMoveToBookUser P((int nr, ChessProgramState *cps, int initial)); // [HGM] book
-
+char *SendMoveToBookUser P((int nr, ChessProgramState *cps, int initial)); // [HGM] book\r
+void HandleMachineMove P((char *message, ChessProgramState *cps));\r
+\r
static char zippyPartner[MSG_SIZ];\r
static char zippyLastOpp[MSG_SIZ];\r
+static char zippyOffender[MSG_SIZ]; // [HGM] aborter\r
static int zippyConsecGames;\r
static time_t zippyLastGameEnd;\r
\r
+extern void mysrandom(unsigned int seed);\r
+extern int myrandom(void);\r
+\r
void ZippyInit()\r
{\r
char *p;\r
"i enthuses:", "i entreats:", "i enunciates:", "i eulogizes:",\r
"i exclaims:", "i execrates:", "i exhorts:", "i expatiates:",\r
"i explains:", "i explicates:", "i explodes:", "i exposes:",\r
- "i exposits:", "i expounds:", "i expresses:", "i extols:",\r
+ "i exposits:", "i expostulates: ",\r
+ "i expounds:", "i expresses:", "i extols:",\r
"i exults:", "i fantasizes:", "i fibs:", "i filibusters:",\r
"i flatters:", "i flutes:", "i fools:", "i free-associates:",\r
"i fulminates:", "i gabbles:", "i gabs:", "i gasps:",\r
SendToICS("\n");\r
}\r
zippyLastGameEnd = time(0);\r
+ if(forwardMostMove < appData.zippyShortGame) \r
+ strcpy(zippyOffender, zippyLastOpp); else zippyOffender[0] = 0; // [HGM] aborter\r
}\r
\r
/*\r
base = atoi(sbase);\r
increment = atoi(sincrement);\r
\r
+ /* [DM] If icsAnalyzeEngine active we don't accept automatic games */\r
+ if (appData.icsActive && appData.icsEngineAnalyze) return;\r
+\r
/* If desired, you can insert more code here to decline matches\r
based on rated, variant, base, and increment, but it is\r
easier to use the ICS formula feature instead. */\r
return;\r
}\r
if (StrStr(appData.zippyVariants, varname) == NULL ||\r
- (i=first.protocolVersion) != 1 && StrStr(first.variants, varname) == NULL /* [HGM] zippyvar */\r
+ ((i=first.protocolVersion) != 1 && StrStr(first.variants, varname) == NULL) /* [HGM] zippyvar */\r
) {\r
sprintf(buf,\r
"%stell %s This computer can't play %s [%s], only %s\n%sdecline %s\n",\r
return;\r
}\r
\r
+ /* [HGM] aborter: opponent is cheater that aborts games he doesn't like on first move. Make him wait */\r
+ if (strcmp(opponent, zippyOffender) == 0 &&\r
+ difftime(time(0), zippyLastGameEnd) < appData.zippyReplayTimeout) {\r
+ sprintf(buf, "%stell %s Sorry, your previous game against %s was rather short. "\r
+ " It will wait %d seconds to see if a tougher opponent comes along.\n%sdecline %s\n",\r
+ ics_prefix, opponent, ics_handle,\r
+ appData.zippyReplayTimeout, ics_prefix, opponent);\r
+ SendToICS(buf);\r
+ return;\r
+ }\r
+\r
/* Engine not yet initialized or still thinking about last game? */\r
if (!first.initDone || first.lastPing != first.lastPong) {\r
sprintf(buf, "%stell %s I'm not quite ready for a new game yet; try again soon.\n%sdecline %s\n",\r
before our own name. */\r
if(star_match[8] == NULL || star_match[8][0] == 0) // [HGM] chessd: open-source ICS has file on next line\r
ZippyHandleChallenge(star_match[4], star_match[5],\r
- star_match[6], star_match[7],\r
- StripHighlightAndTitle(star_match[0]));\r
+ star_match[6], star_match[7], StripHighlightAndTitle(star_match[0]));\r
else ZippyHandleChallenge(star_match[4], star_match[8],\r
star_match[6], star_match[7],\r
StripHighlightAndTitle(star_match[0]));\r
return TRUE;\r
}\r
\r
- if (looking_at(buf, i, "offers you a draw")) {\r
- if (first.sendDrawOffers && first.initDone) {\r
- SendToProgram("draw\n", &first);\r
- }\r
- return TRUE;\r
+\r
+ if (ics_type == ICS_ICC) { // [DM]\r
+ if (looking_at(buf, i, "Your opponent offers you a draw")) {\r
+ if (first.sendDrawOffers && first.initDone)\r
+ SendToProgram("draw\n", &first);\r
+ return TRUE;\r
+ }\r
+ } else {\r
+ if (looking_at(buf, i, "offers you a draw")) {\r
+ if (first.sendDrawOffers && first.initDone) {\r
+ SendToProgram("draw\n", &first);\r
+ }\r
+ return TRUE;\r
+ }\r
}\r
\r
if (looking_at(buf, i, "requests that the game be aborted") ||\r
char buf[MSG_SIZ];\r
int w, b;\r
char *opp = (gameMode==IcsPlayingWhite ? gameInfo.black : gameInfo.white);\r
- Boolean sentPos = FALSE;
+ Boolean sentPos = FALSE;\r
char *bookHit = NULL; // [HGM] book\r
\r
if (!first.initDone) {\r
/* Nothing needs to be done here */\r
} \r
}\r
-
- if(bookHit) { // [HGM] book: simulate book reply
- static char bookMove[MSG_SIZ]; // a bit generous?
-
- programStats.depth = programStats.nodes = programStats.time =
- programStats.score = programStats.got_only_move = 0;
- sprintf(programStats.movelist, "%s (xbook)", bookHit);
-
- strcpy(bookMove, "move ");
- strcat(bookMove, bookHit);
- HandleMachineMove(bookMove, &first);
- }
+\r
+ if(bookHit) { // [HGM] book: simulate book reply\r
+ static char bookMove[MSG_SIZ]; // a bit generous?\r
+\r
+ programStats.depth = programStats.nodes = programStats.time = \r
+ programStats.score = programStats.got_only_move = 0;\r
+ sprintf(programStats.movelist, "%s (xbook)", bookHit);\r
+\r
+ strcpy(bookMove, "move ");\r
+ strcat(bookMove, bookHit);\r
+ HandleMachineMove(bookMove, &first);\r
+ }\r
}\r
\r
\r