Snooker is a cue sport that is played on a large baize-covered table with pockets in each of the four corners and in the middle of each of the long side cushions. It is played using a cue and snooker balls: one white cue ball, 15 red balls worth one point each, and six balls of different colors: yellow (2 points), green (3), brown (4), blue (5), pink (6) and black (7). A player (or team) wins a frame (individual game) of snooker by scoring more points than the opponent(s), using the cue ball to pot the red and colored balls. In this problem, your job is the referee of snooker. You should score both players, ask the correct player to play next, as well as place some of the balls back to the table if necessary. The rules of snooker needed for this problem are following. (We ignore some fouls about incorrectly hitting the cue ball here. We assume that the cue ball is never snookered after a foul, so free ball will never occur. We also assume that both players will make their best attempts to hit the ball on, so you do not need to declare a miss when they do not hit the ball on first.)
At the beginning of each frame the balls are set up by the referee as illustrated above. This will be followed by a break-off shot, the white cue ball can be placed anywhere inside the D (it is called in-hand, which also happens when the cue ball is potted). Players take turns in visiting the table. A break is the number of points scored by a player in one single visit to the table. A player's turn and break end when he fails to pot a ball, when he does something against the rules of the game, which is called a foul, or when a frame has ended.
The ball or balls that can be hit first by the white are called the ball(s)
"on" for that particular stroke. The ball(s) "on" differ from shot to shot:
a red ball, if potted, must be followed by a color, and so on until a break
ends; if a red is not potted, any red ball remains the ball "on". Only
a ball or balls "on" may be potted legally by a player. If a ball not "on"
is potted, this is a foul.
The game of snooker generally consists of two phases. The first phase is the situation in which there are still red balls on the table. In the first phase, at the beginning of a player's turn, the balls "on" are all remaining red balls. The player must therefore attempt to first hit and pot one or more red balls. For every red ball potted, the player will receive 1 point. When a red has been potted, it will stay off the table and the player can continue his break. If no red has been potted or a foul has been made, the other player will come into play. In case one or more red balls have been potted, the player can continue his break. This time one of the six colors (yellow, green, brown, blue, pink and black) is the ball "on". Only one of these can be the ball "on"
and the rules of the game state that a player must nominate his desired color to the referee, although it is often clear which ball the striker is playing and it is not necessary to nominate. When the nominated color is potted, the player will be awarded the correct number of points (yellow, 2; green, 3; brown, 4; blue, 5; pink, 6; black, 7). The color is then taken out of the pocket by the referee and placed on its original spot. Because only one of the colors is the ball "on", it is a foul to first hit multiple colors at the same time, or pot more than one color. If a player fails to pot a ball "on", it being a red or nominated color, the other player will come into play and the balls "on" are always the reds, as long as there are still reds on the table. The alternation between red balls and colors ends when all reds have been potted and a color is potted after the last red, or a failed attempt to do so is made. Then the second phase begins. All six colors have to be potted in ascending order of their points value (yellow, green, brown, blue, pink, black). Each becomes the ball "on" in that order. During this phase, when potted, the colors stay down and are not replaced on the table, unless a foul is made when potting the color, in which case the color is respotted.
When only the black is left, the first score or foul ends the frame, and the player who has scored most points has won it. However, if the score is tied after that, the black is respotted, the players draw lots for choice of playing, the next player plays from in-hand, and the next score or foul ends the frame. When a foul is made during a shot, the player's turn is ended and he will receive no points for the foul shot. The other player will receive penalty
points. Colors illegally potted are respotted (while reds are not), and if the cue ball is potted, the next player will play from in-hand. Fouls concerned in this problem are:
。failing to hit any other ball with the cue ball
。first hitting a ball "not-on" with the cue ball
。potting a ball "not-on"
。potting the white (in-off)
Penalty points are at least 4 points and at most 7 points. The number of penalty points is the value of the ball "on", or any of the "foul" balls, whichever is highest. When more than one foul is made, the penalty is not the added total - only the most highly valued foul is counted. As players usually do not nominate a color explicitly when hitting the colors, please be tolerant and assume that he always nominate the ball with the lowest score when it cannot be deduced from the ball first hit (i.e. when the cue ball does not hit any ball or hit a red first). If a player commits a foul, and his opponent considers that the position left is unattractive, he may request that the offender play again from the resulting position.