JSPM

  • Created
  • Published
  • Downloads 824
  • Score
    100M100P100Q117042F
  • License MIT

Tournament management library

Package Exports

  • tournament

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (tournament) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

Tournament Build Status Dependency Status

Tournament is a pure library for managing the state and generating statistics for a collection of matches in a tournament. Tournaments are created up front and are mutated simply by scoring individual matches. State can be serialized/deserialized via a simple interface.

Usage

Create a new tournament instance from one of the exposed classes, then interact with helper functions to score and calculate results.

var Duel = require('tournament').Duel;
var d = new Duel(4, Duel.WB); // 4 players - single elimination

d.matches; // in playable order
[ { id: { s: 1, r: 1, m: 1 }, // semi 1
    p: [ 1, 4 ] },
  { id: { s: 1, r: 1, m: 2 }, // semi 2
    p: [ 3, 2 ] },
  { id: { s: 1, r: 2, m: 1 }, // grand final
    p: [ 0, 0 ] },
  { id: { s: 2, r: 1, m: 1 }, // bronze final
    p: [ 0, 0 ] } ]

// let's pretend we scored these individually in a more realistic manner
d.matches.forEach(function (m) {
  d.score(m.id, [1, 0]);
});

// now winners are propagated and map scores are recorded
d.matches;
[ { id: { s: 1, r: 1, m: 1 },
    p: [ 1, 4 ],
    m: [ 1, 0 ] },
  { id: { s: 1, r: 1, m: 2 },
    p: [ 3, 2 ],
    m: [ 1, 0 ] },
  { id: { s: 1, r: 2, m: 1 }, // 1 and 3 won their matches and play the final
    p: [ 1, 3 ],
    m: [ 1, 0 ] },
  { id: { s: 2, r: 1, m: 1 }, // 4 and 2 lost and play the bronze final
    p: [ 4, 2 ],
    m: [ 1, 0 ] } ]

// can view results at every stage of the tournament, here are the final ones
d.results();
[ { seed: 1, maps: 2, wins: 2, pos: 1 },
  { seed: 3, maps: 1, wins: 1, pos: 2 },
  { seed: 2, maps: 1, wins: 1, pos: 3 },
  { seed: 4, maps: 0, wins: 0, pos: 4 } ]

API

Installation

For node server usage:

$ npm install tournament --save

For the browser, bundle it up with browserify, say:

$ browserify -r tournament > bundle.js

Running tests

Install development dependencies

$ npm install

Run the tests

$ npm test

License

MIT-Licensed. See LICENSE file for details.