Generic Game Board
Via npm on Node:
npm install simpleboard
Reference in your program:
var simpleboard = require('simpleboard');Create a board:
var board = simpleboard.createBoard(with, height);Put a content in a cell
board.putContent(x, y, content);The content is a game-dependent value/object.
Get the content of a cell
board.getContent(x, y);If the cell is empty, the returned content is null.
Remove the content from a cell
board.removeContent(x, y);Get an array with the board positions
var positions = board.getPositions();Each position is an object with properties x, y and content.
Find a position that satifies a predicate
var position = board.findPosition(function (pos) { return pos.color == 2 });Find all the positions that satify a predicate
var position = board.findPositions(function (pos) { return pos.piece == 'bishop' });Clone a board
var clone = board.clone();This method is useful when you must explore a tree in a game: you can clone the current position before a new move.
git clone git://github.com/ajlopez/SimpleBoard.git
cd SimpleBoard
npm install
npm test
TBD
- Samples
- 0.0.1: Published
Feel free to file issues and submit pull requests — contributions are welcome.
If you submit a pull request, please be sure to add or update corresponding
test cases, and ensure that npm test continues to pass.