0.0.10 • Published 4 years ago

reverjs v0.0.10

Weekly downloads
11
License
LGPL-3.0-or-later
Repository
github
Last release
4 years ago

reverjs

Implementation of a Reversi board in vanilla JavaScript.

How to Use

Install reverjs package from npm:

$ npm install reverjs --save reverjs

Create a new board with initial state:

const board = new Board();

Get a list of allowed moves for a player:

const playerOneValidMoves = board.validMoves(1);
const playerTwoValidMoves = board.validMoves(2);

Apply a move, which must be a valid move, i.e. part of the list returned by validMoves():

// set stone on the field at row 3 and column 2 for player 1
const newBoard = board.play(3, 2, 1);

// set stone on the field at row 5 and column 2 for player 2
const newBoard = board.play(5, 2, 2);

Since the board is implemented as an immutable class, a new board with all changes applied will be returned. This is especially useful for applying speculative moves, which makes implementing bots a lot easier.

Get the result to determine the outcome of the game:

const result = board.result();
console.log(result);

Sample output:

{
    playerOne: 48,
    playerTwo: 16,
    finished: true,
    tied: false,
    winner: 1,
}
0.0.10

4 years ago

0.0.9

4 years ago

0.0.8

4 years ago

0.0.7

4 years ago

0.0.6

4 years ago

0.0.5

4 years ago

0.0.4

4 years ago

0.0.3

4 years ago

0.0.2

4 years ago

0.0.1

4 years ago