Add time increment after move in XBoard mode
[gnushogi.git] / gnushogi / tcontrl.c
index f8f15dc..4e1da41 100644 (file)
@@ -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
  *
@@ -163,7 +164,8 @@ void SetResponseTime(short side)
                 short rtf = in_opening_stage ? 8 : 2;
                 short tcq = in_opening_stage ? 2 : 4;
 
-                TimeControl.clock[side] += TCadd;
+                if(!xboard) /* no pre-add of increment in XBoard mode */
+                    TimeControl.clock[side] += TCadd;
                 ResponseTime = (TimeControl.clock[side])
                     / (((TimeControl.moves[side]) * rtf) + 1);
                 TCleft = (long)ResponseTime / tcq;
@@ -251,7 +253,9 @@ void SetResponseTime(short side)
         else
         {
             /* calculate avg time per move remaining */
-            TimeControl.clock[side] += TCadd;
+
+            if(!xboard) /* no pre-add of increment in XBoard mode */
+                TimeControl.clock[side] += TCadd;
 
             ResponseTime = (TimeControl.clock[side])
                 / (((TimeControl.moves[side]) * 2) + 1);
@@ -294,7 +298,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);
 }
 
@@ -413,3 +417,48 @@ ElapsedTime(ElapsedTime_mode iop)
             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();
+    }
+}