* ----------------------------------------------------------------------
* Copyright (c) 1993, 1994, 1995 Matthias Mutz
* Copyright (c) 1999 Michael Vanier and the Free Software Foundation
+ * Copyright (c) 2008, 2013, 2014 Yann Dirson and the Free Software Foundation
*
* GNU SHOGI is based on GNU CHESS
*
*
* GNU Shogi is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
- * Free Software Foundation; either version 1, or (at your option) any
- * later version.
+ * Free Software Foundation; either version 3 of the License,
+ * or (at your option) any later version.
*
* GNU Shogi is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* for more details.
*
* You should have received a copy of the GNU General Public License along
- * with GNU Shogi; see the file COPYING. If not, write to the Free
- * Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
+ * with GNU Shogi; see the file COPYING. If not, see
+ * <http://www.gnu.org/licenses/>.
* ----------------------------------------------------------------------
*
*/
{
short rtf = in_opening_stage ? 8 : 2;
short tcq = in_opening_stage ? 2 : 4;
+ int moves = TimeControl.moves[side];
- TimeControl.clock[side] += TCadd;
+ if(!xboard) /* no pre-add of increment in XBoard mode */
+ TimeControl.clock[side] += TCadd;
+ if(TCflag == 2 && TCadd == 0) /* sudden death */
+ moves = (moves < 30 ? 30 : moves);
ResponseTime = (TimeControl.clock[side])
- / (((TimeControl.moves[side]) * rtf) + 1);
+ / (moves * rtf + 1);
TCleft = (long)ResponseTime / tcq;
ResponseTime += TCadd / 2;
}
else
{
/* calculate avg time per move remaining */
- TimeControl.clock[side] += TCadd;
+ int moves = TimeControl.moves[side];
+
+ if(!xboard) /* no pre-add of increment in XBoard mode */
+ TimeControl.clock[side] += TCadd;
+ if(TCflag == 2 && TCadd == 0) /* sudden death */
+ moves = (moves < 30 ? 30 : moves);
ResponseTime = (TimeControl.clock[side])
- / (((TimeControl.moves[side]) * 2) + 1);
+ / (moves * 2 + 1);
TCleft = (int) ResponseTime / 3;
ResponseTime += TCadd / 2;
TCcount = MAXTCCOUNTX;
}
#endif
-
+printf("# %2d. moves=%d,%d time=%d,%d ResponseTime=%d+%d\n",GameCnt,TimeControl.moves[computer],TimeControl.moves[opponent],TimeControl.clock[computer],TimeControl.clock[opponent],ResponseTime,TCleft);
assert(TCcount <= MAXTCCOUNTX);
}
#endif
if (flag.timeout)
- ShowMessage("timeout");
+ dsp->ShowMessage("timeout");
+}
+
+
+/*
+ * Determine the time that has passed since the search was started. If the
+ * elapsed time exceeds the target(ResponseTime + ExtraTime) then set timeout
+ * to true which will terminate the search.
+ * iop = COMPUTE_MODE calculate et, bump ETnodes
+ * iop = COMPUTE_AND_INIT_MODE calculate et, set timeout if time exceeded,
+ * set reference time
+ */
+void
+ElapsedTime(ElapsedTime_mode iop)
+{
+ long current_time;
+#ifdef HAVE_GETTIMEOFDAY
+ struct timeval tv;
+#endif
+
+ dsp->PollForInput();
+
+#ifdef HAVE_GETTIMEOFDAY
+ gettimeofday(&tv, NULL);
+ current_time = tv.tv_sec*100 + (tv.tv_usec/10000);
+#else
+ et = ((current_time = time((long *) 0)) - time0) * 100;
+#endif
+
+#ifdef INTERRUPT_TEST
+ if (iop == INIT_INTERRUPT_MODE)
+ {
+ itime0 = current_time;
+ }
+ else if (iop == COMPUTE_INTERRUPT_MODE)
+ {
+ it = current_time - itime0;
+ }
+ else
+#endif
+ {
+#ifdef HAVE_GETTIMEOFDAY
+ et = current_time - time0;
+#endif
+ ETnodes = NodeCnt + znodes;
+
+ if (et < 0)
+ {
+#ifdef INTERRUPT_TEST
+ printf("elapsed time %ld not positive\n", et);
+#endif
+ et = 0;
+ }
+
+ if (iop == COMPUTE_AND_INIT_MODE)
+ {
+ if ((et > (ResponseTime + ExtraTime)) && (Sdepth > MINDEPTH))
+ flag.timeout = true;
+
+ time0 = current_time;
+ }
+
+#ifdef QUIETBACKGROUND
+ if (!background)
+#endif
+ dsp->UpdateClocks();
+ }
+}
+
+
+void
+SetTimeControl(void)
+{
+ if (TCflag)
+ {
+ TimeControl.moves[black] = TimeControl.moves[white] = TCmoves;
+ TimeControl.clock[black] += 6000L * TCminutes + TCseconds * 100;
+ TimeControl.clock[white] += 6000L * TCminutes + TCseconds * 100;
+ }
+ else
+ {
+ TimeControl.moves[black] = TimeControl.moves[white] = 0;
+ TimeControl.clock[black] = TimeControl.clock[white] = 0;
+ }
+
+ flag.onemove = (TCmoves == 1);
+ et = 0;
+ ElapsedTime(COMPUTE_AND_INIT_MODE);
+}
+
+void
+RenewTimeControl(int side, int TCadd)
+{
+ if (flag.gamein || TCadd)
+ {
+ TimeCalc();
+ }
+ else if (TimeControl.moves[side] == 0)
+ {
+ if (XC)
+ {
+ if (XCmore < XC)
+ {
+ TCmoves = XCmoves[XCmore];
+ TCminutes = XCminutes[XCmore];
+ TCseconds = XCseconds[XCmore];
+ XCmore++;
+ }
+ }
+
+ SetTimeControl();
+ }
}