npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

gol-engine

v1.0.1

Published

Game Of Life in typescript

Downloads

4

Readme

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: | | :--- | :---: | | map | nxn matrix of 0 or 1 | | history | list 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.