title: Making a toroidal array in C# (console) for my Conway's game of life, need a little help
body: <p>Hey there, the way my program works so far is...</p>
  
  <p>I have a class called Grid, so far this works, 
  Grid contains a member, 'board' which is a 2D array of bools.
  I manage to load values from a file into the grid fine, 
  in fact I manage to preform Conway's life iterations just fine,
  however the program behaves as if the cells outside the grid are dead (not toroidal)</p>
  
  <p>here's the code (C#) for the member of Grid which I use to find neighbours:  </p>
  
  <pre><code>        public bool Peek(int Horz, int Vert)
      {
          int X = x + Horz, Y = y + Vert;
          if (X &lt; 0)
              X = width - 1;
          else if (X &gt; width - 1)
              X = 0;
          if (Y &lt; 0)
              Y = height - 1;
          else if (Y &gt; height - 1)
              Y = 0;
          return board[X, Y];
      }
  </code></pre>
  
  <p>this appears to be where the problem is,
  Horz and Vert are defining the relative position in the array 'board'
  x and y are the 'current position' members of the Class Grid.</p>
  
  <p>I just can't see what's wrong, It should be in here.</p>
  
  <p>in case you need it here is the code (in Program.Main) that counts neighbours</p>
  
  <pre><code>int neighbours = 0;
                  for (i = -1; i &lt; 2; i++)
                  {
                      if (grid.Peek(i, -1))
                          neighbours++;
                      if (grid.Peek(i, 1))
                          neighbours++;
                  }
                  if (grid.Peek(-1, 0))
                      neighbours++;
                  if (grid.Peek(1, 0))
                      neighbours++;
                  if (grid.Cell)
                  {
                      if (neighbours == 2 || neighbours == 3)
                          next.Cell = true;
                      else next.Cell = false;
                  }
                  else
                  {
                      if (neighbours == 3)
                          next.Cell = true;
                      else next.Cell = false;
                  }
  </code></pre>
  
  <p>the value of grid.Cell (grid being an instance of Grid) is the same as grid.Peek(0, 0) and then the x and y positions in the grid object move to the next cell. (as part of the get and set methods)</p>