Every game asks exactly three questions: your program prints a question, reads the answer, and after the third answer guesses without trying to read anything more. Print each question before you read — a program that reads silently, or asks a fourth question, fails this check.
Within one game, no question is asked twice — there’s no information in an answer you already have.
Across the eight possible games, your program asks seven different questions: one first question, a second question for each answer to the first, and a third question for each combination of the first two answers. If two of those are the same, some later question isn’t really using an answer it was given. (Differences only in capitalization or spacing don’t count as different.)
After the third answer, every game ends with your program printing its
guess as a line starting with I guess. (Capitalization and
spacing don’t matter, but the prefix does — it’s how the tests find
your guess.) A guess after only two questions doesn’t count.
The eight paths produce eight different I guess lines.
(Differences only in capitalization or spacing don’t count as
different.)
You probably know the game 20 Questions: one player thinks of something and the other tries to guess it by asking up to twenty yes/no questions. In this assignment you’re going to write a program to play the guesser in a much simpler game: 3 Questions.
Your program should ask three yes/no questions, and then announce its
guess with a line that starts with I guess — for example,
I guess a dog!. That prefix is how the tests pick your guess
out from anything else your program prints, so you’re free to print a
welcome message before the questions or a “play again?” line after the
guess. After each question, read the player’s answer with
IO.readln(); the tests always answer with exactly a
capital Y or N. (Whether your program also
accepts y, yes, etc. from a human player is up
to you.)
You can play your own game any time: click ▶ Run and type your answers in the terminal on the right. That’s the best way to build it — make the first question work, play it, then grow the tree.
The key to playing well: each question should depend on the answers so far. If “Is it an animal?” gets a Y, the natural follow-up is something like “Is it a mammal?” — but after an N you’d want a completely different question. There’s no information in a question whose answer you can already predict. So a full game is a tree: one first question, two possible second questions (one for each answer to the first), and four possible third questions — seven different questions in all, leading to 2 × 2 × 2 = 8 different final guesses.
That’s also the shape of the code: an if/else
on the first answer, each side asking its own second question and
containing its own if/else, and so on. The code
will get repetitive — that’s okay for now.
When you want to check your work, switch to the Tests tab on the
right and click â–¶ Run again. The tests play all eight games against your
program, answering Y Y Y, then Y Y N, and so on
through N N N. When a test fails, the “got” column shows the
whole conversation, with the answers your program was given marked with
«.