#P2645. Snooker Score Simulation
Snooker Score Simulation
Snooker Score Simulation
In a snooker match, there are 21 balls: 15 red balls and 6 colored balls (yellow, green, brown, blue, pink, black). The scoring for a legally potted ball is as follows:
- Red ball: 1 point
- Yellow ball: 2 points
- Green ball: 3 points
- Brown ball: 4 points
- Blue ball: 5 points
- Pink ball: 6 points
- Black ball: 7 points
Two players (A and B) take turns. The simplified rules are:
Legal Play
- If there is at least one red ball on the table then in a turn the player makes two strokes:
- First stroke: must hit a red ball. If potted legally, the player gains 1 point and that red ball is removed from the table.
- Second stroke: immediately after a red ball is potted, the player may choose any colored ball. The colored ball (if potted legally) gives points as above, but is not removed from the table.
- If after a stroke the red balls become exhausted (i.e. none remain), the game enters the clearance stage. In this stage, in each turn the player must pot the colored balls in ascending order of their point value (i.e. yellow, green, brown, blue, pink, black). Each potted colored ball is then removed from the table.
Fouls
- If the player misses (hits no ball), then 4 points are awarded to the opponent.
- If the player hits a ball that is not the correct ball according to the rules:
- If the wrongly hit ball's point value is greater than 4 then the opponent is awarded points equal to that ball's value.
- If the wrongly hit ball's point value is not greater than 4 then the opponent is awarded 4 points.
Each turn is processed according to the above rules. Initially, there are 15 reds and 6 colors (all colors remain available throughout the red-ball stage). When a foul is committed, the current turn ends immediately and the opponent is awarded the appropriate fouled points. The players alternate turns regardless of whether the turn ended with a legal play or a foul.
The input contains a sequence of events (strokes) made so far in the game. Each event is one of the following types:
RED
— a legal pot of a red ball.COLOR x
— a legal pot of a colored ball, wherex
is one of: yellow, green, brown, blue, pink, black.MISS
— a shot with no ball hit (foul).FAULT x
— a shot hitting an incorrect ball, wherex
is the ball struck.
During the red-ball stage (when at least one red ball remains on the table), each turn should consist of two strokes if possible. The first stroke must be a red ball. If a foul occurs at any stroke, the turn ends immediately (and any subsequent stroke in that turn is skipped). Note that if the last red ball is potted during the first stroke of a turn, then the second stroke of that turn is played under clearance stage rules (i.e. the expected ball is the lowest-valued colored ball still on the table).
In the clearance stage, each turn consists of a single stroke and the expected ball is the next colored ball in the sequence yellow, green, brown, blue, pink, black.
After processing all the given events, output the current scores of player A and player B (in that order) separated by a space.
Note: The turn order is fixed: player A starts, then player B, and so on.
The scoring for fouls is determined as follows: let the value of a ball (if applicable) be v. If v > 4 then the opponent gets v points; otherwise, the opponent gets 4 points.
Mathematical Formulations:
For a legal stroke, the score gained for a ball of type ball is given by:
$$S(ball) = \begin{cases} 1, & \text{if ball is red}\\ 2,3,4,5,6,7, & \text{if ball is yellow, green, brown, blue, pink, black respectively} \end{cases} $$For a foul when the wrong ball is hit, the opponent's awarded points are:
$$F(ball) = \begin{cases} v, & \text{if } v > 4 \\ 4, & \text{if } v \le 4 \end{cases} $$Your task is to simulate the game and compute the current score.
inputFormat
The first line contains an integer N
indicating the number of stroke events.
The following N
lines each contain an event, which can be one of the following formats:
RED
COLOR x
wherex
is one of: yellow, green, brown, blue, pink, blackMISS
FAULT x
Note that events are processed in order. In the red-ball stage (when there is at least one red ball on the table), each turn expects two strokes (first a red, then a color). In the clearance stage (when no red balls remain), each turn consists of one stroke, and the expected ball is the lowest-valued colored ball (according to the order: yellow, green, brown, blue, pink, black).
outputFormat
Output two integers separated by a space: the final scores of player A and player B, respectively.
sample
4
RED
COLOR pink
RED
FAULT blue
12 1