Skip to content

mrlhumphreys/jbackgammon

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

44 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

JBackgammon

A backgammon game state and validation library written in Javascript.

Installation

Install via npm:

$ npm install @mrlhumphreys/jbackgammon

Usage

ES5:

  var Match = require('@mrlhumphreys/jbackgammon').Match;

ES6:

  import { Match } from '@mrlhumphreys/jbackgammon'

Initialize a new match object:

  var match = new Match({
    id: 1,
    game_state: {
      bar: {
        pieces: []
      },
      current_player_number: 1,
      current_phase: 'move',
      dice: [
        { number: null },
        { number: null }
      ],
      off_board: {
        pieces: []
      }
      points: [
        { number: 1, pieces: [ { player_number: 1 }, { player_number: 1 } ] },
        { number: 2, pieces: [ ] },
        ...
      ]
    },
    players: [
      { player_number: 1, name: 'aaa' },
      { player_number: 2, name: 'bbb' }
    ],
    winner: null
  });

Serialize match

  match.asJson;

See if player can pass

  playerNumber = 1;
  match.passable(playerNumber); 

Roll Dice

  playerNumber = 1;
  match.touchDice(playerNumber);

Make a move

  match.touchPoint(4, 1); // select point 4 for player 1
  match.touchPoint(6, 1); // select point 6 for player 1

Pass turn

  playerNumber = 1;
  match.touchPass(playerNumber);

Get winner

  match.winner;

Development

After checkout out the repo, run npm install to install dependencies. Run npm build to transpile ES6 to ES5 into the lib directory. Run npm test to run the tests.

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/mrlhumphreys/jbackgammon. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the Contributor Covenant code of conduct.

License

The module is available as open source under the terms of the MIT License.

About

Backgammon game state and move validation.

Resources

Stars

Watchers

Forks

Packages

No packages published