[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    =?utf-8?q?=5Bknights=5D_src=3A_Determine_whether_to_increment_ti?=
From:       Miha Čančula <miha.cancula () gmail ! com>
Date:       2011-02-16 8:57:11
Message-ID: 20110216085711.62B69A60BE () git ! kde ! org
[Download RAW message or body]

Git commit fb30be9444de58bfa1faffac75facfb371c53081 by Miha Čančula.
Committed on 15/02/2011 at 19:16.
Pushed by mihac into branch 'master'.

Determine whether to increment time depending on move history size.

M  +14   -11   src/gamemanager.cpp     

http://commits.kde.org/knights/fb30be9444de58bfa1faffac75facfb371c53081

diff --git a/src/gamemanager.cpp b/src/gamemanager.cpp
index b0f7511..80ca2f9 100644
--- a/src/gamemanager.cpp
+++ b/src/gamemanager.cpp
@@ -57,9 +57,7 @@ public:
   int timer;
 
   TimeControl whiteTimeControl;
-  int whiteMoves;
   TimeControl blackTimeControl;
-  int blackMoves;
 
   QStack<Move> moveHistory;
   QStack<Move> moveUndoStack;
@@ -74,8 +72,6 @@ GameManagerPrivate::GameManagerPrivate()
     running(false),
     gameStarted(false),
     timer(0),
-    whiteMoves(0),
-    blackMoves(0),
     rules(0)
 {
 
@@ -200,6 +196,15 @@ void Manager::setCurrentTime(Color color, const QTime& time)
     {
         Q_D ( GameManager );
         Move m = d->moveHistory.pop();
+	if ( m.pieceData().first == White )
+	{
+	  d->whiteTimeControl.currentTime = m.time();
+	}
+	else
+	{
+	  d->blackTimeControl.currentTime = m.time();
+	}
+	emit timeChanged ( m.pieceData().first, m.time() );
         if ( d->moveHistory.isEmpty() )
         {
             emit undoPossible(false);
@@ -463,8 +468,6 @@ void Manager::reset()
   d->moveHistory.clear();
   d->moveUndoStack.clear();
   d->gameStarted = false;
-  d->whiteMoves = 0;
-  d->blackMoves = 0;
 }
 
 Rules* Manager::rules() const
@@ -605,20 +608,20 @@ void Manager::sendPendingMove()
     rules()->moveMade ( pendingMove );
     pendingMove = Move();
     
+    int moveNumber;
     switch ( d->activePlayer )
     {
       case White:
-	kDebug() << d->whiteMoves;
-	d->whiteMoves++;
-	if ( d->whiteTimeControl.moves > 0 && ( d->whiteMoves % d->whiteTimeControl.moves ) \
== 0 ) +	moveNumber = ( d->moveHistory.size() + 1 ) / 2;
+	if ( d->whiteTimeControl.moves > 0 && ( moveNumber % d->whiteTimeControl.moves ) == \
0 )  {
 	  setCurrentTime ( White, d->whiteTimeControl.currentTime.addSecs ( \
d->whiteTimeControl.baseTime.minute() * 60 ) );  }
 	break;
 	
       case Black:
-	d->blackMoves++;
-	if ( d->blackTimeControl.moves > 0 && ( d->blackMoves % d->blackTimeControl.moves ) \
== 0 ) +	moveNumber = d->moveHistory.size() / 2;
+	if ( d->blackTimeControl.moves > 0 && ( moveNumber % d->blackTimeControl.moves ) == \
0 )  {
 	  setCurrentTime ( Black, d->blackTimeControl.currentTime.addSecs ( \
d->blackTimeControl.baseTime.minute() * 60 ) );  }


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic