Forge some nearly-duplicate code into subroutine
authorH.G.Muller <hgm@hgm-xboard.(none)>
Fri, 7 Mar 2014 09:31:34 +0000 (10:31 +0100)
committerH.G.Muller <hgm@hgm-xboard.(none)>
Fri, 7 Mar 2014 09:44:35 +0000 (10:44 +0100)
The code testing for the end of a time-control session, and switching
to the parameters for the next one (in main()) was nearly the same
for computer and opponent, and is made into a new routine RenewTimeControl.

gnushogi/gnushogi.h
gnushogi/main.c
gnushogi/tcontrl.c

index abbf02e..10bc25c 100644 (file)
@@ -1045,6 +1045,7 @@ extern int   InputCommand(int root);
 extern void  ExitShogi(void);
 extern void  ClearScreen(void);
 extern void  SetTimeControl(void);
+extern void  RenewTimeControl(int side, int TCadd);
 extern void  SelectLevel(char *sx);
 
 extern void
index 878ce38..da633c2 100644 (file)
@@ -382,28 +382,8 @@ main (int argc, char **argv)
         else
             InputCommand(true);
 
-        if (opponent == white)
-        {
-            if (flag.gamein || TCadd)
-            {
-                TimeCalc();
-            }
-            else if (TimeControl.moves[opponent] == 0)
-            {
-                if (XC)
-                {
-                    if (XCmore < XC)
-                    {
-                        TCmoves   = XCmoves[XCmore];
-                        TCminutes = XCminutes[XCmore];
-                        TCseconds = XCseconds[XCmore];
-                        XCmore++;
-                    }
-                }
-
-                SetTimeControl();
-            }
-        }
+        if(opponent == white)
+            RenewTimeControl(opponent, TCadd);
 
         compptr = (compptr + 1) % MINGAMEIN;
 
@@ -414,28 +394,8 @@ main (int argc, char **argv)
 #endif
             SelectMove(computer, FOREGROUND_MODE);
 
-            if (computer == white)
-            {
-                if (flag.gamein)
-                {
-                    TimeCalc();
-                }
-                else if (TimeControl.moves[computer] == 0)
-                {
-                    if (XC)
-                    {
-                        if (XCmore < XC)
-                        {
-                            TCmoves = XCmoves[XCmore];
-                            TCminutes = XCminutes[XCmore];
-                            TCseconds = XCseconds[XCmore];
-                            XCmore++;
-                        }
-                    }
-
-                    SetTimeControl();
-                }
-            }
+            if(computer == white)
+                RenewTimeControl(computer, false);
         }
     }
 
index 539cb7f..691f5ae 100644 (file)
@@ -435,3 +435,27 @@ SetTimeControl(void)
     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();
+    }
+}