Q:

Making a toroidal array in C# (console) for my Conway's game of life, need a little help

Hey there, the way my program works so far is...
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)
here's the code (C#) for the member of Grid which I use to find neighbours:  
        public bool Peek(int Horz, int Vert)
    {
        int X = x + Horz, Y = y + Vert;
        if (X < 0)
            X = width - 1;
        else if (X > width - 1)
            X = 0;
        if (Y < 0)
            Y = height - 1;
        else if (Y > height - 1)
            Y = 0;
        return board[X, Y];
    }

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.
I just can't see what's wrong, It should be in here.
in case you need it here is the code (in Program.Main) that counts neighbours
int neighbours = 0;
                for (i = -1; i < 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;
                }

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)

A:

x and y are the 'current position' members of the Class Grid.

I don't see a bug in the code snippet but this statement raises a Big Red Flag.  The grid doesn't have a current position, only a Cell does.  You cannot keep track of the 'next.Cell' state for the grid, it must be computed for each individual cell.  The next grid is created from the new cells after evaluating all the grid positions.  Or use two grids and swap them.

