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 9316899
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 19, 20262026-06-19T02:44:33+00:00 2026-06-19T02:44:33+00:00

I’m not sure if I’m going about this the right way, I’ve created my

  • 0

I’m not sure if I’m going about this the right way, I’ve created my code which works for all “still life” cell arrangements, ie. Beehive, Block, Boat and Loaf. However, for arrangements that are supposed of be manipulated and involve the death and birth of cells I have problems.

Right now I’m creating cells first, and then killing off anyone’s which fall into the rules (If the surrounding neighbours is a total less than or equal to one, equal to or greater than four).

What I have going now, doesn’t work how it’s supposed to. I’ll include some images underneath my code:

public class Untitled {
    public static void main(String[] params){
        Life life = new Life();
        String[][] list = life.readGame();

        life.print(list);
        System.out.println();

        for(int i = 1; i <= 5; i++){
            list = life.run(list);
            life.print(list);
            System.out.println();
        }
    }
}

class Life {
    public String[][] readGame(){
        String[][] array = {
                { "-","-", "-", "-", "-", "-","-"},
                { "-","-", "-", "-", "-", "-","-"},
                { "-","-", "-", "x", "-", "-","-"},
                { "-","-", "-", "x", "-", "-","-"},
                { "-","-", "-", "x", "-", "-","-"},
                { "-","-", "-", "-", "-", "-","-"},
                { "-","-", "-", "-", "-", "-","-"}
        };
        return array;
    }

    public void print(String[][] array){
        for(int x = 0; x < array.length; x++){
            for(int y = 0; y < array[x].length; y++){
                System.out.print(array[x][y]);
            }
            System.out.println();
        }
    }

    public String[][] run(String[][] array){
        populateCells(array);
        System.out.println("Populated:\n");
        print(array);
        killCells(array);
        System.out.println("Killed:\n");
        print(array);
        return array;
    }

    public int amountOfNeighbors(String[][] array, int x, int y){
        int amount = 0;

        for(int x1 = -1; x1 <= 1; x1++){
            if(x + x1 >= 0 && x + x1 < array.length){
                for(int y1 = -1; y1 <= 1; y1++){
                    if(y + y1 >= 0 && y + y1 < array[x1 + x].length){
                        if(!(x1 == 0 && y1 == 0) && !array[x1 + x][y1 + y].equals("-")){ 
                            amount++;
                        }
                    }
                }
            }
        }
        return amount;
    }

    public void populateCells(String[][] array){
        int neighbours;

        for(int x = 0; x < array.length; x++){
            for(int y = 0; y < array[x].length; y++){
                neighbours = amountOfNeighbors(array,x,y);

                if(neighbours == 3){
                    array[x][y] = "x";
                }
            }
        }
    }

    public void killCells(String[][] array){
        int neighbours;

        for(int x = 0; x < array.length; x++){
            for(int y = 0; y < array[x].length; y++){
                neighbours = amountOfNeighbors(array,x,y);

                if(neighbours <= 1 || neighbours >= 4){
                    array[x][y] = "-";
                }
            }
        }
    }
}

As for the images, here’s a simple blinker structure and what happens after population and deletion of cells:

1

2

3

  • 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-19T02:44:34+00:00Added an answer on June 19, 2026 at 2:44 am

    Each time you call run() you need to create a copy of the original board, and use that copy to check the state of each cell as you modify the cells in the original board.

    Otherwise, each time you update a cell you will be inadvertently changing the states of the cells around it.

    This is a fairly common bug in simulations that involve game boards like Game of Life – so now you know to watch out for it 🙂

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

Sidebar

Related Questions

I'm not entirely sure how I managed to jack this up. http://pretty-senshi.com If you
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
this is what i have right now Drawing an RSS feed into the php,
I have this code to decode numeric html entities to the UTF8 equivalent character.
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I have a text area in my form which accepts all possible characters from
Let's say I'm outputting a post title and in our database, it's Hello Y&#8217;all
For some reason, after submitting a string like this Jack’s Spindle from a text
link Im having trouble converting the html entites into html characters, (&# 8217;) i

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.