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 = ;
Get a list of allowed moves for a player:
const playerOneValidMoves = board;const playerTwoValidMoves = board;
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 1const newBoard = board; // set stone on the field at row 5 and column 2 for player 2const newBoard = board;
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;console;
Sample output:
{
playerOne: 48,
playerTwo: 16,
finished: true,
tied: false,
winner: 1,
}