Catalog npm
PACKAGE EXPLORERView in registry

2048-ts-engine

npm

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

2048enginegametypescript
Versions collected19
Direct dependencies5From release 1.4.5
Last observed20 Oct, 18:55 UTC

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.

Versions 19

Collected releases
VersionPublishedDirect dependenciesOpen version
1.4.5Registry latest3 Apr 20225
1.4.43 Apr 20223
1.4.33 Apr 20223
1.4.23 Apr 20223
1.4.13 Apr 20223
1.4.03 Apr 20223
1.3.23 Apr 20223
1.3.13 Apr 20223
1.3.03 Apr 20223
1.2.63 Apr 20223
1.1.61 May 20213
1.1.51 May 20213
1.1.41 May 20213
1.1.31 May 20213
1.1.21 May 20213
1.1.11 May 20213
1.1.01 May 20213
1.0.112 Mar 20210
1.0.012 Mar 20210

Package advisories

0
No matching advisories collected

This describes our collected data; it is not a security assessment.

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:0754772dcd74b577422deeef10acb85f53f8ff566f79c03864081dba9375ccd2