Skip to content

Instantly share code, notes, and snippets.

@freshlogic
Last active September 2, 2017 16:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save freshlogic/48f86ac9a332cb9d2390b131077b4a7e to your computer and use it in GitHub Desktop.
Save freshlogic/48f86ac9a332cb9d2390b131077b4a7e to your computer and use it in GitHub Desktop.
Coders Bracket 2016
function(game, team1, team2) {
var percentages = {
round5: { 1: 100, 2: 94, 3: 85, 4: 78, 5: 68, 6: 66, 7: 60, 8: 48, 9: 52, 10: 40, 11: 34, 12: 35, 13: 22, 14: 15, 15: 6, 16: 0 },
round4: { 1: 87, 2: 69, 3: 61, 4: 56, 5: 52, 6: 51, 7: 27, 8: 18, 9: 8, 10: 46, 11: 38, 12: 49, 13: 24, 14: 12, 15: 14, 16: 0 },
round3: { 1: 79, 2: 72, 3: 50, 4: 35, 5: 21, 6: 33, 7: 37, 8: 70, 9: 40, 10: 33, 11: 33, 12: 5, 13: 0, 14: 0, 15: 0, 16: 0 },
round2: { 1: 59, 2: 46, 3: 47, 4: 72, 5: 75, 6: 23, 7: 0, 8: 57, 9: 50, 10: 0, 11: 60, 12: 0, 13: 0, 14: 0, 15: 0, 16: 0 },
round1: { 1: 57, 2: 48, 3: 64, 4: 23, 5: 50, 6: 67, 7: 0, 8: 50, 9: 0, 10: 0, 11: 0, 12: 0, 13: 0, 14: 0, 15: 0, 16: 0 },
round0: { 1: 67, 2: 33, 3: 44, 4: 33, 5: 0, 6: 50, 7: 0, 8: 50, 9: 0, 10: 0, 11: 0, 12: 0, 13: 0, 14: 0, 15: 0, 16: 0 }
};
var lowerSeededTeam = team1;
var higherSeededTeam = team2;
if (team1.seed === team2.seed) {
// If the seeds of two teams are the same, use the team's rank
if (team2.official_rank < team1.official_rank) {
lowerSeededTeam = team2;
higherSeededTeam = team1;
}
} else if (team2.seed < team1.seed) {
lowerSeededTeam = team2;
higherSeededTeam = team1;
}
// Get the winning percentage for the lower seeded team based on round
var percentage = percentages['round' + game.round][lowerSeededTeam.seed];
// Add the delta of the team's rpi * winning percentage
percentage += (lowerSeededTeam.rpi * lowerSeededTeam.win_pct - higherSeededTeam.rpi * higherSeededTeam.win_pct) * 100;
// Add the delta of the team's 3-point percentage
percentage += (lowerSeededTeam.three_point_pct - higherSeededTeam.three_point_pct) * 1;
// Add the delta of the team's field goal percentage
percentage += (lowerSeededTeam.field_goal_pct - higherSeededTeam.field_goal_pct) * 1;
// Add the delta of the team's free throw percentage
percentage += (lowerSeededTeam.free_throw_pct - higherSeededTeam.free_throw_pct) * 1;
// Generate a random number between 0 and 100
var random = Math.round(Math.random() * 100);
if (random <= percentage) {
// Lower seeded team wins game
lowerSeededTeam.winsGame();
} else {
// Upset: higher seeded team wins game
higherSeededTeam.winsGame();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment