@melodie_05/arcade-core
v1.0.2
Published
2048 game logic
Readme
Arcade Core
A JavaScript game logic package for the 2048 game, played on a 4×4 grid.
Installation
You can install this package via npm:
npm install @melodie_05/arcade-coreUsage
Import the functions you need:
import { move, spawn, hasMoves, canMove } from "@melodie_05/arcade-core";API Reference
move(board, direction)
Takes a 4x4 board array and a direction ('UP', 'DOWN', 'LEFT', 'RIGHT'). Slides every tile as far as it can go, merges equal neighbors once, and returns a completely new board.
spawn(board, rng?)
Puts a new 2 or 4 in a random empty cell and returns the new board.
Parameters :rng (Math.random), a random number generator function. If omitted, the function uses its default random source. A new tile is 2 with 90% probability or 4 with 10% probability.
hasMoves(board)
Checks whether the game has any legal moves remaining. Returns true if any direction would still change the board, and false when the game is over.
canMove(board, direction)
Checks whether the board can change when moving in the specified direction.
Returns true if the move changes the board, or false otherwise.
Changelog
See CHANGELOG.md for version history and release notes.
