Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/kjirou/reversi
Core logics for the Reversi
https://github.com/kjirou/reversi
Last synced: 12 days ago
JSON representation
Core logics for the Reversi
- Host: GitHub
- URL: https://github.com/kjirou/reversi
- Owner: kjirou
- Created: 2015-12-15T09:59:34.000Z (almost 9 years ago)
- Default Branch: master
- Last Pushed: 2021-08-31T07:40:15.000Z (about 3 years ago)
- Last Synced: 2024-04-23T19:37:53.324Z (7 months ago)
- Language: JavaScript
- Homepage:
- Size: 69.3 KB
- Stars: 4
- Watchers: 3
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# reversi
[![npm version](https://badge.fury.io/js/reversi.svg)](http://badge.fury.io/js/reversi)
[![Build Status](https://travis-ci.org/kjirou/reversi.svg?branch=master)](https://travis-ci.org/kjirou/reversi)Core logics for the [Reversi](https://en.wikipedia.org/wiki/Reversi)
![](https://raw.githubusercontent.com/kjirou/reversi/master/doc/demo.gif)
## Playtest
### Installation
```bash
npm install -g reversi
```### Run by CUI
You can start the Reversi game by `reversi` command:
```bash
$reversi01234567
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
```bash
npm install --save reversi
```### Examples
More examples can be found in [here](examples).
```js
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 }
```