Catalog npm
Back to packageRELEASE DETAILS

1.0.0

npm

2048-danyo

2048 game utility

2048
Published20 Apr 2025
Direct dependencies0
Transitive dependenciesNot calculated

README

Current package documentation

2048 Game Utility

A lightweight and extensible Node.js utility for managing the core logic of the classic 2048 game. This utility includes board initialization, tile spawning, movement logic, and game-over detection - ideal for building 2048 game UIs, simulations, or reinforcement learning environments.

Installation

You can install this package using npm:

npm install 2048-danyo

Usage

Importing the Module

const Twenty48 = require('2048-danyo');

Creating a Game Instance

const game = new Twenty48();
console.log(game.board); // Prints the initial board

Spawning a tile

Spawns a tile on a random empty square

game.spawnTile(game.board, true);
console.log(game.board); // Prints the board after spawning a tile

Copying a board

Returns a deep copy of the provided board

const boardCopy = game.copyBoard(game.board);
console.log(boardCopy); // Prints the copied board

Rotating a board

Rotates a board 90 degrees counter clockwise

const rotatedBoard = game.rot90(game.board);
console.log(rotatedBoard); // Prints the rotated board

Making a move

Performs a move in the specified direction, where:

  • L is left
  • R is right
  • U is up
  • D is down
game.makeMove(game.board, 'L');
console.log(game.board) // Prints the board after moving tiles left

Checking for an empty square

One of the conditions for the game to still be playable is for it to have at least one empty square.

const hasEmptySquare = game.hasEmptySquare(game.board);
console.log(hasEmptySquare); // true or false

Checking for tiles that can be merged

One of the conditions for the game to still be playable is for it to have at least one pair of tiles that can be merged.

const hasMergableTiles = game.hasMergableTiles(game.board);
console.log(hasMergableTiles); // true or false

Checking game over status

Checks for any remaining legal moves

const isGameOver = game.gameOver(game.board);
console.log(isGameOver); // true or false

String representation of the game board

Returns a string representation of the current board. Empty cells are shown as ..

const str = game.toString();
console.log(str);

Example Output

2..2
....
....
....

License

This project is licensed under the MIT License.

Downloads & popularity

2downloads
7-day window · source-reported counts20 Oct 2026
210
2026-10-20: 2 · observed 2026-10-20T23:26:44.5635551Z
20 Oct20 Oct

npm · 1 observations shown. Missing days are unknown.

View observed values
Date / source periodValueObserved at
2026-10-2022026-10-20T23:26:44.5635551Z

Declared dependencies 0

Native requirements
0 direct targetsNot calculated transitive count
No declared dependencies in this collected response

Declarations describe requirements; they are not a resolved dependency graph.

Distribution files

1 collected
Distribution 1

Source distribution

Source file
Checksums from source
{
  "shasum": "a2af38132c03326f088a6fb62d10a3f44f7b8411",
  "tarball": "https://registry.npmjs.org/2048-danyo/-/2048-danyo-1.0.0.tgz",
  "fileCount": 4,
  "integrity": "sha512-UGd8jfEt57iJAB+XJJTzrDNkt/5p764gzUyCYFHB9fgxwm6D7WphL6mHpPH68XFp2fEQYCRAgQwbCw1T9lX+6w==",
  "signatures": [
    {
      "sig": "MEQCIFtzPbh6A4M/HGG4zPSdcPJqJ827fNiCELogEV6J1LUdAiB8fU9V8pxyjXvt96IFK7sHr2cyovwg69AW8+2arOLCYA==",
      "keyid": "SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"
    }
  ],
  "unpackedSize": 8691
}

Repository

PENDING
dhong9/2048-danyo

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:a0679e35a8372a8137e55215665c8540ffddda727f6b3ea7abaeb6cf4ea5327b

Other collected versions

1.0.120 AprView all collected versions →