Note that there are some explanatory texts on larger screens.

plurals
  1. POC++ dynamic array "losing" data
    primarykey
    data
    text
    <p>So firstly, here's my declaration and initialization:</p> <pre><code>int** GameField = 0; GameField = new int*[mapsize]; for(int i = 0; i &lt; mapsize; i++) GameField[i] = new int[mapsize]; for(int j = 0; j &lt; mapsize; j++) for(int i = 0; i &lt; mapsize; i++) GameField[i][j] = 0; </code></pre> <p>Now i'm trying to insert data with a simple command:</p> <pre><code>if(!(Player1.find(Move) == Player1.end()) &amp;&amp; iter&gt;0) { GameResult=1; }else { Player1[Move] = 1; GameField[Move.first][Move.second]=1; if(WinCheck(Player1, Move, x, mapsize)) GameResult = 1; } </code></pre> <p>Simoultaneously i insert the data into an STL map. Visual Studio has no native display for dynamic data, so i'm unable to view the content of the table. Tried watching memory but it's pretty hard to make sense of it. There is a part of program that seems to be working till a certain point:</p> <pre><code> bool CheckIfMovePossible(int **GameField, pair &lt;int,int&gt; &amp;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; } </code></pre> <p>It's supposed to check if there are any neighbouring data in the container. I calculate the values manualy and using the debugger, and in each case the program acts as if there is no data in requested location, while it must there for it is present in the map. Any info will be appreciated.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload