Game of Life Minor fixing please help

Hello, so I'm working on the game of life and I'm stuck at the part where you're suppose to reflect them when the cells hit either a corner or the edge of the program. my program works but it doesn't continue when it hits the corners or edges instead it starts crashing on me and I was wondering if any of the function below is wrong? Thank You!



1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
void Step(int World[ROWS_MAX][COLUMNS_MAX])
{
    //creates TempWorld
    int TempWorld[ROWS_MAX][COLUMNS_MAX];

    //brings in the old World
    //brings in the function of copy World
    //its a simple for loop that that develops the original 2d array but sets it
    //equal to the new array.

    CopyWall(World);

    CopyWorld (World,TempWorld);

        for (int  i = 0; i <= ROWS_MAX - 1; i++)
        {
            for (int j = 0; j <= COLUMNS_MAX - 1; j++)
            {
                //continuously runs count neighbors
                //identifies if the neigbor lives or dies making it a 1 or a 0
                CountNeighbors(World, TempWorld, i, j);

            }
        }

    //outputs the new World.
    CopyWorld (TempWorld, World);
    CopyWall(World);

}

void CopyWall (int World[ROWS_MAX][COLUMNS_MAX])
{

    int TempWorld[ROWS_MAX][COLUMNS_MAX];
    //goes through the rows and exchanges the first and the last row

    CopyWorld(World,TempWorld);

    for (int i=0; i<ROWS_MAX; i++)
    {
        TempWorld[0][i] = World[ROWS_MAX-1][i];
        TempWorld[ROWS_MAX][i] = World[1][i];
    }
    //goes through the columns and exchanges the first and the last
    for (int j=0; j<COLUMNS_MAX; j++)
    {
        TempWorld[j][0] = World[j][COLUMNS_MAX-1];
        TempWorld[j][COLUMNS_MAX] = World[j][1];
    }

cout<<"Did I crash"<<endl;
    //goes through the corners and exchanges the ones diagonal to them.
    TempWorld[0][0] = World[ROWS_MAX+1][COLUMNS_MAX+1];
    TempWorld[0][COLUMNS_MAX] = World[ROWS_MAX+1][1];
    TempWorld[ROWS_MAX][0] = World[1][COLUMNS_MAX+1];
    TempWorld[ROWS_MAX-1][COLUMNS_MAX-1] = World[1][1];

    CopyWorld(TempWorld,World);
}
Last edited on
Where exactly does your program crash? If you're not sure, set some breakpoints as you debug your program.
My guess by looking at the code (and assuming it's this code which is causing the crashing), I'd say you're accessing some array out of bounds somewhere.
for (int i=0; i<ROWS_MAX; i++)
{
TempWorld[0][i] = World[ROWS_MAX-1][i];


Is it ROWS_MAX= COLUMNS_MAX always?
Topic archived. No new replies allowed.