Would you like to clone this notebook?

When you clone a notebook you are able to make changes without affecting the original notebook.

Cancel

Conway's game of life using @monarchwadia/conways-game-engine (expand the log output!)

node v10.24.1
version: 1.0.2
endpointsharetweet
const { ConwaysGameEngine } = require("@monarchwadia/conways-game-engine") /** / Expand the console output! Youll have \ | to press the little arrow to the left | | of each log. A bit tedious. But trust | \ me, its worth it! / --------------------------------------- \ ^__^ \ (oo)\_______ (__)\ )\/\ ||----w | || || */ const FONT = { [1]: "# ", [0]: ". ", default: "? " } // init engine const engine = new ConwaysGameEngine(); /* Draw a glider . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . # . . . . . . . . . . # . . . . . . . # # # . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */ engine.draw(3, 4); engine.draw(4, 5); engine.draw(5, 5); engine.draw(5, 4); engine.draw(5, 3); renderer(engine); // CALCULATE for (var i = 0; i < 10; i++) { engine.step(); renderer(engine); } // Other stuff function renderer(engine) { const { world, config } = engine; const { rowSize, colSize } = config; let string = ''; for (let row = 0; row < rowSize; row++) { for (let col = 0; col < colSize; col++) { const value = world[row][col]; const font = FONT[value] || FONT.default; string += font; } string += '\r\n'; } // render console.log(string); }
Loading…

no comments

    sign in to comment