Tennis scores meets Code Golf 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 or Djokovic 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.
Perl - 424 bytes

*1=a;*2=b;@1=(Wawrinka,0);@2=(Djokovic,0);
$$_++&gt;${$o=S^$_}&amp;&amp;$$_&gt;3and$1=$2=0,
$w=$w[$_]+=($$_[$.]++&gt;$$o[$.]||(($t=$$_[$.]==$$o[$.])&amp;&amp;!$%&amp;&amp;$.&lt;5))&amp;&amp;
$$_[$.]&gt;5+$%&amp;&amp;!($1[$.]=$2[$.+=!$%]=$w&lt;2&amp;&amp;0,$$_[$.-1]+=$%,$%=$t)for&lt;&gt;=~/./g;
@s=(' 0',15,30,(40)x($e=$$o&lt;3||$$o-2),Ad);
$%and$_="[$_]"for@1[-1],@2[-1];$d[$&amp;]=$1&gt;2&amp;&amp;$1==$2&amp;&amp;' Deuce'.($1&gt;3&amp;&amp;" ($e)");
print"@1",$w&lt;3&amp;&amp;" - $s[$1]$d[1]","\n@2",$w&lt;3&amp;&amp;" - $s[$2]$d[2]",$w&gt;2&amp;&amp;"\n${$&amp;}[0] wins"


Newlines have been added for readability horizontal sanity.

I believe this to be a complete solution, according to the scoring of the Australian Open:


Best of five sets (a.k.a. race to three).
Sets 1-4 are played as a 6-6 tie-breaker.
Set 5 is played as an advantage set.


Test Cases



1211222122111122111


 

Wawrinka 1 - 40
Djokovic 1 - 30




12112221221111221112


 

Wawrinka 1 - 40
Djokovic 1 - 40 Deuce




121122212211112211122


 

Wawrinka 1 - 40
Djokovic 1 - Ad




1211222122111122111221


 

Wawrinka 1 - 40 Deuce (2)
Djokovic 1 - 40




22111111212122221122111212212112121221212211221121222222112112221121121122221122221211111222121222122211212122111212112211222121211212211212211122121211112222222212211121122


 

Wawrinka 6 [5] - 30
Djokovic 6 [6] - 40




221111112121222211221112122121121212212122112211212222221121122211211211222211222212111112221212221222112121221112121122112221212112122112122111221212111122222222122111211222


 

Wawrinka 6 0 -  0
Djokovic 7 0 -  0




1122222211121211121211111121111211221222212212112221211222211222112212211121122122212122212222122212212211221111121222111221211111211112222212122122112111212121221221212211112122212211111111112111212222221112212121122212121111122111222222111212221121221111222122122222111212111111221121122111122122111222222121122221112221221122221121211212111122111121212112112121222122


 

Wawrinka 5 4 6 6 5 - 15
Djokovic 7 6 4 4 6 - 40




11222222111212111212111111211112112212222122121122212112222112221122122111211221222121222122221222122122112211111212221112212111112111122222121221221121112121212212212122111121222122111111111121112122222211122121211222121211111221112222221112122211212211112221221222221112121111112211211221111221221112222221211222211122212211222211212112121111221111212121121121212221222


 

Wawrinka 5 4 6 6 5
Djokovic 7 6 4 4 7
Djokovic wins




222221112112212212222111222211111111121111121112211221221211212121122211222112111112122122212222211112122212221111121111121211212112112112221221121122121121112221221222122122211222212121212112112111221221121112222212122222221111112222222221221122211221121111221121222222111111122221122111211121222112112122212122221121222221222121212111121221221112111212212222122212212212112111112112112121112221111221221221121222122211221212211111111222222121221112221212


 

Wawrinka 6 7 6 4 7 - 40
Djokovic 3 5 7 6 8 - Ad




2222211121122122122221112222111111111211111211122112212212112121211222112221121111121221222122222111121222122211111211111212112121121121122212211211221211211122212212221221222112222121212121121121112212211211122222121222222211111122222222212211222112211211112211212222221111111222211221112111212221121121222121222211212222212221212121111212212211121112122122221222122122121121111121121121211122211112212212211212221222112212122111111112222221212211122212122


 

Wawrinka 6 7 6 4 7 
Djokovic 3 5 7 6 9 
Djokovic wins


All intermediate scores for the last test case can be seen here: http://codepad.org/FzDIcf0W