C++ dynamic array "losing" data -


so firstly, here's declaration , initialization:

int** gamefield = 0; gamefield = new int*[mapsize];                   for(int = 0; < mapsize; i++)         gamefield[i] = new int[mapsize];  for(int j = 0; j < mapsize; j++)                         for(int = 0; < mapsize; i++)             gamefield[i][j] = 0; 

now i'm trying insert data simple command:

if(!(player1.find(move) == player1.end()) && iter>0)                     {             gameresult=1;                                                }else         {             player1[move] = 1;                                       gamefield[move.first][move.second]=1;                            if(wincheck(player1, move, x, mapsize))                 gameresult = 1;         } 

simoultaneously insert data stl map. visual studio has no native display dynamic data, i'm unable view content of table. tried watching memory it's pretty hard make sense of it. there part of program seems working till point:

    bool checkifmovepossible(int **gamefield, pair <int,int> &move, int mapsize) {     int x = move.first;     int y = move.second;     bool neighbour = false;      if(gamefield[modulo(x+1,mapsize)][y]==(1||2))                       // po prawej         neighbour = true;      if(gamefield[modulo(x+1,mapsize)][modulo(y+1,mapsize)]==(1||2))         neighbour = true;      if(gamefield[modulo(x+1,mapsize)][modulo(y-1,mapsize)]==(1||2))         neighbour = true;      if(gamefield[x][modulo(y+1,mapsize)]==(1||2))                       // x         neighbour = true;      if(gamefield[x][modulo(y-1,mapsize)]==(1||2))         neighbour = true;      if(gamefield[modulo(x-1,mapsize)][modulo(y+1,mapsize)]==(1||2))     // po lewej         neighbour = true;      if(gamefield[modulo(x-1,mapsize)][y]==(1||2))         neighbour = true;      if(gamefield[modulo(x-1,mapsize)][modulo(y-1,mapsize)]==(1||2))         neighbour = true;      return neighbour;  } 

it's supposed check if there neighbouring data in container. calculate values manualy , using debugger, , in each case program acts if there no data in requested location, while must there present in map. info appreciated.

it appears wanted code this

if(gamefield[modulo(x+1,mapsize)][y]==(1||2))   

is this.

if ( gamefield[modulo(x+1,mapsize)][y] == 1 ||      gamefield[modulo(x+1,mapsize)][y] == 2)   

unrelated question, seems logic a lot of work after has been determined function return true.

consider using else if or having code return true it's determined that return value.


Comments

Popular posts from this blog

monitor web browser programmatically in Android? -

Shrink a YouTube video to responsive width -

wpf - PdfWriter.GetInstance throws System.NullReferenceException -