From: H.G.Muller Date: Fri, 7 Mar 2014 09:31:34 +0000 (+0100) Subject: Forge some nearly-duplicate code into subroutine X-Git-Url: http://winboard.nl/cgi-bin?p=gnushogi.git;a=commitdiff_plain;h=fba3360f72a4da97710e6ef675887a8d2a1a36b2 Forge some nearly-duplicate code into subroutine 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. --- diff --git a/gnushogi/gnushogi.h b/gnushogi/gnushogi.h index abbf02e..10bc25c 100644 --- a/gnushogi/gnushogi.h +++ b/gnushogi/gnushogi.h @@ -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 diff --git a/gnushogi/main.c b/gnushogi/main.c index 878ce38..da633c2 100644 --- a/gnushogi/main.c +++ b/gnushogi/main.c @@ -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); } } diff --git a/gnushogi/tcontrl.c b/gnushogi/tcontrl.c index 539cb7f..691f5ae 100644 --- a/gnushogi/tcontrl.c +++ b/gnushogi/tcontrl.c @@ -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(); + } +}