Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

*Javascript Requirements: You are not creating a visualization of Conway's Game of Life. You are simply writing a function named stepBoard that takes a 2D

*Javascript

student submitted image, transcription available belowstudent submitted image, transcription available below

Requirements:

You are not creating a visualization of Conway's Game of Life. You are simply writing a function named stepBoard that takes a 2D array of booleans and returns a 2D array of booleans. That's it.

Put JavaScript code in file named conway.js.

Your file must contain a top-level function named stepBoard. You may write as many other helper functions as you want, but we will only test your code by calling stepBoard.

stepBoard takes a board as input. A board is a 2D array of booleans. true means the cell is alive, false means it's dead. For example, this board:

would be represented as [[true, false, true], [false, true, false]].

  • stepBoard must return (not print) the input board advanced one step in the simulation. For example,
  • stepBoard([[true, false, true], [false, true, false]])
    should return
    [[false, true, false], [false, true, false]]
  • You may assume that all input boards will be rectangular, meaning that every row will have the same number of columns. Note that the empty board, a board with one empty row, and a board with one empty column are all valid rectangular boards. In these cases, stepBoard should simply return the inputted board.
  • The code must only use plain JavaScript: no npm modules, no NodeJS standard library modules, no browser APIs, and no frameworks or outside libraries.
  • It should not include any import/export or NodeJS require statements.
  • stepBoard must be a pure function, meaning it should cause no side effects (including mutating the input board) and always return the same output when called with the same input. If this doesn't make sense, see here for more details.
student submitted image, transcription available below  

Rules Two cells are neighbors if they're adjacent vertically, horizontally, or diagonally. All cells that aren't on the edge of the board are surrounded by exactly eight neighbors: 1 2 3 +4 6 7 5 00 8 At each iteration, we compute the next state of the board according to these three rules (paraphrased from Wikipedia): 1. Any live cell with exactly two or three live neighbors remains alive. 2. Any dead cell with exactly three live neighbors becomes a live cell. 3. All other live cells die in the next generation. Similarly, all other dead cells stay dead. We usually use white to indicate a dead cell and black to indicate a live cell.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Advanced Accounting

Authors: Gail Fayerman

1st Canadian Edition

9781118774113, 1118774116, 111803791X, 978-1118037911

More Books

Students also viewed these Programming questions

Question

a discussion of the company Amgen growth and future prospects

Answered: 1 week ago