// -------------------- // 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.