@siggame/tourneyjs
TypeScript icon, indicating that this package has built-in type declarations

0.3.4 • Public • Published

siggame/tourneyjs

Tournament Algorithms

Travis GitHub Tag Dependencies NPM Version NPM Total Downloads

Table Of Contents

Description

tourneyjs is a collection of different tournament algorithms along with the building blocks to create custom tournaments.

Getting Started

 npm install --save @siggame/tourneyjs

Usage

Single Elimination

import { SingleEliminationTournament } from "tourneyjs";

// create single elimination tournament without bronze finals
/**
 * SingleEliminationTournament( teams: any[], settings: Settings )
 * Settings : { bronzeFinal : boolean, randomize : boolean }
*/

const single_elim = new SingleEliminationTournament<T>([...teams]: T[]);

// add finished event listener
single_elim.when("finished", some_callback);

// add error event listener
single_elim.when("error", some_error_handler);

/**
 * Allow for asynchronous progress of the tournament.
 *
 * fight(match: Duel<T>) => Promise<IMatchResult<T>>
 *
 * IMatchResult<T> = {
 *  winner: T; losers: T[];
 * }
 *
 * success(match: Duel<T>) => void
 *
 * will have the match with updated meta_data where the
 * result is stored
 *
 * failure(match: Duel<T>, error: any) => void
 *
 * will be called for each failure, but the error event
 * listener will only execute once. the match and error
 * are parameters to the callback
*/

single_elim.play(
    async (match) => {
        // define how match winner should be decided
    }, (match) => {
        // get access to match after winner has been decided
    }, (match, error) => {
        // report or recover from error
});

single_elim.pause();
single_elim.resume();

single_elim.stop();
single_elim.resume();
// Error thrown

Contributors

Change Log

View our CHANGELOG.md

License

View our LICENSE

Contributing

View our CONTRIBUTING.md

Package Sidebar

Install

npm i @siggame/tourneyjs

Weekly Downloads

5

Version

0.3.4

License

MIT

Unpacked Size

21.5 kB

Total Files

19

Last publish

Collaborators

  • user404d