title: C game and matrix
body: <p>I have a problem that I don't know how to solve.</p>
  <p>I have this matrix (original photo at <a href="https://i.stack.imgur.com/Z7Ssu.png" rel="nofollow noreferrer">https://i.stack.imgur.com/Z7Ssu.png</a> ):</p>
  <pre><code>{
    {   0,   1,   0,   2,   0,   3,   0,   0,   0,   0,   0,   0,   0,   0,   0},
    {   0,   4,   5,   6,   5,   4,   0,   0,   0,   0,   0,   0,   0,   0,   0},
    {   0,   0,   0,   7,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0},
    {   0,   0,   0,   8,   9,  10,  11,  12,  13,  14,  15,  16,  17,  18,   0},
    {   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,  19,   0},
    {   0,   0,   0,   0,   0,   0,   0,  26,  25,  24,  23,  22,  21,  20,   0},
    {   0,   0,   0,   0,   0,   0,   0,  27,   0,   0,   0,   0,   0,   0,   0},
    {   0,   0,   0,   0,  41,  42,  43, 255,   0,   0,   0,   0,   0,   0,   0},
    {   0,   0,   0,   0,  40,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0},
    {   0,   0,   0,   0,  39,   0,   0,  24,  23,  22,   0,  16,  15,  14,   0},
    {   0,  35,  36,  37,  38,   0,   0,  25,   0,  21,   0,  17,   0,  13,   0},
    {   0,  34,   0,   0,   0,  28,  27,  26,   0,  20,  19,  18,   0,  12,   0},
    {   0,  33,  32,  31,  30,  29,   0,   0,   0,   0,   0,   0,   0,  11,   0},
    {   0,   0,   0,   0,   0,   0,   0,   4,   5,   6,   7,   8,   9,  10,   0},
    {   0,   0,   0,   0,   0,   0,   0, 254,   0,   0,   0,   0,   0,   0,   0},
  }
  
  </code></pre>
  <p>The soldier spawn at the number 254 in the matrix then after this, he will follow the numbers which represent the road.</p>
  <p>The road that the soldier will have to follow will be the number 4 then 5 then 6 etc... and to do that, the soldier will go to the point around him where the number is the highest.</p>
  <p>The soldier is represented by a number, we can say It's 230. I want to do a function that will move the soldier by one number only.
  For example, if the soldier spawn, then he is at the number 254, so there will be no more number 254 because the number 230 will have the point. When i will call the function, the soldier, so the number 230 will be at 4. then again, when i will call the function, he will be at 5. and each time the soldier moves, the point where he was, will be equal to the number he moved to minus 1.</p>
  <p>This is what i have done :</p>
  <pre><code>int point_around[4];
  for( i=0 ; i &lt; 15 ; i++){
      for( j=0 ; j &lt; 15 ; j++){
          if( matrix[i][j] == 230){
                  
                  /* in point_around array we have the points around */
                  get_point_around(matrix[i][j], point_around);
  
                  /* looking for the max point, around the number 230 */
                  /* sort the array to have the max point */
                  size_tab=4;
                  while( size_tab&gt; 1 ){ 
                      for( k=0 ; k &lt;  size_tab-1 ; k++ ){
                          if( point_around[k] &gt; point_around[k+1] ){ 
                              tmp = point_around[k];
                              point_around[k] = point_around[k+1];
                              point_around[k+1] = tmp;
                          }
                      }
                      size_tab--;
                  }
  
                  max = point_around[3];
                 
                  if( max == matrix[i-1][j] ){
                      matrix[i-1][j] = 230;
                  } 
                  else if( max == matrix[i][j+1] ){
                      matrix[i][j+1] = 230; 
                  }
                  else if( max == matrix[i+1][j] ){
                      matrix[i+1][j] = 230;
                  }  
                  else {
                      matrix[i][j-1] = 230;
                  }  
                                      
                  matrix[i][j] = max - 1;
      }
  }
                  
                
  </code></pre>
  <p>My problem is that when he will move to the right, so i call the function one time for him to move one time, he will move many times because of the j loop. I don't know how i can fix this.</p>