reversi
v3.0.0
Published
Core logics for the Reversi
Downloads
31
Readme
reversi
Core logics for the Reversi
Playtest
Installation
npm install -g reversi
Run by CUI
You can start the Reversi game by reversi
command:
$reversi
01234567
0--------
1--------
2--------
3---ox---
4---xo---
5--------
6--------
7--------
x: 2, o: 2
> Place a "x" piece
(x,y):
If you input like this:
(x,y):3,2
It becomes such a result:
01234567
0--------
1--------
2---x----
3---xx---
4---xo---
5--------
6--------
7--------
x: 4, o: 1
> Place a "o" piece
(x,y):
Use in Node.js
Installation
npm install --save reversi
Examples
More examples can be found in here.
var reversi = require('reversi');
var Game = reversi.Game;
var PIECE_TYPES = reversi.PIECE_TYPES;
//
// Start a game
//
var game = new Game();
console.log(game.toText());
//
// 01234567
// 0--------
// 1--------
// 2--------
// 3---ox---
// 4---xo---
// 5--------
// 6--------
// 7--------
// x: 2, o: 2
// > Place a "x" piece
//
//
// Place a piece by (rowIndex, colIndex)
//
var report = game.proceed(2, 3);
console.log(game.toText());
//
// 01234567
// 0--------
// 1--------
// 2---x----
// 3---xx---
// 4---xo---
// 5--------
// 6--------
// 7--------
// x: 4, o: 1
// > Place a "o" piece
//
//
// Get more information at "proceed" execution
//
console.log(report);
//
// { pieceType: 'BLACK',
// rivalPieceType: 'WHITE',
// rowIndex: 2,
// colIndex: 3,
// isSuccess: true,
// isNextActorPassed: false }
//
//
// Get status
//
game.isEnded; // -> false
game.getHighScorer(); // -> PIECE_TYPES.BLACK
//
// Board object
//
var board = game.board;
var squares = board.squares; // -> squares[rowIndex][colIndex]
//
// Chack placable squares
//
board.isPlaceableSquare(0, 0, PIECE_TYPES.WHITE); // -> false
board.isPlaceableSquare(4, 5, PIECE_TYPES.WHITE); // -> true
board.getPlaceableSquares(PIECE_TYPES.WHITE); // -> 3 squares
board.hasPlacableSquare(PIECE_TYPES.WHITE); // -> true
//
// Get score detail
//
board.countByPieceType(); // -> { [PIECE_TYPES.BLACK]: 4, [PIECE_TYPES.WHITE]: 1, [PIECE_TYPES.BLANK]: 59 }