duel.js
function (p, round, game) {
  // we know round <= p
  var numGames = Math.pow(2, p - round);
  var midPoint = Math.floor(Math.pow(2, p - round - 1)); // midPoint 0 in finals

  // reverse the match list map
  var reversed = $.odd(Math.floor(round/2));
  // split the match list map in two change order and rejoin the lists
  var partitioned = $.even(Math.floor((round + 1)/2));

  if (partitioned) {
    if (reversed) {
      return (game > midPoint) ? numGames - game + midPoint + 1 : midPoint - game + 1;
    }
    return (game > midPoint) ?  game - midPoint : game + midPoint;
  }
  return reversed ? numGames - game + 1 : game;
}
function (p, round, game) {
  // we know round <= p
  var numGames = Math.pow(2, p - round);
  var midPoint = Math.floor(Math.pow(2, p - round - 1)); // midPoint 0 in finals

  // reverse the match list map
  var reversed = $.odd(Math.floor(round/2));
  // split the match list map in two change order and rejoin the lists
  var partitioned = $.even(Math.floor((round + 1)/2));

  if (partitioned) {
    if (reversed) {
      return (game > midPoint) ? numGames - game + midPoint + 1 : midPoint - game + 1;
    }
    return (game > midPoint) ?  game - midPoint : game + midPoint;
  }
  return reversed ? numGames - game + 1 : game;
}
function ( p , round , game ) { // we know round <= p var numGames = Math . pow ( 2 , p - round ) ; var midPoint = Math . floor ( Math . pow ( 2 , p - round - 1 ) ) ; // midPoint 0 in finals // reverse the match list map var reversed = $ . odd ( Math . floor ( round / 2 ) ) ; // split the match list map in two change order and rejoin the lists var partitioned = $ . even ( Math . floor ( ( round + 1 ) / 2 ) ) ; if ( partitioned ) { if ( reversed ) { return ( game > midPoint ) ? numGames - game + midPoint + 1 : midPoint - game + 1 ; } return ( game > midPoint ) ? game - midPoint : game + midPoint ; } return reversed ? numGames - game + 1 : game ; }
helper to mix down progression to reduce chances of replayed matches
helper to mix down progression to reduce chances of replayed matches