@ting-yu/arcade-core
v1.1.0
Published
Pure functions for 2048 game logic.
Readme
arcade-core
Pure functions for 2048 game logic.
Functions
move(board, direction): Returns the board after moving in the given direction.canMove(board, direction): Returns true if moving in that direction changes the board.hasMoves(board): Returns true if the board can move in at least one direction.spawn(board, rng): Returns a new board with a 2 or 4 added to a random empty cell.scoreGained(board, direction): Returns the points earned by merges in that move.
Install
npm install @ting-yu/arcade-coreExample
import { move } from '@ting-yu/arcade-core';
const board = [
[2, 0, 2, 0],
[0, 0, 0, 0],
[0, 0, 0, 0],
[0, 0, 0, 0]
];
const nextBoard = move(board, 'left');
console.log(nextBoard[0]); // [4, 0, 0, 0]