New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

gol-engine

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

gol-engine

Game Of Life in typescript

latest
Source
npmnpm
Version
1.0.1
Version published
Maintainers
1
Created
Source

Look what we can do !

Features

You can create an instance of the object world and with it you can:

  • Produce a NxN matrix called: "map".
  • Execute all rules to all cell in the NxN matrix.
  • It store automatically the history in the object world as: world.history
  • Set initial patern in the world. (bar / gliders / etc)

How to use this ?

installation:

cd into your project and execute:

npm i gol-engine
//or with yarn
yarn add gol-engine

Classes:

World class:

This class do all the job: generate days / save history / set patterns

const {world} = require('gol-engine')
const myWorld = new world['default'](5) //The argument is the size on the matrix
Data:Desc:
mapnxn matrix of 0 or 1
historylist of nxn matrix of 0 or 1
Methods:Desc:
initWorld()This create the inital matrix (no arguments)
displayGrid()console.log the grid
getGrid()return the map data
getNeighbour(posx:number,posy:number)return the numbers of neighbour
nextDay()generate the next frame and save the previous one in the history
generateDays(time:number=10)execute nextDays() n times. Default value of n=10
bar(x:number,y:number)Spawn a bar of 3 cells at (x,y)
block(x:number,y:number)Spawn a block of 2x2 cells at (x,y)
frog(x:number,y:number)Spawn a frog @(x,y)
barFive(x:number,y:number)Spawn a bar of five cells at (x,y)
glider(x:number,y:number)Spawn a Glider at (x,y)
uClown(x:number,y:number)Spawn a Clown at (x,y)

Example:

Here is the instruction for basic usage:

  • create a file and cd into it.
  • install the package with:
npm i gol-engine
//or with yarn
yarn add gol-engine
  • create a file named "gol.js"
  • paste the following code inside "gol.js"
const {world} = require('gol-engine')
// in your favorite framework:
// import {world} from 'gol-engine'

const myWorld = new world['default'](5)

console.log('INIT..')
myWorld.initWorld()

console.log('### INITIAL MAP ###')
console.log(myWorld.map)

console.log('SET BAR @(2,2)...')
myWorld.bar(2,2)

console.log('### MAP WITH BAR ###')
console.log(myWorld.map)

console.log('GENRERATING NEXT FRAME...')
myWorld.nextDay()

console.log('### FINAL MAP ###')
console.log(myWorld.map)
  • run gol.js:
node ./gol.js
  • enjoy the logs !

Important

Remenber to init() before using the object "world".

Technical stack

  • TS
  • ESlint
  • Npm
  • Git
  • A lot of patience :p

About

Npm module made from scratch by me, for you, with <3. I used this code to do this in Vue.js with the TS template.

Hey there !
I'm letItCurl, fullstack developer engineer in freelance a.k.a Roland in real life :p
If you have any question you can contact me if you wish !

I'm always ready to help !

Email me

FAQs

Package last updated on 30 Apr 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts