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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T20:25:10+00:00 2026-06-16T20:25:10+00:00

I have the following logic code for my Game of Life application in Java.

  • 0

I have the following logic code for my Game of Life application in Java. I have the problem that the rules do not act like the default Conway’s Game of Life rules. I have read up on them on Wikipedia, and they are the following;

  • Any live cell with fewer than two live neighbours dies, as if caused by under-population.
  • Any live cell with two or three live neighbours lives on to the next generation.
  • Any live cell with more than three live neighbours dies, as if by overcrowding.
  • Any dead cell with exactly three live neighbours becomes a live cell, as if by reproduction.

I have attempted to duplicate these rules in the following code, but it acts unlike the normal Conway’ Game of Life;

int surroundingLife = 0;
if (lifeMap[cX+1][cY]) { //Right
    surroundingLife++;
}
if (lifeMap[cX-1][cY]) { // Left
    surroundingLife++;
}
if (lifeMap[cX][cY+1]) { // Above
    surroundingLife++;
}
if (lifeMap[cX][cY-1]) { // Below
    surroundingLife++;
}
if (lifeMap[cX-1][cY-1]) { // Bottom left
    surroundingLife++;
}
if (lifeMap[cX+1][cY+1]) { // Top Right
    surroundingLife++;
}
if (lifeMap[cX-1][cY+1]) { // Some other corner (I don't know which one)
    surroundingLife++;
}
if (lifeMap[cX+1][cY-1]) { // Yet another corner (I don't know which one)
    surroundingLife++;
}
if (running) {
    // Logic for life
    if (surroundingLife < 2 && lifeMap[cX][cY]) {// Rule 1. Any live cell with fewer than two live neighbours dies, as if caused by under-population.
        lifeMap[cX][cY] = false;
    } else if (surroundingLife == 2 && lifeMap[cX][cY]) { // Rule 2. Any live cell with two or three live neighbours lives on to the next generation.
        lifeMap[cX][cY] = true;
    } else if (surroundingLife == 3 && lifeMap[cX][cY]) { // Rule 3. Same as above
        lifeMap[cX][cY] = true;
    } else if (surroundingLife > 3 && lifeMap[cX][cY]) { // Rule 4. Any live cell with more than three live neighbours dies, as if by overcrowding.
        lifeMap[cX][cY] = false;
    } else if (surroundingLife == 3 && !lifeMap[cX][cY]) { // Any dead cell with exactly three live neighbours becomes a live cell, as if by reproduction.
        lifeMap[cX][cY] = true;
    }
}   

This is how it looks after running a couple of generations;

GameOfBugs, or BugsOfLife.

It reminds me of the ‘maze’ ruleset, which is odd.

I don’t believe there is a fault with my surroundingLife calculator, as it returns 8 when entities have 8 others surrounding them. Is the problem due to me looping through Y then X?

  • 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-16T20:25:11+00:00Added an answer on June 16, 2026 at 8:25 pm

    The problem is that you are modifying the grid in the same pass as you are evaluating what needs to change. Each time you change a cell, you are affecting the outcome of all future tests in the same pass that border that cell.

    You need to make a copy of the grid. Always test (read) from that copy, and apply changes (write) to the original.

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

Sidebar

Related Questions

I have a code that has the following logic. g++ gives me the error
I need syntax help with the following code logic: I have a code block
I have the following logic in my code if((leftCombo.getSelectedIndex() !> rightCombo.getSelectedIndex())&&(rightCombo.getSelectedIndex() !< leftCombo.getSelectedIndex()) Doing
I have a bit of code with the following logic: //pseudo-code foreach (element in
I have an Android application with the following logic of activities execution: if FIRST_RUN
Long story short Say I have the following code: // a class like this
I have the following logic in a more than decade old code for which
I have seen code with the following logic in a few places: public void
I have following code. Parent Class: class Parent{ void a() { if(// some logic
I have following code for the UIAlertView Loading indicator which is not working and

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.