A middle stage tournament that deals with unexpected ties
TieBreaker deals within groups ties in tournaments that has group-like equivalents. Such tournaments include:
TieBreaker will break ties for any tournament that implements
rawPositions, a special method that converts results into a raw array of positions per "group".
Unlike every other tournament type, this tournament CAN NOT be created directly. It needs a finished tournament instance to be created from, and the number of players we want to pick from this tournament:
var gs = 8 groupSize: 4 ;// score groupstage so that we have some tiesgsmatchesforEachif mids === 1gsscoremid i === 2 ? 10 : 1 1;if mids === 2gsscoremid 4indexOfmidr >= 0 ? 1 0 : 0 1;;gsisDone; // true
In this case the group stage is tied in the following ways:
Then, we may create tiebreakers in one of two ways, the simplest creates an
FFA style match for each group where we need to break it up:
var tb = TieBreakerfromgs 4; // want the top 4tbmatches;id: s: 1 r: 1 m: 1 // group 1 tiebreakerp: 3 8id: s: 2 r: 1 m: 1 // group 2 tiebreakerp: 4 5 7tbscoretbmatches0id 21;tbscoretbmatches1id 321;var top4 = tbresultsslice0 4; // will contain results for 1,3,4,5
The more advanced creates mini groupstages for each group involving the tied players:
var tb = TieBreakerfromgs 4 grouped: true ;tbmatches;id: s: 1 r: 1 m: 1 p: 3 8// group 2 tiebreaker subgroupid: s: 2 r: 1 m: 1 p: 5 7id: s: 2 r: 2 m: 1 p: 4 7id: s: 2 r: 3 m: 1 p: 4 5
tb.matches is a non-empty array, there were ties that meant isolating the top 4 was impossible. Depending on how many players we request to forward (in this case 4),
TieBreaker may need more or fewer matches played.
At the end of the
TieBreaker tournament, you can call results and get the newly positioned results array. However, unless you were creating the tournament in
strict mode, the ties may not have been broken fully.
tbmatchesforEach// tie all the tiebreaker matches in group 2 (continuing grouped example)tbscoremid mids === 2 ? 11 : 21;;tbisDone; // trueTieBreakerisNecessarytb 4; // true
In this case we would need to recreate the
TieBreaker from the previous instance. Until the conflict has been resolved, you will need to keep doing this:
// recreate tiebreaker from partially broken/unbroken tiebreaker instancevar tb2 = TieBreakerfromtb 4;tb2matches;id: s: 2 r: 1 m: 1 p: 5 7id: s: 2 r: 2 m: 1 p: 4 7id: s: 2 r: 3 m: 1 p: 4 5
Repeating this procedure will eventually lead to a tiebreaker result where
!TieBreaker.isNecessary(prevTb, 4). In this case you can pick out the top 4 by slicing the results, or simply using
.from on your next tournament.
tb2isDone; // trueTieBreakerisNecessarytb2 4; // false - assume we unbroke group 2 in tb2var top4 = tb2resultsslice0 4; // results for top 4// send the top 4 players from the groupstage to a two-round duel tournamentvar duel = Duelfromtb2 4;
Without going into detail, it is fairly easy to end up in a situation where you have many different multi-way ties. The following is a
GroupStage test case:
If we get the results from
GroupStage, it will say that
[1,2,5,6] are all 1st placers, and thus tie all these four
results[i].pos attributes at
If we wanted the top 4 to proceed to a different tournament we would end up picking three players from group 1 and one player from group 2.
While this seems terrible,
GroupStage have nonetheless computed the results to the best of its knowledge.
By specifying the number of players you want to extract,
TieBreaker can create matches needed to forward the top
n players ((some restrictions apply)[#limitations]) to another tournament fairly. See example below for a detailed explanation.
Using the ties outlined above, if we:
Then need to break:
That gives 3 out of the 4 to proceed, and the last is player 5 who won his group alone and is guaranteed through.
Then only need to break the 1st place cluster in group 1, because we know 5 is one of the top 2.
Only need to break the 2nd place cluster from group 2, because we know [1,2,6] are all in the top 6.
Results out from a
TieBreaker instance are identical to the results received from the tournament we are breaking. The only difference is that we modify the
pos attributes in two ways:
n(fairly) by simply filtering by
r.pos <= n, or by calling
gposattributes are modified
posattributes are at the end built up like
TieBreaker only allows a multiple of the number of groups/sections to be chosen, lest unfair inferences about positions between groups is needed to be made. Some help with this is under development.
While TieBreaker implements
from slightly differently than any other tournament, is still a perfectly valid tournament. All the methods available on the tournament base class exist on
TieBreaker. Read the tournament API
MIT-Licensed. See LICENSE file for details.