VGC Tiebreaker Mechanics (and probably random Wi-Fi and Wi-Fi Competitions as well as well)
For reference here are what the official rules say about the tiebreakers for VGC battles:
29.1. Tiebreakers
Should the time limit expire before a player knocks out his or her opponent’s final Pokémon, the winner of the game is determined based on the criteria below.
1. Remaining Pokémon
If one player has more remaining Pokémon than the other, that player wins the game.
If both players have the same number of Pokémon remaining, the result of the game is determined by average percentage of HP remaining, as described below.
2. Average Percentage of HP Remaining
If one player’s team has a higher average percentage of HP remaining, that player wins the game.
If both players’ teams have the same average HP remaining, the result of the game is determined by amount of HP remaining, as described below.
3. Amount of Total HP Remaining
If one player’s team has a higher total HP remaining, that player wins the game.
If both players’ teams have the same total HP remaining, the result of the game is a tie.
These tiebreakers are automatically applied by the game when the timer in a match runs out. How the second tiebreaker works has come into question so I did some testing regarding it. How people seem to think it worked was:
Tiebreaker Rating = (sum of (current HP/max HP) for each living Pokemon) / (# of living Pokemon)
With the higher tiebreaker rating winning the second tiebreaker. This is incorrect.
For the tests, I'll give the number of Pokemon alive, their current and max HP when the timer expires.
[b]Test #1[/b]
Team 1
4 Pokemon alive with the following current and max HP:
156/156
155/155
170/170
161/161
Team 2
4 Pokemon alive with the following current and max HP:
185/185
[b]168[/b]/201
191/191
167/167
Team 1 wins. Both teams had the same number of Pokemon and Team 2 had the higher total remaining HP so this shows the second tiebreaker does exist.
[b]Test #2[/b]
Team 1
1 Pokemon alive with the following current and max HP along with the max HP of the three fainted Pokemon:
[b]142[/b]/155
0/156
0/161
0/170
Team 2
1 Pokemon alive with the following current and max HP along with the max HP of the three fainted Pokemon:
155/155
0/185
0/191
0/201
[b]Team 1 wins.[/b] I don't think you will find many people who would have expected this result. Team 2 has 1 full HP Pokemon against a single damaged Pokemon and loses despite what many would interpret to be a higher average Percentage of HP Remaining.
[b]Test #3[/b]
Team 1
[b]140[/b]/155
0/156
0/161
0/170
Team 2
155/155
0/185
0/191
0/201
[b]Team 2 wins.[/b] The difference in this scenario is Team 1's first Pokemon has 140 HP instead of 142. This is enough for team 1 to either lose the second tiebreaker or tie the second tiebreaker and lose on the third.
I believe the truth of the second tiebreaker is:
Tiebreaker Rating = floor((total current HP of all Pokemon) * 100 / (total max HP of all Pokemon))
Using my formula:
Test #1
Team 1 Tiebreaker score = 100
Team 2 Tiebreaker score = 95
Test #2
Team 1 Tiebreaker score = 22
Team 2 Tiebreaker score = 21
Test #3
Team 1 Tiebreaker score = floor(21.81) = 21
Team 2 Tiebreaker score = floor(21.17) = 21 (Team 2 wins by 3rd tiebreaker)
It's worth noting that before the floor, team 1 actually wins the 2nd tiebreaker but due to the floor it becomes a tie and a loss by 3rd tiebreaker.
Any other ideas for test cases or mistakes I may have made?