#P8079. Interactive Word Guess Game

    ID: 21262 Type: Default 1000ms 256MiB

Interactive Word Guess Game

Interactive Word Guess Game

In this problem, you are required to implement an interactive word guessing game. In each round, the interactive library will generate a word of length \(5\) from a given dictionary and provide its first letter. You have at most 5 chances to guess the hidden word.

For each guess, you must output a word (of length \(5\)) that exists in the dictionary. If your guess is correct, the round ends immediately. Otherwise, the interactive library returns two boolean arrays \(\texttt{gold}\) and \(\texttt{silver}\):

  • \(\texttt{gold}[i]\) for \(0 \leq i < 5\) is \(true\) if and only if the \(i\)th letter of your guess is correct in both character and position.
  • \(\texttt{silver}[i]\) (only defined for letters that are not golden) is \(true\) if the letter appears elsewhere in the hidden word among the non-golden positions.

For example:

  • If the hidden word is panic and your guess is paper, then gold[0] = true (\(p\) is correct) and gold[1] = true (\(a\) is correct), and all other entries are false. Note that although the second p in paper appears in panic, it is ignored as it is part of the golden letters.
  • If the hidden word is apple and your guess is paper, then gold[2] = true (\(p\) in the third position is correct) and silver[0] = true, silver[1] = true, and silver[3] = true because those guessed letters appear in the hidden word in non‐golden positions.

Scoring: You will play \(T = 1000\) rounds in total. The score for each round is determined as follows:

  • If any guessed word is not of length \(5\) or is not in the dictionary, you score \(0\) for that round.
  • If you guess correctly on the 1st try, you earn \(150\) points; 2nd try: \(120\) points; 3rd try: \(100\) points; 4th try: \(90\) points; 5th try: \(85\) points.
  • If all five guesses are wrong, you earn \(0\) for that round.

Your final score will be the minimum of \(100\) and the average score over the \(1000\) rounds.

Interactive Function Interface:

You must implement the following two functions in a single source file named word.cpp (for C++):

const char *guess(int num_testcase, int remaining_guesses, char initial_letter, bool *gold, bool *silver);
void init(int num_scramble, const char *scramble);

Details:

  • The parameter num_testcase indicates the current round (\(1 \leq num_testcase \leq T\)).
  • Each round calls the guess function between 1 and 5 times. On the \(j\)th call, remaining_guesses is \(6-j\) (i.e. from 5 down to 1).
  • The initial_letter is the first letter of the hidden word (a lowercase letter).
  • For calls with remaining_guesses == 5, the arrays gold and silver are not available (may be NULL). For calls with remaining_guesses < 5, these arrays have size 5.
  • The string returned by guess must be exactly 5 characters long and exist in the dictionary.
  • The init function is called exactly once before any calls to guess. Its parameters are num_scramble (the size of the dictionary) and scramble, which is a concatenation of all dictionary words (each word is 5 characters, no separators).

Additional files provided include header files and sample executables for testing (e.g. word.h, word_sample.cpp, play.cpp, etc.).

inputFormat

This is an interactive problem. You do not need to read any input from standard input. Instead, implement the functions as specified. The testing framework will call these functions with appropriate parameters.

outputFormat

This is an interactive problem. You do not need to write anything to standard output. Your solution is expected to implement the required functions correctly.

sample

num_testcase: 1
remaining_guesses: 5
initial_letter: a
(scramble string provided in init)
Return value from guess: "apple"