Catalog npm
Back to packageRELEASE DETAILS

1.4.2

npm

2048-ts-engine

`2048-ts-engine` is a typescript based app that handles logic for 2048 game. You can also use plain JS, if Typescript is not needed.

2048enginegametypescript
Published3 Apr 2022
Direct dependencies3
Transitive dependenciesNot calculated

README

Current package documentation

Getting Started 🚀

2048-ts-engine handles logic for 2048 game. Despite being written in Typescript, you can also use plain JS, if TS is not needed.

Installation

yarn add 2048-ts-engine

How to use

  • The lib returns two main functions
    • startGame - simply starting the game
    • move
      • evaluating move, calculating points, board coordination etc,
      • accepts these parameters
    direction: Direction
    game: Game
    

Both these functions return all game related data (board coordinates, score, status etc.) which look like this:

{
  "score": 16,
  "board": [
    [ 0, 0, 4, 0 ],
    [ 0, 0, 0, 0 ],
    [ 2, 0, 0, 0 ],
    [ 4, 8, 0, 8 ]
  ],
  "gameStatus": "STARTED"
}

You will need to store the current state somewhere, since the engine only processes the game, and after every move, the current state of game is returned.

import { startGame, move } from '2048-ts-engine';
import { Direction, Game, GameStatus } from '2048-ts-engine/src/types';

const newGame = startGame();
const gameProcessed = move(Direction.UP, newGame);

Useful scripts

  # test game logic
  yarn test

Downloads & popularity

Awaiting observations

No metric observations yet

Download counts and popularity will appear here as the collector receives them.

Declared dependencies 3

Native requirements
3 direct targetsNot calculated transitive count
Package / targetRequirementRelationship
@types/jest
Environment
{
  "local_name": "@types/jest",
  "alias": false,
  "peer_metadata": null
}
^26.0.23development
jest
Environment
{
  "local_name": "jest",
  "alias": false,
  "peer_metadata": null
}
^26.6.3development
typescript
Environment
{
  "local_name": "typescript",
  "alias": false,
  "peer_metadata": null
}
^4.2.4development

Distribution files

1 collected
Distribution 1

Source distribution

Source file
Checksums from source
{
  "integrity": "sha512-Z5cn/jG4sQWniq/TBasMzCQr8cZhOTy9T8qxSA58q2okcElab+mRt4LWZwM6Tmgvd1n0Aqkz/QGNDj5ntFOTPg==",
  "shasum": "e84356a0d4537b8dd831681f9345dbe098e3f16f",
  "tarball": "https://registry.npmjs.org/2048-ts-engine/-/2048-ts-engine-1.4.2.tgz",
  "fileCount": 46,
  "unpackedSize": 42771,
  "signatures": [
    {
      "keyid": "SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA",
      "sig": "MEQCIGxjlMhZwavPZLoGeiPv/HXIwXQ0/OQbA+ob38EWqhx0AiB3/9U1nUgLXNsZlaAhSxM0oaZUqXs2jEFFdeCedb3tBg=="
    }
  ],
  "npm-signature": "-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJiScvgACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2VmpdFA//ZGEPZzx6Z5ZF3wScGGW1+DcPkFb4V3/oiauOyYFMTbcR4PUU\r\nStRXoMA/YGhx6Obg+ahZtiKaturqf0tHpplV78uWuOxV1EEMwkEK6dK0Cm8c\r\nzgI0He8EK1yQA1S3Z+7Z/ooL2Jibvy309e4MdidH8MM1Lar90VHIwppN5Vi0\r\nXp0gsv51NKSbbOq05/yOrEpgMtEx10m+VUZD64jM0+j1ZmMa9D1gPUY2E6jM\r\nk2oaH2zA55M6IPYfRmZR9mU8RGipuBah4sLWhwdL5e3+qDv77vcRZHLfacMS\r\nVSQq4TKJ6H6p5n0D3M1enm928fN2MCtI9DvK40JQpotiJ/HEZtf17PVdCYEm\r\nmSpYLDXYyXXwRADaLaVL+AgsD6nXsKkZexUkhgxzaJRir2C5FoTuaNYlRneS\r\nutJmWEWmBBdoJiA7WqTn8VgbCkJ9KICC/ay4tRqkKbA/K6dHpLAyfifHqIAN\r\nt3QcM0xNUn1X87Wirh7RBP9J6XSYzdzklIVVvqvYh0uvjjR58KaYRiBimMnn\r\nUuxUB49Zy8AsQDs7Qf1RaH06XduJ/TAFbBi8hyHSB1EcRGACw4i70lUuthTa\r\nOBtdXqwxJT+eqS/tKjy944MFW22YiVVoMgUTFz5F+KlSMTwMg4l2aw9Qmvoj\r\nkCmpFeytyP0zGqCicXTgAAxtx/v/Xlpjn4o=\r\n=ZhxP\r\n-----END PGP SIGNATURE-----\r\n"
}

Repository

PENDING
karelnguyen/2048-ts-engine

Shared repository data · GitHub

License detected in repository
Not collected

Metadata history

Meaningful changes
Current collected state Current

Observed since 20 Oct, 18:55 UTC

No superseded metadata states collected. Unchanged observations do not create new revisions.

Record identity

package_version:a50c25cb706069a0fc035c6183f82655da665eb6b4d3cf54d18a7a98d7e0891e

Other collected versions

1.4.53 Apr1.4.43 Apr1.4.33 Apr1.4.13 Apr1.4.03 Apr1.3.23 AprView all collected versions →