   
   for(int e = 0; e < 4; e++){
 
-    if(matrix[current[e][0]+pos[0]-1][current[e][1]+pos[1]] != 0){
+    if((current[e][0] + pos[0] - 1) < 0 ){
+        moveable = 0;
+    }
+
+    if((current[e][0] + pos[0] - 1) >= matrixx ){
+        moveable = 0;
+    }
+
+    if(current[e][1] + pos[1] < 0 ){
+        moveable = 0;
+    }
+
+    if(current[e][1] + pos[1] >= matrixy ){
+        moveable = 0;
+   } 
+
+
+    if(moveable && matrix[current[e][0]+pos[0] - 1][current[e][1]+pos[1]] != 0){
       moveable = 0;
     }
 
-    if(current[e][0]+pos[0]-1 == -1){
-      moveable = 0;
-    }
-
-  }
-  
-  if(moveable == 1){
+  }
+  
+  if(moveable){
     pos[0]--;
   }
 

  
  for(int e = 0; e < 4; e++){

    if(matrix[current[e][0]+pos[0]][current[e][1]+pos[1]] != 0){
      moveable = 0;
    }

    if(current[e][0]+pos[0] < 0){
      moveable = 0;
    }

    if(current[e][0]+pos[0] > 9){
      moveable = 0;
    }



void down(){
  moveable = 1;

  for(int e = 0; e < 4; e++){

    if(current[e][0] + pos[0] < 0 ){
        moveable = 0;
    }

    if(current[e][0] + pos[0] >= matrixx ){
        moveable = 0;
    }

    if((current[e][1] + pos[1] - 1) < 0 ){
        moveable = 0;
    }

    if((current[e][1] + pos[1] - 1) >= matrixy ){
        moveable = 0;
   } 

    if(moveable && (matrix[current[e][0] + pos[0]][current[e][1] + pos[1] - 1] != 0)) {
      moveable = 0;
    }

  }
  
  if(moveable){
    pos[1]--;
  }else{
    add(random(7));
  }

}

void right(){
    
  moveable = 1;
  
  for(int e = 0; e < 4; e++){

    if((current[e][0] + pos[0] + 1) < 0 ){
        moveable = 0;
    }

    if((current[e][0] + pos[0] + 1) >= matrixx ){
        moveable = 0;
    }

    if(current[e][1] + pos[1] < 0 ){
        moveable = 0;
    }

    if(current[e][1] + pos[1] >= matrixy ){
        moveable = 0;
   } 

    if(moveable && matrix[current[e][0]+pos[0] + 1][current[e][1]+pos[1]] != 0){
      moveable = 0;
    }

  }
  
  if(moveable){
    pos[0]++;
  }
}
