2.0.0 • Published 12 months ago
game2048engine v2.0.0
Game 2048 engine
The current engine can handle a NxN (N > 2) field with the numbers 0,2,4,8,16,...,2^M (M < 53).
Field input format example: [ 0,2,0,4, 4,0,0,0, 0,0,0,0, 8,0,16,16, ]
To make a move, you need to send one of the four directions U, D, L or R.
Move input format example: "L" Moves input format example: "L", "R", "U", "U", "D"
Move processing example: 0, 4, 4, 4 "L" -> 8, 4, 0, 0
As a result of the engines processing, the passed field will be changed according to the passed moves.
Typical use case:
import {createEngine} from 'game2048engine'
...
const field = [
[0,2,0,4],
[4,0,0,0],
[0,0,0,0],
[8,0,16,16],
]
const engine4x4 = createEngine(4);
while(true) {
const move = readInput();
engine4x4.safeApplyMove(field, move); // or just call engine4x4.applyMove(field, move) if we want to avoid arguments validation
addMoreValues(field);
updateDisplay(field);
}
...
2.0.0
12 months ago