Problem L
Codenames
Codenames is a popular board game. Two teams compete by each having a “spymaster” give one-word clues that can point to multiple words on the board. The other players on the team attempt to guess their team’s words while avoiding the words of the other team. The objective is to be the first team to have all their team’s words revealed.
Players split into two teams: red and blue. One player of each team is selected as the team’s spymaster; the others are field operatives.
Teams take turns. On each turn, the appropriate spymaster gives a verbal hint about the words on the respective cards. Each hint may only consist of one single word and a number. The spymaster’s hint should be as close to their own agents’ cards as possible. The hint’s number tells the field operatives the maximum number of guesses to make.
After a spymaster gives the hint, their field operatives make guesses about which Codename cards bear words related to the hint and point them out, one at a time. When a Codename card is pointed out, the spymaster reveals the identity of that card—a blue agent card, a red agent card, an innocent bystander card, or the assassin card. Depending on the identity of the card, one of these things happens:
-
If an assassin is pointed out, the game ends immediately, and their team loses.
-
If an innocent bystander is pointed out, the turn simply ends.
-
If an agent of the other team is pointed out, the turn ends, and that other team is one agent closer to winning.
-
If an agent of their team is pointed out, they are one agent closer to winning, and they may choose to make another guess.
The game ends when all of one team’s agents are identified (winning the game for that team), or when one team has identified the assassin (losing the game).
To simplify the problem, let’s assume that both teams share
the same dictionary of hint words and their associations with
Codename cards. For example, consider this board (
Plate(R) |
Screen(I) |
Novel(A) |
Robin(B) |
Iron(R) |
Server(B) |
The list of hint words and their associated Codenames cards is given in Table 2.
Alfred |
Robin, Server, Plate |
Net |
Server, Screen, Plate |
Computer |
Screen, Server |
|
Screen, Robin, Server |
Crusoe |
Robin, Novel |
Film |
Iron, Screen |
Once the spymaster gives a hint word and a number,
For example, assuming the blue team goes first in the first
round, the blue spymaster may give a hint “Twitter, 2”. The
blue team has
Now you are selected as the spymaster, and your team (color specified in the input) goes first. Assuming both spymasters play optimally, what is your probability of winning the game?
Input
The first line consists of an integer and a character,
separated by a single space. The integer is
The second line consists of
The third line consists of
The fourth line consists of an integer
Each of the following
Output
Probability of winning the game. Your answer will be
considered correct if it has an absolute error of at most
Sample Explanation
The blue spymaster has three hint words to choose from (in
any case, their team can only make one guess in the turn, so
the choice of
-
If they choose the first, their team has
probability of guessing “apple” and wins the game, and probability of guessing “java” and ends the turn, which allows the red spymaster to give the third hint word and win. So the blue team’s winning chance is in this case; -
If they choose the second, their team has
probability of guessing “apple” and wins the game, and probability of guessing “dog” and loses the game. So the blue team’s winning chance is also ; -
If they choose the third, their team has
probability of guessing “sleep” and loses the game, and probability of guessing “java” and ends the turn, which allows the red spymaster to give the third hint word and win. So the blue team’s winning chance is in this case.
To sum up, the best strategy for the blue spymaster is
either (1) or (2) and their winning chance is
Sample Input 1 | Sample Output 1 |
---|---|
4 B apple sleep java dog B R I A 3 2 apple java 2 apple dog 2 sleep java |
0.5000 |