   allGreen();
   delay(1000);
   clearSquares();
-  // Initialize the baseboard peripherals 
+  // 2 - Initialize the baseboard peripherals 
   initializeHardwarePeripherals();
-  // Show the welcome message
+  // 3 - Show the welcome message
   doWelcome();  
-  // Find other player
-  rival_id = findPlayer();
+  // 4 - Find other player
+  String result = findPlayer();
+  start_turn = result[4];
+  rival_id = result.substring(0,4);
 }
 
 void loop() {
   delay(200);
-  
-  // ************************************************************************
-  // ******** Player turn ***************************************************
-  // ************************************************************************
-  for (int i = 0; i < 9; i++){
-    previousGreenStatus[i] = greenStatus[i];
-  }
-  // 1 -Update color status
-  //   -Check player move, wait until it happens
-  printMsg("Your turn.");
-  boolean waitForMove = true;  
-  int player_move = 0;
-  
-  while (waitForMove){
-    updateBoardStatus();  
-    player_move = checkPlayerMove();
-    if (player_move == -1){
-      // No move, wait and check again
-      delay(30);
-    }else if (player_move > -1){
-      // Legal move, continue
-      waitForMove = false;
-    } else if (player_move == -2){
-      // Player has moved 2 pieces, illegal move      
-      msgAndWait("You moved two pieces! Correct you move.");      
-    } else if (player_move == -3){
-      // Player has moved the piece into an square already used.     
-      msgAndWait("You moved your piece into an already used square! Correct you move.");
-    }
-  }
-
-  // 2- Send move to server  
-  sendMove(player_move);
-  
-  // 3 -Check victory conditions
-  greenVictory = checkWin(greenStatus);
-  if (greenVictory){
-    printMsg("A winner is you"); //TODO think some proper msgs
-    victoryLoop('g');
-  }
-  
-  
-  
-  // ************************************************************************
-  // ******* Rival turn *****************************************************
-  // ************************************************************************
-  printMsg("Wait for your rival's move.");
-  
-  // 1- 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;    
-    }
-  }  
-  // 2- Update color status
-  if (rival_move > -1 && rival_move  < 9){
-    redStatus[rival_move] = 1;
-    squares[rival_move]->setRed();
-  }
-  
-  // 3 -Check victory conditions
-  redVictory = checkWin(redStatus);
-  if (redVictory){
-    printMsg("You lose!"); 
-    victoryLoop('r');
+  if ((turn > 0) || (turn == 0 && start_turn=='0')){
+    // ************************************************************************
+    // ******** Player turn ***************************************************
+    // ************************************************************************
+    for (int i = 0; i < 9; i++){
+      previousGreenStatus[i] = greenStatus[i];
+    }
+    // 1 -Update color status
+    //   -Check player move, wait until it happens
+    printMsg("Your turn.");
+    boolean waitForMove = true;  
+    int player_move = 0;
+    
+    while (waitForMove){
+      updateBoardStatus();  
+      player_move = checkPlayerMove();
+      if (player_move == -1){
+        // No move, wait and check again
+        delay(30);
+      }else if (player_move > -1){
+        // Legal move, continue
+        waitForMove = false;
+      } else if (player_move == -2){
+        // Player has moved 2 pieces, illegal move      
+        msgAndWait("You moved two pieces! Correct you move.");      
+      } else if (player_move == -3){
+        // Player has moved the piece into an square already used.     
+        msgAndWait("You moved your piece into an already used square! Correct you move.");
+      }
+    }
+  
+    // 2- Send move to server  
+    sendMove(player_move);
+    
+    // 3 -Check victory conditions
+    greenVictory = checkWin(greenStatus);
+    if (greenVictory){
+      printMsg("A winner is you"); //TODO think some proper msgs
+      victoryLoop('g');
+    }
+  }
+  
+  if ((turn > 0) || (turn == 0 && start_turn=='1')){
+    // ************************************************************************
+    // ******* Rival turn *****************************************************
+    // ************************************************************************
+    printMsg("Wait for your rival's move.");
+    
+    // 1- 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;    
+      }
+    }  
+    // 2- Update color status
+    if (rival_move > -1 && rival_move  < 9){
+      redStatus[rival_move] = 1;
+      squares[rival_move]->setRed();
+    }
+    
+    // 3 -Check victory conditions
+    redVictory = checkWin(redStatus);
+    if (redVictory){
+      printMsg("You lose!"); 
+      victoryLoop('r');
+    }
   }
 }
 

 *   COMMUNICATION WITH THE GAME SERVER
 **********************************************/

int findPlayer(){
  //TODO
  // rival_id = send ("REGISTER " + player_id + "\0n")
  // returns the rival_id
  return 113;

}

int getMove(){
  //TODO
  // move = send ("GET_MOVE " + rival_id)
  return 0;
}

void sendMove(int player_move){
  //TODO
  // send ("MOVE " + player_move + player_id)
  Serial.println("sending move");
}


void setup() {  
  Serial.begin(9600);
  Serial.println("Setup...");
  // 1 - Initialize the tictactoe board
  for (int i = 0; i < 9; i++){
    squares[i] = new Square(8 - i, i + 1, &_sd);
  }
