X-Git-Url: http://winboard.nl/cgi-bin?a=blobdiff_plain;f=gnushogi%2Ftcontrl.c;h=afdb32cd3663f17bdd489a7104e8fc4fd4cddc29;hb=0733495e0c47ce7590d799cafa9d1d1f9906ef41;hp=df3a1ecf14897d0ccbd8ace8ea092ec7bce555f5;hpb=8ae7e7d1b257ef36d8a9fd1cd88807954ef10764;p=gnushogi.git diff --git a/gnushogi/tcontrl.c b/gnushogi/tcontrl.c index df3a1ec..afdb32c 100644 --- a/gnushogi/tcontrl.c +++ b/gnushogi/tcontrl.c @@ -4,6 +4,7 @@ * ---------------------------------------------------------------------- * 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 * @@ -14,8 +15,8 @@ * * 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 @@ -23,8 +24,8 @@ * 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 + * . * ---------------------------------------------------------------------- * */ @@ -162,10 +163,14 @@ void SetResponseTime(short side) { 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; } @@ -251,10 +256,15 @@ void SetResponseTime(short side) 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; @@ -294,7 +304,7 @@ void SetResponseTime(short side) 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); } @@ -345,5 +355,116 @@ CheckForTimeout(int score, int globalscore, int Jscore, int zwndw) #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(); + } }