Skip to content

Commit

Permalink
clean up ko and adv relation and remove dead branch - can only be con…
Browse files Browse the repository at this point in the history
…sistent if people are deliberately fiddling with internals (and should not test for that)
  • Loading branch information
clux committed Oct 3, 2014
1 parent efaef57 commit ba76fd6
Showing 1 changed file with 7 additions and 15 deletions.
22 changes: 7 additions & 15 deletions masters.js
Expand Up @@ -77,26 +77,18 @@ Masters.configure({
});

Masters.prototype._progress = function (match) {
var ko = this.knockouts[match.id.r - 1] || 0;
var ko = this.knockouts[match.id.r - 1];
if (ko) {
// if more matches to play -> progress the top not knocked out
var adv = match.p.length - ko;
var top = Base.sorted(match).slice(0, adv);
var nextM = this.findMatch(mId(match.id.r + 1));

if (!nextM || top.length !== adv) { // sanity
var str = !nextM ?
"next match not found in tournament":
"less players than expected in round " + match.id.r+1;
throw new Error("corruption at " + match.id + ": " + str);
}
// progress
nextM.p = top;
var next = this.findMatch(mId(match.id.r + 1));
next.p = top;
}
};

Masters.prototype._verify = function (match, score) {
var ko = this.knockouts[match.id.r - 1] || 0;
var ko = this.knockouts[match.id.r - 1] | 0;
var adv = match.p.length - ko;
if (ko > 0 && score[adv-1] === score[adv]) {
return "scores must unambiguous decide who is in the top " + adv;
Expand All @@ -115,9 +107,9 @@ Masters.prototype._stats = function (res, m) {
Base.resultEntry(res, s).pos = m.p.length; // tie them all
});
if (m.m) {
var ko = this.knockouts[m.id.r-1];
var adv = m.p.length - (ko || 0);
var isFinal = (ko == null);
var ko = this.knockouts[m.id.r-1] | 0;
var adv = m.p.length - ko;
var isFinal = (!ko);

// update positions
var top = $.zip(m.p, m.m).sort(Base.compareZip);
Expand Down

0 comments on commit ba76fd6

Please sign in to comment.