#P6989. Epic Win in Rock-Paper-Scissors FSM Tournament
Epic Win in Rock-Paper-Scissors FSM Tournament
Epic Win in Rock-Paper-Scissors FSM Tournament
In this problem, two finite state machines (FSMs) compete in a game of rock‐paper‐scissors. Each FSM is a Moore machine: every state defines the move to play (either Rock, Paper, or Scissors) and the transitions for each possible opponent move (Rock, Paper, and Scissors). The rules of rock‐paper‐scissors are standard: if both moves are the same, the round is a draw; otherwise, Rock beats Scissors, Paper beats Rock, and Scissors beat Paper.
You are given the complete description of your opponent's FSM, except for its unknown initial state. Your task is to design your own FSM such that, no matter which state the opponent starts in, you win at least $99\%$ of the first $10^9$ rounds. This is called an epic win.
Your strategy is to first "synchronize" the opponent: since you know its entire transition table, you can find a synchronizing sequence (a word over {R, P, S}) that brings the opponent to the same state regardless of where it starts. Once synchronized, you can simulate the opponent's behavior exactly. For each round, if the opponent in its current state will output a move m, you simply output the move that beats m (i.e. if m is R then output P, if m is P then output S, and if m is S then output R). In reaction phase, your FSM will follow the cycle dictated by the opponent's transitions.
The opponent FSM is described as follows. Each state (numbered from 0 to n−1) is given by a move (R, P, or S) and three transitions: the next state if the opponent sees Rock, Paper, or Scissors. Your output FSM must be a Moore machine with states numbered from 1 to m (with state 1 as the initial state). Each state in your FSM is described by an output move and three transitions (for opponent inputs R, P, and S) that force your FSM to follow your planned synchronization and reaction sequence.
Note: It is guaranteed that the given opponent FSM is synchronizable (i.e. there exists a sequence in {R, P, S} that sends all states to the same state). Use this fact to achieve an epic win.
inputFormat
The first line contains an integer n
($1 \le n \le 100$), the number of states in the opponent's FSM. The following n
lines each contain a description of a state. The i-th line (0-indexed) contains a character and three integers: the move of state i
(one of R, P, S) and the transitions for Rock, Paper, and Scissors respectively. For each state, the transitions are given as integers in the range 0 to n−1.
outputFormat
First, output an integer m
, the number of states in your FSM. Then output m
lines; the i-th line (states are numbered from 1 to m, with 1 being the initial state) should contain a character and three integers: the move of that state and the transitions for opponent inputs R, P, and S respectively. In your FSM, the transitions must be defined in such a way that your strategy achieves at least $99\%$ wins over $10^9$ rounds.
Note: Your FSM should incorporate a synchronization phase based on a synchronizing word of the opponent's FSM, followed by a reaction phase where you always play the winning move against the predicted opponent move.
sample
1
R 0 0 0
1
P 1 1 1
</p>