     color = squares[i]->checkColor();
     if (previousGreenStatus[i] != greenStatus[i]){
       totalMoves++;
-      player_move = i+1;
+      player_move = i;
     }
   }
   
   if (totalMoves == 0) {
     // The player has not done any move
-    player_move = 0;
+    player_move = -1;
   } else if (totalMoves > 1) {
     // The player has moved 2 pieces, which is an illegal move
-    player_move = -1;
+    player_move = -2;
   }
   else if (color == 'r'){
     // The player has moved his piece into an square already used by the rival
-    player_move = -2;
+    player_move = -3;
   }
   
   return player_move;

  while (waitForMove){
    updateBoardStatus();  
    player_move = checkPlayerMove();
    if (player_move == 0){
      // No move, wait and check again
      delay(30);
    }else if (player_move > 0){
      // Legal move, continue
      waitForMove = false;
    } else if (player_move == -1){
      // Player has moved 2 pieces, illegal move      
      msgAndWait("You moved two pieces! Correct you move.");      
    } else if (player_move == -2){
      // Player has moved the piece into an square already used.     
      msgAndWait("You moved your piece into an already used square! Correct you move.");
    }

  
  
  
  // ************************************************************************
  // ******* Rival turn *****************************************************
  // ************************************************************************
  printMsg("Wait for your rival's move.");
  
  // Check rival move, wait until it happens
  waitForMove = true;
  int rival_move = -1;
  while(waitForMove){
    rival_move = getMove();
    // Wait and check again
    if (rival_move < 0){
      delay(100);
    } else{
      waitForMove = false;    
    }
  }  
  // Update color status
  if (rival_move > -1 && rival_move  < 9){
    redStatus[rival_move] = 1;
    squares[rival_move]->setRed();
  }
  
  // Check victory conditions
  redVictory = checkWin(redStatus);
  if (redVictory){
    printMsg("You lose!"); 
    victoryLoop('r');
  }
}

/**********************************************
