Question
*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
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.
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
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started