}
}
}
private PossibleAnswers generatePossibleAnswers(Piece piece) {
PossibleAnswers answers = new PossibleAnswers();
// first select the instrument distractors
int instrument = piece.getMainInstrument();
List<Instrument> instruments = new ArrayList<>(ANSWERS_PER_QUESTION);
instruments.add(new Instrument(instrument, InstrumentNameExtractor.getInstrumentName(instrument)));
while (instruments.size() < ANSWERS_PER_QUESTION) {
int[] set = random.nextBoolean() ? InstrumentGroups.MAIN_PART_INSTRUMENTS : InstrumentGroups.MAIN_PART_ONLY_INSTRUMENTS;
int selectedId = set[random.nextInt(set.length)];
Instrument newInstrument = new Instrument(selectedId, InstrumentNameExtractor.getInstrumentName(selectedId));
if (selectedId != instrument && !instruments.contains(newInstrument)) {
instruments.add(newInstrument);
}
}
Collections.shuffle(instruments, random);
answers.setInstruments(instruments);
// fill the metre distractors
List<Metre> metres = new ArrayList<>(ANSWERS_PER_QUESTION);
metres.add(new Metre(piece.getMetreNumerator(), piece.getMetreDenominator()));
while (metres.size() < ANSWERS_PER_QUESTION) {
int[] metre = MetreConfigurer.getRandomMetre(random);
// disallow metres that have the same ratios as the correct answer
Metre newMetre = new Metre(metre[0], metre[1]);
if (!metres.contains(newMetre) && isNotDerivedMetre(piece, metre)) {
metres.add(newMetre);
}
}
Collections.shuffle(metres, random);
answers.setMetres(metres);
return answers;
}