choices function
- TheoryOption right,
- List<
TheoryOption> errors, - List<
TheoryOption> others, - Random rng,
Os botões de uma pergunta: a certa e até três erradas diferentes dela (pelo
TheoryOption.id), na ordem do sorteio. Os erros do tópico (errors, os
comuns) entram primeiro, sorteados entre si; faltando, completam com
others.
Implementation
({List<TheoryOption> options, int correct}) choices(
TheoryOption right,
List<TheoryOption> errors,
List<TheoryOption> others,
Random rng,
) {
// Uma opção repetida é a mesma resposta, pelo id (a nota e a sua enarmônica)
// ou pelo texto (duas cifras que se escrevem igual).
final seen = {right.id, right.label};
final wrong = <TheoryOption>[];
final pools = [
[...errors]..shuffle(rng),
[...others]..shuffle(rng),
];
for (final pool in pools) {
for (final option in pool) {
if (wrong.length == 3) break;
if (seen.contains(option.id) || seen.contains(option.label)) continue;
seen.addAll([option.id, option.label]);
wrong.add(option);
}
}
final options = [right, ...wrong]..shuffle(rng);
return (options: options, correct: options.indexOf(right));
}