In light of the 2014 Australian Open in Melbourne, and the win by Stanislas Wawrinka against Novak Djokovic, I propose the following code golf challenge!
Wawrinka and Djokovic are at it again for the basis of this CGC. Your challenge is to take a string consisting of 1's and 2's and determine the tennis scores based on the tennis scoring system. A "1" indicates that Wawrinka has scored a point, whereas a "2" indicates that Djokovic has scored a point.
For the sake of example: 1211222122111122111
will generate a two-line output:
Wawrinka 1 - 40
Djokovic 1 - 30
The longer the string, the further into the game the score is.
Rules:
- Shortest code wins, pure and simple.
- The scores when displayed must be right aligned and also column aligned; e.g.
Sample alignment of output:
Wawrinka 7 5 3 - 0 Djokovic 6 7 4 - 15
If a game is in progress, the score must be displayed after the set scores. Game scores must follow set scores with a space-dash-space separator. If this happens to be the first game, a 0-0 set score must be displayed.
Wawrinka 0 - 0 Djokovic 0 - 15
A game will go in order of 0, 15, 30, 40, and game point. If a game reaches 40-40, a deuce is declared, and the score must display the deuce on the player row scoring the point:
Wawrinka 7 5 3 - 40 Djokovic 6 7 4 - 40 Deuce
If a deuce is reached, the next point will be an advantage to the player scoring the point:
Wawrinka 7 5 3 - Ad Djokovic 6 7 4 - 40
The point after that, if scored by the advantaged player, wins the game, else the game goes back to deuce.
If more than one deuce is scored in between advantage points, the number of the deuce will be indicated by a number in parentheses:
Wawrinka 7 5 3 - 40 Djokovic 6 7 4 - 40 Deuce (2)
A set is won if a player reaches 6 games or more and with a two game margin in lead, e.g. 7-5, 6-4... 9-7 (In the case of last night's fifth set)
Consecutive sets must be separated with a space.
There are tie breaks in the Australian Open, therefore if a 6-6 set is reached, a tie-break is established by the first player reaching seven points with a two point margin lead. Display of tie breaks are shown within square brackets as follows:
Wawrinka 7 6 [6] Djokovic 6 6 [4]
The winner of the tie-break is said to have won the previous set 7-6.
If the fifth set reaches 6-6, play is continued without tie-break until a two game margin is reached with one player, that player being the winner of that set. There are NO tie-breaks in the fifth set.
If a player has won three sets, a third line will be displayed saying
Wawrinka wins
orDjokovic wins
depending on who has won and the code then terminates.Wawrinka 2 6 6 3 9 Djokovic 6 4 2 6 7 Wawrinka wins
If the string ends such that the last point has won a game, set or match, the game score is not displayed...
Wawrinka 7 5 3 Djokovic 6 7 4
If the string goes beyond a match being won, the rest of the string is ignored, the score displayed and the winner declared.