duel.js
function (id) {
  var b = id.s
    , r = id.r
    , g = id.m
    , p = this.p;

  // knockouts / special finals
  if (b >= this.last) { // greater than case is for BF in long single elimination
    if (b === WB && this.isLong && r === p - 1) {
      // if bronze final, move loser to "LBR1" at mirror pos of WBGF
      return [gId(LB, 1, 1), (g + 1) % 2];
    }
    if (b === LB && r === 2*p - 1 && this.isLong) {
      // if double final, then loser moves to the bottom
      return [gId(LB, 2 * p, 1), 1];
    }
    // otherwise always KO'd if loosing in >= last bracket
    return null;
  }

  // WBR1 always feeds into LBR1 as if it were WBR2
  if (r === 1) {
    return [gId(LB, 1, Math.floor((g+1)/2)), g % 2];
  }

  if (this.downMix) {
    // always drop on top when downmixing
    return [gId(LB, (r-1)*2, mixLbGames(p, r, g)), 0];
  }

  // normal  LB drops: on top for (r>2) and (r<=2 if odd g) to match bracket movement
  var pos = (r > 2 || $.odd(g)) ? 0 : 1;
  return [gId(LB, (r-1)*2, g), pos];
}
function (id) {
  var b = id.s
    , r = id.r
    , g = id.m
    , p = this.p;

  // knockouts / special finals
  if (b >= this.last) { // greater than case is for BF in long single elimination
    if (b === WB && this.isLong && r === p - 1) {
      // if bronze final, move loser to "LBR1" at mirror pos of WBGF
      return [gId(LB, 1, 1), (g + 1) % 2];
    }
    if (b === LB && r === 2*p - 1 && this.isLong) {
      // if double final, then loser moves to the bottom
      return [gId(LB, 2 * p, 1), 1];
    }
    // otherwise always KO'd if loosing in >= last bracket
    return null;
  }

  // WBR1 always feeds into LBR1 as if it were WBR2
  if (r === 1) {
    return [gId(LB, 1, Math.floor((g+1)/2)), g % 2];
  }

  if (this.downMix) {
    // always drop on top when downmixing
    return [gId(LB, (r-1)*2, mixLbGames(p, r, g)), 0];
  }

  // normal  LB drops: on top for (r>2) and (r<=2 if odd g) to match bracket movement
  var pos = (r > 2 || $.odd(g)) ? 0 : 1;
  return [gId(LB, (r-1)*2, g), pos];
}
function ( id ) { var b = id . s , r = id . r , g = id . m , p = this . p ; // knockouts / special finals if ( b >= this . last ) { // greater than case is for BF in long single elimination if ( b === WB && this . isLong && r === p - 1 ) { // if bronze final, move loser to "LBR1" at mirror pos of WBGF return [ gId ( LB , 1 , 1 ) , ( g + 1 ) % 2 ] ; } if ( b === LB && r === 2 * p - 1 && this . isLong ) { // if double final, then loser moves to the bottom return [ gId ( LB , 2 * p , 1 ) , 1 ] ; } // otherwise always KO'd if loosing in >= last bracket return null ; } // WBR1 always feeds into LBR1 as if it were WBR2 if ( r === 1 ) { return [ gId ( LB , 1 , Math . floor ( ( g + 1 ) / 2 ) ) , g % 2 ] ; } if ( this . downMix ) { // always drop on top when downmixing return [ gId ( LB , ( r - 1 ) * 2 , mixLbGames ( p , r , g ) ) , 0 ] ; } // normal  LB drops: on top for (r>2) and (r<=2 if odd g) to match bracket movement var pos = ( r > 2 || $ . odd ( g ) ) ? 0 : 1 ; return [ gId ( LB , ( r - 1 ) * 2 , g ) , pos ] ; }
find the match and position a loser should move "down" to in the current bracket
find the match and position a loser should move down to in the current bracket