Overlapping values in the matrix

Asked

Viewed 55 times

0

Ola has a matrix that is formed by a set of random numbers. However some of these sets of numbers overlap. What can I do?inserir a descrição da imagem aqui

void ransnipa(int (*board)[40]){
    srand(time(NULL));
    int k;
    int x[snipa];
    int y[snipa];


    for(k=0 ; k < snipa ;k++){
        x[k]= rand() % 39;
        y[k]= rand() % 39;

        do{

            x[k]= rand() % 39;
            y[k]= rand() % 39;

        }while(( (board[x[k]][y[k]]) && (board[x[k]+1][y[k]]) && (board[x[k]+1][y[k]+1]) && (board[x[k]][y[k]+1])) == -1);

        board[x[k]][y[k]]=2;
        board[x[k]+1][y[k]]=2;
        board[x[k]+1][y[k]+1]=2;
        board[x[k]][y[k]+1]=2;



    }

}
void rantank(int (*board)[40]){
    srand(time(NULL));
    int k;
    int x[tank];
    int y[tank];
    int ant;

    for(k=0 ; k < tank ;k++){
        x[k]= rand() % 39;
        y[k]= rand() % 39;

        do{

            x[k]= rand() % 39;
            y[k]= rand() % 39;

        }while(((board[x[k]][y[k]]) && (board[x[k]+1][y[k]]) && (board[x[k]+1][y[k]+1]) && (board[x[k]][y[k]+1]) && (board[x[k]][y[k]-1]) && (board[x[k]+1][y[k]-1]) && (board[x[k]-1][y[k]-1]) && (board[x[k]-1][y[k]]) && (board[x[k]-1][y[k]+1])) == -1);

        board[x[k]][y[k]]=3;
        board[x[k]+1][y[k]]=3;
        board[x[k]+1][y[k]+1]=3;
        board[x[k]][y[k]+1]=3;

        board[x[k]][y[k]-1]=3;
        board[x[k]+1][y[k]-1]=3;
        board[x[k]-1][y[k]-1]=3;
        board[x[k]-1][y[k]]=3;
        board[x[k]-1][y[k]+1]=3;

    }

}
  • Friend has no way to post the full source code (by Git or right here)? Because I’m assuming the variables tank and snipa be declared globally. If this is true, most likely these variables have been overwritten/changed. Some solutions: - Use const to make the global variables secure from a possible overwrite; - Use #define NOME_DA_VARIAVEL VALOR; - Don’t use global variable; unfortunately I can’t give a better opinion, because I can’t debug and track code.

  • O que você está querendo testar com esta condição: (((board[x[k]][y[k]]) && (board[x[k]+1][y[k]]) && (board[x[k]+1][y[k]+1]) && (board[x[k]][y[k]+1]) && (board[x[k]][y[k]-1]) && (board[x[k]+1][y[k]-1]) && (board[x[k]-1][y[k]-1]) && (board[x[k]-1][y[k]]) && (board[x[k]-1][y[k]+1])) == -1)? What you expect as a result of operations && (logical E) on integers?

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.