Observed since 20 Oct, 18:55 UTC
No superseded metadata states collected. Unchanged observations do not create new revisions.
Game engine for 2048 game
Handles logic for 2048 game.
Originally based on 2048-ts-engine by Karel Nguyen, but has now been completely rewritten to support additional features.
import { createGame, Direction } from '2048-engine';
const game = createGame();
game.move(Direction.UP);
game.move(Direction.RIGHT);
console.log(game);
might print:
{
currentState: {
board: [
[ null, null, { value: 2, id: 0 }, { value: 4, id: 1 } ],
[ null, null, null, { value: 4, id: 2 } ],
[ null, null, { value: 4, id: 3 }, null ],
[ null, null, null, null ]
],
score: 0,
rngNumber: 455431,
totalTileCount: 4,
status: { hasPossibleMoves: true, isWon: false }
},
boardMeta: { rows: 4, cols: 4 },
randomSeed: 455423,
moveLog: [ { type: 0, direction: 0 }, { type: 0, direction: 3 } ],
move: [Function: move]
}
createGameThe package exposes one method createGame that creates a new game.
createGame(gameData?) => Game
Can be supplied with GameData to initialize the game with.
GameThe created game object contains the following properties:
currentState: The current state of the game. (see GameState)move: Function to make a move in the game. Takes a Direction as an argument and returns an updated GameState in addition to updating game.currentStateboardMeta: Metadata about the board. Contains rows and cols properties, which are the number of rows and columns in the board.randomSeed: The random seed used to create the game. A new game created with the same random seed will be exactly the same given the same moves.moveLog: List of all moves made in the game. Each move is a Move object.GameDataGameData is a subset of Game containing all properties except currentState and move. A new game created with the same GameData as an existing game will be exactly the same.
GameStateThe gameState contained within Game contains the following properties:
board: The board state. A 2D array of Tile-objects.score: The current score of the game.status: object containing booleans isWon and hasPossibleMoves describing current game status.TileEach tile object contains an id, and its current value. The tile might also contain a mergedId specifying the id of the tile it was most recently merged with.
id: id to identify the tile, unique per game.value: The value of the tile.mergedId: The id of the tile it was most recently merged with. (useful for animations)Download counts and popularity will appear here as the collector receives them.
This describes our collected data; it is not a security assessment.
Observed since 20 Oct, 18:55 UTC
No superseded metadata states collected. Unchanged observations do not create new revisions.
package:ff7c44a5579a0a79df92adcc1c06542bc1093ca214dbf2ff7f37acad4f64c9d7