montecalro2048 is a simple Monte Calro solver for 2048 game 2048 game.
var Board = require("montecalro2048").Board;
var board = new Board([
[ 2, 16, 8, 0],
[ 0, 64, 125, 16],
[ 32, 512, 8, 4],
[ 8, 2, 64, 16]
]);
var bestmove = board.estimate().direction // 0:UP, 1:RIGHT, 2:DOWN, 3:LEFT
Board
is a sampler of 2048 game.
-
setup
2D Array - Setup of the game. -
options
Object-
target
Integer - Target value of the game. Default is2048
. -
depth
Integer - The samling depth. Default is10
. -
sampling
Integer - The samling size for all valid moves. Default is500
.
-
The Board
class has the following methods:
Returns a estimation
.
-
estimation
Object-
direction
Integer - Estimated move(0: up, 1: right, 2: down, 3: left). -
evaluation
Integer - The evaluations of all moves.
-
A new tile will randomly appear in an empty(=0) spot on the board with a value of either 2 or 4.
-
direction
Integer - Move the board to the input direction (0: up, 1: right, 2: down, 3: left).
-
position
String - String of urrent position.
var Board = require(montecalro2048).Board;
var board = new Board([
[0, 0, 0, 0],
[0, 0, 0, 0],
[0, 0, 0, 0],
[0, 0, 0, 0]
]);
while (!board.isOvered() && !board.isCleared()) {
console.log(board.print());
console.log()
board.add();
console.log(board.print());
console.log()
board.move(board.estimate().direction);
};
console.log(board.print());
console.log()