fixes empty initial step and board dimensions
This commit is contained in:
@ -31,11 +31,12 @@ function evolve1d(state, rules) {
|
||||
// }
|
||||
|
||||
// performance "choke point" in full imperative
|
||||
function createBoard(state, rules, height) {
|
||||
function createBoard(state, rules, max) {
|
||||
var board = [];
|
||||
let prevState = [];
|
||||
for (let i = 0; i < height; i++) {
|
||||
for (let i = 0; i < max; i++) {
|
||||
let nextState = [];
|
||||
// use the passed initial step during first iteration
|
||||
if (i == 0) {
|
||||
nextState = evolve1d(state, rules);
|
||||
} else {
|
||||
@ -121,7 +122,7 @@ function getDrawingValues(state, acc, cell) {
|
||||
// Populates the first state with a single living cell in the center
|
||||
function create1dStateOneCell(width) {
|
||||
return [...Array(width)].map((cell, index) => {
|
||||
if (index === width / 2 || index === width + 1 / 2) return 1;
|
||||
if (index === Math.floor(width / 2)) return 1;
|
||||
return 0;
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user