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:
- normalize: strip surrounding whitespace (Python’s
str.strip, so\x1c..\x1fcount as whitespace too) and, withAnswer::trim_trailing_slash, trailing/; - literal mistakes (
Answer::mistake): an exact match gives its tailored message; - correct? If so, pass;
- computed feedback (
Answer::feedback) for answers that cannot be listed literally, such as “starts withdbut does not end witha”; - the error text (
Answer::error), or the tersemessages::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§
- Mistake
Key - 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’sTupleAnswer). The text is split keeping empty items, each item is stripped, a wrong number of items fails withAnswer::format_message, and otherwise the first failing part’s message wins. - suffix
- The answer must equal
expectedor end with/expected, so a bare name and a path ending in it are both accepted.