예제 #1
0
 //add a ring to the top of the tower if smaller then preceding ring
 bool AddRing(int ringValue) {
     if(TowerManager.CheckMoveValidity(this, ringValue))
     {
         stack.push(ringValue);
         return true;
     }
     //move was invalid so ring cannot be moved
     else return false;
 }   
예제 #2
0
 /*
 * Method description: 
 * moves a ring from one tower (stack) to another
 * Inputs:
 * from and to are the stacks the ring is moving from and to respectively
 * 
 * Output: from and to stacks are modified to reflect the move
 */
 void MoveRing(Stack from, Stack to)
 {
     //remove the ring from the first stack if not empty
     if(from.Count == 0) return;
     int ringValue = from.Peek());
     if(TowerManager.CheckMoveValidity(to, ringValue))
     {
         to.Push(from.Pop());
     }
     //simulate move by pushing to the destination stack the popped value from the source stack
     moves++;
 }