Skip to content

Latest commit

 

History

History
71 lines (51 loc) · 2.49 KB

api.md

File metadata and controls

71 lines (51 loc) · 2.49 KB

Duel

A duel tournament is an implementation of the abstract Tournament interface. This document will contain the main methods and helpers exposed by duel, but not the ones implemented in Tournament. The main API, which covers most standard tournament management is covered in the tournament API.

Duel Class

Let Duel = require('duel'). A Duel tournament can be created directly via this:

Duel(numPlayers, opts) :: duel

Returns a Duel instance.

var duelSingle = Duel(8, { last: Duel.WB }); // 8p Single elimination with bronze final
var duelDouble = Duel(16, { last: Duel.LB, short: true }) // 16p Double elimination with a single grand final

Options

Constructor options are

{
  last: Type, // Either Duel.LB or Duel.WB for the last bracket in use
  short: Boolean // Whether to skip bronze final in single elimintation or potential double final in double elimination
}

Enumerable Properties

Enumerable properties of the instance are NOT considered part of the API unless explicitly stated herein.

Duel Statics

Duel.attachNames(fn) :: MonkeyPatch

This will create a roundName method on Duel. For example usage see duel-names.

Duel Methods

duel.right(id) :: [rightId, index]

Given a match Id, produce the match and position to advance winner rightwards to in the current bracket.

var id = duel.matches[0].id; // { s: 1, r: 1, m: 1 }
duel.right(id); // [ { s: 1, r: 2, m: 1}, 0 ]

Here, the winner of WB R1 M1 will move to index 0 in the player array for WB R2 M1.

duel.down(id) :: [downId, index]

Given a match Id, produce the match and position to advance loser downwards to in the bracket below.

var id = duel.matches[1].id; // { s: 1, r: 1, m: 2 }
duel.down(id); // [ { s: 2, r: 1, m: 1 }, 1 ]

Here, the loser of WB R1 M1 will drop down to index 1 in the player array for LB R1 M2.

Duel Constants

Duel.WB :: 1

Duel.LB :: 2

Bracket types are either Duel.WB, or Duel.LB. These are valued as 1 and 2 respectively, after their bracket numbers in the match id.

Duel.WO :: -1

This is found in certain player arrays in matches when numPlayers is not a perfect power of two. These only occur in WBR1, LBR1 or LBR2.

Id Class

The match ids generated by Duel are just thin wrappers around the normal match ids, but with a string representation:

duel.matches[0]; // { s: 1, r: 1, m: 1 }
duel.matches[0].toString(); // WB R1 M1