Problem Statement |
| Clue is a board game played by three or more players. The object of the game is to determine who has committed a
crime, where the crime was committed, and with what weapon. In this problem, we will number the suspects 1-6, the
weapons 1-6, and the locations 1-9 and assume that there are exactly 3 people playing. Each suspect, weapon
and location is represented by its own card, for a total of 21 cards. In the game, one suspect card, one weapon
card and one location card are secretly chosen at random and set aside as the suspect, weapon and location associated
with the crime. The remaining cards are then dealt so that each player gets a total of exactly 6 cards. There are a number of turns in a game, and each turn a player guesses one suspect, one weapon and one location. Then the player to his left examines her cards, and if she has one or more of the cards in
the guess, she must reveal one of them to the player who made the guess. If she has more than one of the cards, she gets to choose which one to reveal. If, and only if, the player to the immediate left of the guesser doesn't have one of the three cards, then the third player (to the guesser's right) must examine his or her cards, and perform the same procedure. Eventually, enough guesses are made that one player may deduce which cards are set aside, and he or she wins the game.
Your goal is to write a class to try to deduce the cards which are set aside. You will be given a
String[], cards, representing the cards in your hand. You will also be given a
String[], guesses, representing the guesses made, in the order they were made, and the results of
the guesses. Each element of cards will be formatted as "<type><number>", where <type> is
'S', 'L', or 'W', representing suspect, location or weapon, respectively. <number> is a single digit,
representing which suspect, location or weapon the card shows. Each element of guesses will be formatted
as:
"<guesser> <suspect guessed> <location guessed> <weapon guessed> <responder>
<response>"
<guesser> will be a digit between 1 and 3, inclusive, representing the person making
the guess. You are player 1, so if <guesser> is 1, it means that you made the guess. <suspect guessed>,
<location guessed>, and <weapon guessed> will all be single digits representing which suspect, location
and weapon were guessed. <responder> will be a single digit between 0 and 3, inclusive, representing the player who responded to the guess. <responder> will not be the
same as <guesser>. If <responder> is 0, it means that none of the non-guessing players had any of the
cards associated with the guess. If <responder> is 1, it means that you are the one who
responded, and <response> will be an element of cards, representing which card you showed to
the guesser. If <guesser> is 1, then you are the one who guessed, and if <responder> is not 0, then <response> will represent the card that player <responder> showed you. If you are the guesser and no one responded, or if you are neither the responder nor the guesser, then <response> will be "N0" (the number zero, not the letter oh), meaning that the response was either hidden from you or did not exist.
You are to determine the set of cards that could be secret cards. This set will always contain at least one suspect, one location, and one weapon. You should return a sorted String[], each of whose elements represents a single card in this set, in the same format as elements of cards.
|
|
Definition |
| Class: | Clue | Method: | whodunit | Parameters: | String[], String[] | Returns: | String[] | Method signature: | String[] whodunit(String[] cards, String[] guesses) | (be sure your method is public) |
|
|
|
|
Notes |
- | You are player 1, the player to your left is player 2, and the player to his or her left is player 3, who is to your right. |
- | Players do not necessarily make guesses in any particular order. So, a single player may make more than 1 guess in a row. |
|
Constraints |
- | cards will contain exactly 6 distinct elements, formatted as described in the problem statement. |
- | guesses will contain between 0 and 50 elements, inclusive, formatted as described in the problem statement. |
- | There will always be at least one way to divide the cards not in cards between the secret cards, player 2's cards, and player 3's cards that is consistent with guesses. |
- | Each element of guesses will be formatted as described above. |
- | If <guesser> is 1, then either <responder> will be 0 and <response> will be N0, or <responder> will not be 0 and <response> will represent one of the three cards guessed. |
- | If neither <guesser> nor <responder> is 1, then <response> will be N0. |
- | If <responder> is 1, then <response> will be an element of cards and will be one of the three cards guessed. |
- | If <responder> is not 1, then <response> will not be an element of cards. |
- | <responder> will not equal <guesser> |
|
Examples |
0) | |
| {"S1","S2","S4","S3","S5","W5"} | {"1 1 1 1 0 N0"} |
| Returns: { "L1", "S6", "W1" } | In this example, you make a single guess of S1, W1, L1. No one is able to respond (<responder> = 0), which means that neither of the other two players has S1, W1, or L1. Thus those three cards must all be either secret cards or your cards. W1 and L1 are not your cards, and are thus secret cards. Furthermore, since you have five of the six suspect cards, the only other possible suspect card that could be a secret card is S6. |
|
|
1) | |
| {"L3","S2","S4","S3","S5","W5"} | {"2 1 1 1 0 N0"} |
| Returns:
{ "L1",
"L2",
"L4",
"L5",
"L6",
"L7",
"L8",
"L9",
"S1",
"S6",
"W1",
"W2",
"W3",
"W4",
"W6" } | This is a similar guess as the one in example 0, only with a different guesser. You have no idea which cards the guesser has, so the guess doesn't really tell you anything, and any card not in your hand can be a secret card. |
|
|
2) | |
| {"W4","W1","L5","L9","S3","L2"} | {"2 3 8 4 1 W4",
"1 3 8 3 3 W3"} |
| Returns: { "L8", "S1", "S2", "S4", "S5", "S6", "W2", "W5", "W6" } | From the first guess, we know that player 3 doesn't have S3, L8, or W4. Similarly, from the second guess, we know that player 2 doesn't have S3, L8, or W3. We also know that player 3 has W3, since he showed it to us.
First, we can deduce that the secret location must be L8, since neither of the other players have it, and we don't have it. Next, the secret weapon has to be W2, W5, or W6, since we know who has the other weapons. The only thing we know about suspects is the secret card isn't S3, since we have that. |
|
|
3) | |
| {"W4","W1","L5","L9","S3","L2"} | {"1 3 5 4 0 N0"} |
| Returns:
{ "L1",
"L3",
"L4",
"L6",
"L7",
"L8",
"S1",
"S2",
"S4",
"S5",
"S6",
"W2",
"W3",
"W5",
"W6" } | Guessing three of your own cards will never give you any new information. |
|
|
4) | |
| {"W4","W1","L5","L9","S3","L2"} | {} |
| Returns:
{ "L1",
"L3",
"L4",
"L6",
"L7",
"L8",
"S1",
"S2",
"S4",
"S5",
"S6",
"W2",
"W3",
"W5",
"W6" } | |
|
5) | |
| {"L5","L7","L8","S5","W5","W6"} | {"2 6 1 6 3 N0",
"3 6 5 4 1 L5",
"1 6 1 3 2 W3",
"2 3 5 1 3 N0",
"3 5 7 1 1 S5",
"1 6 1 1 3 L1",
"2 1 2 5 3 N0",
"3 4 6 5 1 W5",
"1 3 3 4 2 W4",
"2 6 4 1 3 N0",
"3 4 3 6 1 W6",
"1 4 6 1 2 S4",
"2 2 5 6 3 N0",
"3 6 7 4 1 L7",
"1 6 4 1 3 L4",
"2 6 5 1 1 L5",
"3 4 3 1 2 N0",
"1 6 2 1 3 L2",
"2 6 3 1 0 N0",
"3 6 3 1 0 N0"} |
| Returns: { "L3", "S6", "W1" } | |
|