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

gameoflifebuilder

v1.0.0

Published

This is a Javascript with TypeScript support library that implements Conway's Game of Life. It allows users to create a game instance, set initial states of cells, and iterate through generations.

Downloads

6

Readme

Game of Life Builder Library

https://img.shields.io/badge/License-MIT-yellow.svg

https://img.shields.io/badge/JavaScript-ES6-yellow.svg

https://img.shields.io/badge/TypeScript-Ready-blue.svg

This is a TypeScript library for creating and simulating Conway's Game of Life.

Installation

To install this library, simply run the following command:

npm install game-of-life-builder

Usage

To use the library, first, import it into your TypeScript file:

import { GameOfLifeBuilder } from 'game-of-life-library';

You can then use the GameOfLifeBuilder class to build a Game of Life instance.

const initialGeneration = [
  [false, true, false],
  [false, true, false],
  [false, true, false],
];

const builder = new GameOfLifeBuilder();
const game = builder
  .withInitialGeneration(initialGeneration)
  .setAsClassicGameOfLife(3, 3)
  .build();

// run the game for 10 iterations
for (let i = 0; i < 10; i++) {
  game.nextGeneration();
}

API

The GameOfLifeBuilder class provides the following methods:

withInitialGeneration(initialGeneration: boolean[][]): GameOfLifeBuilder

This function sets the initial generation of a Game of Life instance.

  • initialGeneration: A two-dimensional boolean array representing the initial state of the cells in the Game of Life. Each element in the array represents a cell, and its value indicates whether the cell is alive (true) or dead (false). The dimensions of the array determine the size of the game board.
  • Returns: The method withInitialGeneration returns an instance of GameOfLifeBuilder.

withRules(rules: IGameRules): GameOfLifeBuilder

This function sets the rules for the Game of Life and returns a GameOfLifeBuilder object.

  • rules: An object that defines the rules for a game of life simulation.
  • Returns: The method withRules returns a GameOfLifeBuilder object.

setAsClassicGameOfLife(width: number, height: number): GameOfLifeBuilder

This function sets the game type as Classic Game of Life and returns a GameOfLifeBuilder object.

  • width: The width of the game board/grid in the Classic Game of Life.
  • height: The number of rows in the game grid.
  • Returns: The method setAsClassicGameOfLife returns an instance of GameOfLifeBuilder.

build(): GameOfLifeBase

This function initializes a Game of Life instance and returns it.

  • Returns: An instance of the GameOfLifeBase class after initializing it with the Init() method of the Game object.

Helper Function

The library also provides a helper function CreateBooleanArray to create a 2D boolean array.

CreateBooleanArray(x: number, y: number): boolean[][]

This function creates a 2D boolean array with a specified number of rows and columns.

  • x: The number of rows in the boolean array.
  • y: The number of columns in the 2D boolean array that will be created by the CreateBooleanArray function.
  • Returns: A 2-dimensional boolean array with x rows and y columns, where all values are initialized to false.

Examples

To see more examples of how to use this library, please refer to the Samples folder in the repository.

License

This library is licensed under the MIT License. See the LICENSE file for more information.

Support

If you find useful, consider supporting the project by making a donation via PayPal:

Support in Paypal ♥️