Skip to content

Instantly share code, notes, and snippets.

@promatik
Created April 12, 2016 22:39
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 promatik/d0352e6a3e9b39c483f56a2c175f9024 to your computer and use it in GitHub Desktop.
Save promatik/d0352e6a3e9b39c483f56a2c175f9024 to your computer and use it in GitHub Desktop.
Check whenever penalty shootout game is finished or not
// --------------------
// Penalty Shoot-out
// Ilustrated example at https://jsfiddle.net/promatik/yo00Lr4e/
// --------------------
function checkPenaltyShootOutEnd(round, score1, score2, total_rounds, first_shooter) {
return Math.abs(score1-score2) > (round > total_rounds ? round % 2 : Math.ceil((10-round) / 2) - (first_shooter ^ score1 < score2 ? 0 : round % 2));
}
// --------------------
// Usage example, for: 0 1 0 _ _ - 1 1 _ _ _
// Round should be 5 (because there are 5 tries for booth teams), total rounds are 10
// score1 is 1, and score2 is 2, and as the first shooter is the first player, first_shooter should be true.
// checkPenaltyShootOutEnd(5, 1, 2, 10, true) : false. Game isn't ended.
// checkPenaltyShootOutEnd(6, 3, 0, 10, true) : true. There's no chance for player 2 to recover.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment