Jim and Bob are playing badminton doubles against two other players, but mid-game they face a dilemma:
After a fast-paced rally they have no idea who has to serve next and where they have to stand for the next serve.
Bad enough they only know the scores in order.
To help them out, you have to know the rules:
- If the serving team has an even score, serving is done by the player on the right side (relatively facing towards the net)
- If the serving team has an odd score, serving is done by the left player.
- If the serving team changes, the players' position remains.
- If one team keeps the right to serve the ball, the two players of that team swap places, so the same player serves again.
- The team, that scored last, serves next.
This is where you come to help them out.
Your task is to take the scores in order and return the position for all four players according to the rules as well as the player, who has to serve next.
Input is a string / array / set / whatever you like containing all scores in the order they are scored.
"0:0, 0:1, 0:2, 1:2, 1:3" or
["0:0", "0:1", "0:2", "1:2", "1:3"]
You may assume team 1 (the left part of the score) served first in the beginning.
The input is not secured to be valid!
Your program / function / script has to output an ASCII-art style badminton court (don't care about orientation) with the position of the players and some representation of the player serving next (a single line saying
Next to serve is >Player1< is enough).
Example output of the example given above (
"0:0, 0:1, 0:2, 1:2, 1:3"):
|-----|-----| |-Jim-|-Bob-| //Team 1 |###########| |-P4--|-P3--| //Team 2 |-----|-----| Player P4 of team 2 serves next.
The players are named Jim, Bob, P3 and P4. P3 and P4 swap their places after scoring "0:2" and keeping the right to serve. Jim and Bob never scored two times in a row and thus never swap places.
Last notes about input and output:
- Input is assumed to be always in order with the first (left) score to be team 1, which may be assumed to have served first.
- The names of the players are irrelevant as long as it is documented which player belongs to which team.
- Team 1 is always the upper/left team in your output.
- Even though a usual badminton round ends when one team scores 21 (without overtime), you may assume the game to be as long as the two teams want to play.
- Sometimes the input may be incomplete (missing a score). Then your program has to output an error message indicating invalid input (
Error!is enough for golfing reasons).
This is code-golf, so the least amount of bytes wins.
There are bonuses to claim though:
- -20% if you output the court and server for every single serve.
- -10% if your program allows to choose the serving team.
- -15% if the user can choose the names for the players.
The bonus percentages are first added and then applied to the byte count, resulting in a maximum bonus of 45%!
Test cases (so you don't have to come up with your own):
(Strings only, including output and validation):
0:0, 1:0, 2:0, 3:0, 3:1, 3:2, 4:2, 4:3, 5:3, 6:3, 6:4, 7:4, 7:5, 7:6, 8:6, 8:7, 9:7, 10:7, 11:7, 12:7, 12:8, 12:9, 13:9
|-----|-----| |-Bob-|-Jim-| //Team 1 |###########| |-P4--|-P3--| //Team 2 |-----|-----| Player Jim of team 1 serves next.
0:0, 0:1, 0:2, 1:2, 2:2, 3:3, 4:3, 4:4 -> Invalid /\ Both teams can't score at the same time/missing intermediate score
Invalid input! Please check input and try again.
In case you have questions or need clarification, please ask so I can improve the challenge.