Skip to main content

Module answer

Module answer 

Source
Expand description

Answer rules: how a submitted answer is judged.

An Answer is built from a constructor (exact, one_of, int, suffix, parts, exact_with) and refined with modifiers. The order in which a text rule judges an answer is part of the contract, because authors rely on it:

  1. normalize: strip surrounding whitespace (Python’s str.strip, so \x1c..\x1f count as whitespace too) and, with Answer::trim_trailing_slash, trailing /;
  2. literal mistakes (Answer::mistake): an exact match gives its tailored message;
  3. correct? If so, pass;
  4. computed feedback (Answer::feedback) for answers that cannot be listed literally, such as “starts with d but does not end with a”;
  5. the error text (Answer::error), or the terse messages::INCORRECT.

The default wrong-answer text is exactly Nesprávně. and never contains the answer: a hint about the answer belongs in a level’s hints, where the player asks for it.

Integer rules parse like Python’s int(text.strip()) ("+5", "1_000" and "007" are all numbers) and fail with Answer::invalid text otherwise.

Structs§

Answer
A rule that judges a submitted answer. See the module documentation.

Enums§

MistakeKey
What a literal mistake matches: text for text rules, an integer for int.

Functions§

exact
The answer must equal expected (after normalization).
exact_with
The answer must equal a value computed from the situation, such as the basename of the player’s $HOME, which is not known until the game runs.
int
The answer must be this integer, parsed like Python’s int().
one_of
The answer must equal one of the accepted values.
parts
The answer is several values joined by separator, each judged by its own rule (Python’s TupleAnswer). The text is split keeping empty items, each item is stripped, a wrong number of items fails with Answer::format_message, and otherwise the first failing part’s message wins.
suffix
The answer must equal expected or end with /expected, so a bare name and a path ending in it are both accepted.