1.2.5 • Published 1 year ago

@mrlhumphreys/jbackgammon v1.2.5

Weekly downloads
36
License
MIT
Repository
github
Last release
1 year ago

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.

1.2.5

1 year ago

1.2.0

2 years ago

1.2.4

2 years ago

1.2.3

2 years ago

1.2.2

2 years ago

1.2.1

2 years ago

1.1.0

3 years ago

1.0.0

4 years ago

0.4.5

4 years ago

0.4.4

5 years ago

0.4.3

5 years ago

0.4.2

5 years ago

0.4.1

5 years ago

0.4.0

5 years ago

0.3.9

5 years ago

0.3.8

5 years ago

0.3.7

5 years ago

0.3.6

5 years ago

0.3.5

5 years ago

0.3.4

5 years ago

0.3.3

5 years ago

0.3.2

5 years ago

0.3.1

5 years ago

0.3.0

5 years ago

0.2.5

5 years ago

0.2.4

5 years ago

0.2.3

5 years ago

0.2.2

5 years ago

0.2.1

5 years ago

0.2.0

5 years ago

0.1.11

5 years ago

0.1.10

5 years ago

0.1.9

5 years ago

0.1.8

5 years ago

0.1.7

5 years ago

0.1.6

5 years ago

0.1.5

5 years ago

0.1.4

5 years ago

0.1.3

5 years ago

0.1.2

5 years ago

0.1.1

5 years ago

0.1.0

5 years ago