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

  • Home
  • SEARCH
  • 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 6959883
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T15:19:53+00:00 2026-05-27T15:19:53+00:00

I implemented a Conway’s Game of Life in JavaScript but I’m not seeing the

  • 0

I implemented a Conway’s Game of Life in JavaScript but I’m not seeing the same patterns such as Gosper’s Glider Gun. I seed the grid the ways it’s depicted in the Wikipedia article but, the gun never happens.

Will someone look at my code and see if there’s anything wrong with it, any suggestions to the implementation?

https://github.com/DiegoSalazar/ConwaysGameOfLife

  • 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-05-27T15:19:54+00:00Added an answer on May 27, 2026 at 3:19 pm

    You are not updating all of the cells simultaneously, rather sequentially. A cell that is born in the first generation will not appear alive to the calculation of other cells of the first generation (it still counts as dead).

    Create a new property called willBeAlive and use that to hold the cell’s new calculated alive state. Once all the calculations for that generation are done, set each cell’s alive property to its willBeAlive property and redraw.

    Here are the changes:

    Automaton.prototype.update = function() {
      for (var x = 0; x < this.w; x++) {
        for (var y = 0; y < this.h; y++) {
          this.grid[x][y].killYourselfMaybe();
        }
      }
      // set the alive property to willBeAlive
      for (var x = 0; x < this.w; x++) {
        for (var y = 0; y < this.h; y++) {
                this.grid[x][y].alive = this.grid[x][y].willBeAlive;
            }
        }  
    }
    
    
    Cell.prototype.killYourselfMaybe = function(grid) {
      var num = this.numLiveNeighbors();
    
      this.willBeAlive = false;
    
      if (this.alive) {
        // 1. Any live cell with fewer than two live neighbours dies, as if caused by under-population.
        if (num < 2) this.willBeAlive = false;
        // 2. Any live cell with two or three live neighbours lives on to the next generation.
        if (num == 2 || num == 3) { this.willBeAlive = true}
        // 3. Any live cell with more than three live neighbours dies, as if by overcrowding.
        if (num > 3) this.willBeAlive = false;
      } else {
        // 4. Any dead cell with exactly three live neighbours becomes a live cell, as if by reproduction.
        if (num == 3) this.willBeAlive = true;
      }
    }
    

    and here is a seed array for “Gosper’s Glider Gun”:

    [[2,6],[2,7],[3,6],[3,7],[12,6],[12,7],[12,8],[13,5],[13,9],[14,4],[14,10],[15,4],[15,10],[16,7],[17,5],[17,9],[18,6],[18,7],[18,8],[19,7],[22,4],[22,5],[22,6],[23,4],[23,5],[23,6],[24,3],[24,7],[26,2],[26,3],[26,7],[26,8],[36,4],[36,5],[37,4],[37,5]]
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have implemented Conway's Game of Life problem in Java swing. Everything is working
I implemented an rpc call. It works on local machine but does not work
I'm trying to implement Conway's Game of Life on an embedded device. I've only
I am currently trying to implement Conway's Game of Life in a Code, and
I'm working on a Java implementation of Conway's game of life as a personal
I implemented a quick search in my application. But when I turned the screen,
I implemented a javascript menu onto my site http://www.ogormanconstruction.co.uk/work If you select 'Work' then
I implemented the delegate-callback pattern between two classes without retaining the delegate. But in
I implemented an http server using javascript and Node.js. for some reason when the
I implemented in my app MFMessageComposeViewController for send sms. It works well, but 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.