Jump to content

Problema num alguritmo do jogo "lifegame"


sebas

Recommended Posts

Eu não precebo muito disto, pois so tenho programação ha 2 meses e para projecto final tenho que fazer o "lifegame". Os professores deram umas ajudas mas o meu programa esta a dar um erro e n sei qual é. Podem me ajudar?

No main.c:

...(um pequeno excerto)

imprime(game, dimx, dimy);
    //evoluir a matriz

  /* while(1)
    {
      evolui( game,dimx,dimy);
      imprime(game,dimx,dimy);

     //verificar se carregaou nalguma tecla
      if( kbhit())
        break;
    }

   */ //libertar a memoria da matriz
    liberta( game, dimy);

    return 0;
}

e na biblioteca

int numVivos( char**game,int dimx,  int dimy, int x, int y)
{
    int count = 0;
for (py=1;py<dimy-1;py++)
{
     for (px=1;px<dimy-1;px++)
{


         //1ª linha

         if(game[y-1][x-1]=='o') count++;
         if(game[y-1][x]=='o') count++;
         if(game[y-1][x+1]=='o') count++;

        // 2ª linha

         if(game[y][x-1]=='o') count++;
         if(game[y][x+1]=='o') count++;

   

         if(game[y+1][x+1]=='o') count++;
         if(game[y+1][x]=='o') count++;
         if(game[y+1][x-1]=='o') count++;
    }
}
    // contar as celulas vivas
    return count;
}

void evolui( char ** game,int dimx,  int dimy)
{
    char **tmp;
    int x,y, vivas;
    //alocar memoria para o jogo tempoarario
    tmp = aloca(dimx, dimy);
    //inicializar as celulas
    limpa( tmp, dimx,dimy);

    //percorrer todas as linhas
    for (y=1; y<dimx-1; y++)
    {
         //percorrer todas as colunas
         for (x=1; x<dimx-1; x++)
         {
             vivas = numVivos(game,dimx,dimy,x,y);
         if(vivas<2) tmp [y][x]='.';
         if(vivas>3) tmp [y][x]='.';
         if(vivas==3) tmp [y][x]='x';
         if(vivas==2) tmp [y][x]=game [y][x];
         }

    }

   /* //copiar o tmp para o game
    for(y=0; y < dimy; y++)
    {
         for( x=0; x < dimx; x++)
         {
             game[y][x] = tmp[y][x];
         }
    }
    *///libertar o tmp
    liberta(tmp,dimy);

}

mas o meu programa dá me 4 erros no "int numVivos"

C:\Users\Sebastião\Desktop\C\life\LifeGame.c:96: error: `py' undeclared (first use in this function)

C:\Users\Sebastião\Desktop\C\life\LifeGame.c:96: error: (Each undeclared identifier is reported only once

C:\Users\Sebastião\Desktop\C\life\LifeGame.c:96: error: for each function it appears in.)

C:\Users\Sebastião\Desktop\C\life\LifeGame.c:98: error: `px' undeclared (first use in this function)

o que esta mal? Podem explicar o que posso fazer?

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

By using this site you accept our Terms of Use and Privacy Policy. We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.