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 🙏

© 2026 – Pkg Stats / Ryan Hefner

@jialisheng/arcade-core

v0.1.2

Published

Core game logic for a 2048 arcade game

Readme

@jialisheng/arcade-core

A lightweight JavaScript package that provides the core game logic for the 2048 game.

Description

This package exports five functions: move(), spawn(), canMove(), hasMoves(), and moveWithScore(). These functions handle tile movement, merging, random tile generation, move validation, and score calculation.

The package is independent of UI frameworks and can run in a Node.js environment.

Installation

Install the package using npm:

npm install @jialisheng/arcade-core

Usage

import { move, spawn, canMove, hasMoves } from "@jialisheng/arcade-core";

const board = [
    [2, 0, 2, 4],
    [0, 4, 4, 0],
    [2, 2, 2, 2],
    [0, 0, 0, 0]
];

const newBoard = move(board, "left");

console.log(newBoard);

Expected output:

[
    [4, 4, 0, 0],
    [8, 0, 0, 0],
    [4, 4, 0, 0],
    [0, 0, 0, 0]
]

API Reference

move(board, direction)

Slides and merges tiles on the board in the specified direction. It returns a new board without modifying the original board.

This function does not spawn a new tile; use spawn() separately after a valid move.

The direction parameter accepts four possible values: "left", "right", "up", and "down".

spawn(board, rng)

Randomly selects an empty cell and generates a new tile with a value of either 2 or 4. There is a 90% probability of generating a 2 and a 10% probability of generating a 4.

It returns a new board without modifying the original board.

The rng parameter is optional and defaults to Math.random. It must be a function that returns a number between 0 (inclusive) and 1 (exclusive).

If no empty cells are available, the function returns a new board with the same contents.

canMove(board, direction)

Checks whether moving the tiles in the specified direction would change the board.

It returns true if the move is possible and false otherwise.

hasMoves(board)

Checks whether at least one valid move remains in any of the four directions.

It returns true if a valid move exists and false if no moves are possible.

moveWithScore(board, direction)

Slides and merges tiles in the specified direction and calculates the score earned from merging tiles.

It returns a new board without modifying the original board. Like move(), this function does not spawn a new tile.

Parameters:

  • board: A two-dimensional array representing the game board.
  • direction: One of "left", "right", "up", or "down".

Returns:

An object containing:

  • board: The updated board after the move.
  • score: The points earned from merges during this move.

Example:

import { moveWithScore } from "@jialisheng/arcade-core";

const board = [
    [2, 2, 0, 0],
    [4, 4, 0, 0],
    [0, 0, 0, 0],
    [0, 0, 0, 0]
];

const result = moveWithScore(board, "left");

console.log(result.board);
// [
//     [4, 0, 0, 0],
//     [8, 0, 0, 0],
//     [0, 0, 0, 0],
//     [0, 0, 0, 0]
// ]

console.log(result.score); // 12

Testing

Run the unit tests using Node.js:

npm test

The unit tests cover directional movement, tile merging, move validation, and edge cases. They also verify that the original board is not modified by movement operations.

Version Information

The package is published on npm as @jialisheng/arcade-core.

The current published version used by the Arcade application is 0.1.1.

See CHANGELOG.md for version history.

Related Project

This package is used by Jiali Sheng's Arcade, a Svelte 5 application featuring 2048 and a mini crossword puzzle.

Live Website: Jiali Sheng's Arcade

Author

Jiali Sheng

CS5610 — Web Development, Fall 2026

Northeastern University