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

@spicehandler/arcade-core

v1.1.1

Published

Business logic for 2048 game

Readme

@spicehandler/jeremyspicehandler_cs5610_arcade_core

Game logic for 2048, written as pure JavaScript functions. No dependencies, no DOM, and no framework, so it runs in Node or the browser.

Install

npm install @spicehandler/arcade-core

## Usage

```js
import { move, spawn, canMove, hasMoves } from '@jeremyspicehandler_cs5610_arcade_core';

let board = [
	[2, 2, 0, 0],
	[0, 0, 0, 0],
	[0, 0, 0, 0],
	[0, 0, 0, 0]
];

if (canMove(board, 'left')) {
	board = move(board, 'left');   // first row becomes [4, 0, 0, 0]
	board = spawn(board);          // adds a 2 or 4 to a random empty cell
}

if (!hasMoves(board)) {
	console.log('Game over');
}

The board

A board is a 4×4 array of arrays of numbers. 0 means an empty cell.

All functions are pure: they never change the board you pass in, and always return a new board instead.

API

move(board, direction)

Slides every tile as far as it can go in direction ('up', 'down', 'left', or 'right'), merging equal neighbors once each. Returns the new board. If nothing can move, the returned board matches the original.

moveScore(board, direction)

Returns the points earned by moving in direction: the total value of every tile created by a merge. For example, two 8s merging into a 16 earns 16 points. Returns 0 if nothing merges or the direction is unrecognized. Call it with the board before the move.

spawn(board, rng = Math.random)

Places a new tile in a random empty cell: a 2 (90% of the time) or a 4 (10%). Returns the new board, or the board unchanged if there are no empty cells. rng is an optional function returning a number from 0 up to (but not including) 1, useful for testing or seeded games.

canMove(board, direction)

Returns true if moving in direction would change the board, otherwise false.

hasMoves(board)

Returns true if any direction would change the board, and false when the game is over.

License

MIT