duel.js
function (size, p, last, isLong) {
  var matches = [];
  // first WB round to initialize players
  for (var i = 1; i <= Math.pow(2, p - 1); i += 1) {
    matches.push({ id: gId(WB, 1, i), p: woMark(seeds(i, p), size) });
  }

 // blank WB rounds
  var r, g;
  for (r = 2; r <= p; r += 1) {
    for (g = 1; g <= Math.pow(2, p - r); g += 1) {
      matches.push({id: gId(WB, r, g), p: blank() });
    }
  }

  // blank LB rounds
  if (last >= LB) {
    for (r = 1; r <= 2*p - 2; r += 1) {
      // number of matches halves every odd round in losers bracket
      for (g = 1; g <= Math.pow(2, p - 1 - Math.floor((r + 1) / 2)); g += 1) {
        matches.push({ id: gId(LB, r, g), p: blank() });
      }
    }
    matches.push({ id: gId(LB, 2*p - 1, 1), p: blank() }); // grand final match 1
  }
  if (isLong) {
    // bronze final if last === WB, else grand final match 2
    matches.push({ id: gId(LB, last === LB ? 2*p : 1, 1), p: blank() });
  }
  return matches.sort(Base.compareMatches); // sort so they can be scored in order
}
function (size, p, last, isLong) {
  var matches = [];
  // first WB round to initialize players
  for (var i = 1; i <= Math.pow(2, p - 1); i += 1) {
    matches.push({ id: gId(WB, 1, i), p: woMark(seeds(i, p), size) });
  }

 // blank WB rounds
  var r, g;
  for (r = 2; r <= p; r += 1) {
    for (g = 1; g <= Math.pow(2, p - r); g += 1) {
      matches.push({id: gId(WB, r, g), p: blank() });
    }
  }

  // blank LB rounds
  if (last >= LB) {
    for (r = 1; r <= 2*p - 2; r += 1) {
      // number of matches halves every odd round in losers bracket
      for (g = 1; g <= Math.pow(2, p - 1 - Math.floor((r + 1) / 2)); g += 1) {
        matches.push({ id: gId(LB, r, g), p: blank() });
      }
    }
    matches.push({ id: gId(LB, 2*p - 1, 1), p: blank() }); // grand final match 1
  }
  if (isLong) {
    // bronze final if last === WB, else grand final match 2
    matches.push({ id: gId(LB, last === LB ? 2*p : 1, 1), p: blank() });
  }
  return matches.sort(Base.compareMatches); // sort so they can be scored in order
}
function ( size , p , last , isLong ) { var matches = [ ] ; // first WB round to initialize players for ( var i = 1 ; i <= Math . pow ( 2 , p - 1 ) ; i += 1 ) { matches . push ( { id : gId ( WB , 1 , i ) , p : woMark ( seeds ( i , p ) , size ) } ) ; } // blank WB rounds var r , g ; for ( r = 2 ; r <= p ; r += 1 ) { for ( g = 1 ; g <= Math . pow ( 2 , p - r ) ; g += 1 ) { matches . push ( { id : gId ( WB , r , g ) , p : blank ( ) } ) ; } } // blank LB rounds if ( last >= LB ) { for ( r = 1 ; r <= 2 * p - 2 ; r += 1 ) { // number of matches halves every odd round in losers bracket for ( g = 1 ; g <= Math . pow ( 2 , p - 1 - Math . floor ( ( r + 1 ) / 2 ) ) ; g += 1 ) { matches . push ( { id : gId ( LB , r , g ) , p : blank ( ) } ) ; } } matches . push ( { id : gId ( LB , 2 * p - 1 , 1 ) , p : blank ( ) } ) ; // grand final match 1 } if ( isLong ) { // bronze final if last === WB, else grand final match 2 matches . push ( { id : gId ( LB , last === LB ? 2 * p : 1 , 1 ) , p : blank ( ) } ) ; } return matches . sort ( Base . compareMatches ) ; // sort so they can be scored in order }
make ALL matches for a Duel elimination tournament
make ALL matches for a Duel elimination tournament