Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9005809
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T01:14:37+00:00 2026-06-16T01:14:37+00:00

I’m writing a program based on John Conway’s Game of Life. I got it

  • 0

I’m writing a program based on John Conway’s Game of Life. I got it to compile and Even run after days of working on it non stop. However, the result it is printing out is wrong…

This is my code (not including the main method)

 //clears the grid
public static void clearGrid ( boolean[][] grid )
{

    for(int row = 0; row < 18; row++){
       for(int col = 0; col < 18; col++){
          grid[row][col]= false;
       }
    }
    //set all index in array to false
}

//generate the next generation
public static void genNextGrid ( boolean[][] grid )
{
    int n; //number of neighbors

    boolean[][] TempGrid = grid;// a temporary array
    for(int row = 0; row < 18; row++)
    {
        for(int col = 0; col < 18; col++)
        {
            TempGrid[row][col] = grid[row][col];
            n = countNeighbors(grid, row, col);

            if(grid[row][col] == true)
            {
                if(n != 2 && n != 3)
                {
                    TempGrid[row][col] = false;
                }
                else
                    TempGrid[row][col] = true;
            }

            else
            {
                if(n == 3)
                {
                    TempGrid[row][col] = true;
                }
                else
                    TempGrid[row][col] = false;
            }
            grid[row][col] = TempGrid[row][col];
        }
    }
}

 //count how many neighbors surrounding any speicific cell
public static int countNeighbors ( final boolean[][] grid, final int row, final int col )
{
    int n = 0;
    for (int TempRow = row - 1; TempRow <= row + 1; TempRow++)
    {
        if (TempRow >= 0 && TempRow < 18)
        {
            for (int TempCol = col - 1; TempCol <= col + 1; TempCol++)
            {
                if (TempCol >= 0 && TempCol < 18 && (TempRow != row || TempCol != col))
                {
                    if (grid[TempRow][TempCol])
                    {
                        n++;
                    }
                }
            }
        }
    }
    return n;
 }

I am pretty sure that the problem is occuring within my genNextGrid method.

The assignment sheet included

public static void genNextGrid (boolean[][] grid);

This method will actually generate the next generation of the simulation.
It should use the two-dimensional array grid that is passed to it as the “current” generation. It should create a second,
temporary two-dimensional array that will hold the “next” generation. You will need to create this temporary matrix to work
with as you can’t make changes to the current matrix because you would risk losing all of the information you need in
order to successfully create the next generation.”

  1. I created a temporary array
  2. I copied the current array to the temporary
  3. I later copied the temporary back to current array like the instruction said.

so I’m not really sure what I did wrong.

It’s nearly 3 a.m, been staring at my Vim screen since noon. Any help would be greatly appriciated.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T01:14:38+00:00Added an answer on June 16, 2026 at 1:14 am

    In addition to not really creating a new temp array but just getting a reference to old one, as said in other answers: you copy the tempGrid cell into the grid cell in the same loop where you calculated it. So next loop iteration will use the new calculated value, instead of the current “old” value in grid.

    You need to first calculate entire tempGrid, and then copy it over grid. Or better than copying, would be to set grid to point to tempGrid’s array, but that might be out of scope of your homework (you would have to return tempGrid from genNextGrid() and assign it to original grid reference).

    The whole point of needing a tempGrid instead of just single temp cell is, you need the previous generation in grid during calculation of next generation.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am writing an app for my school newspaper, which is run completely online
link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
Configuring TinyMCE to allow for tags, based on a customer requirement. My config is
I've got a string that has curly quotes in it. I'd like to replace
I have a small JavaScript validation script that validates inputs based on Regex. I
I would like to run a str_replace or preg_replace which looks for certain words
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
i got an object with contents of html markup in it, for example: string

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.