Add variable question distractor pools
This commit is contained in:
@@ -30,6 +30,8 @@ func start_block(selected_system: String, block_size: int, selected_mode: String
|
||||
mode = selected_mode
|
||||
session_kind = "block"
|
||||
active_questions = QuestionBankService.build_block(selected_system, block_size)
|
||||
for index in range(active_questions.size()):
|
||||
active_questions[index] = _prepare_question_choices(active_questions[index])
|
||||
answers.clear()
|
||||
answers.resize(active_questions.size())
|
||||
current_index = 0
|
||||
@@ -293,10 +295,38 @@ func _draw_core_question() -> Dictionary:
|
||||
var candidate: Dictionary = core_question_pool[index]
|
||||
if str(candidate.get("id", "")) != last_id or core_question_pool.size() == 1:
|
||||
core_question_pool.remove_at(index)
|
||||
return candidate.duplicate(true)
|
||||
return _prepare_question_choices(candidate.duplicate(true))
|
||||
return {}
|
||||
|
||||
|
||||
func _prepare_question_choices(question: Dictionary) -> Dictionary:
|
||||
var existing: Array = question.get("presented_choices", [])
|
||||
if not existing.is_empty():
|
||||
return question
|
||||
|
||||
var all_choices: Array = question.get("choices", []).duplicate(true)
|
||||
var correct_id := str(question.get("correct_choice_id", ""))
|
||||
var correct_choice: Dictionary = {}
|
||||
var distractors: Array = []
|
||||
for choice in all_choices:
|
||||
if typeof(choice) != TYPE_DICTIONARY:
|
||||
continue
|
||||
if str(choice.get("id", "")) == correct_id:
|
||||
correct_choice = choice
|
||||
else:
|
||||
distractors.append(choice)
|
||||
|
||||
distractors.shuffle()
|
||||
var presented: Array = distractors.slice(0, min(4, distractors.size()))
|
||||
if not correct_choice.is_empty():
|
||||
presented.append(correct_choice)
|
||||
elif not all_choices.is_empty():
|
||||
presented = all_choices.slice(0, min(5, all_choices.size()))
|
||||
presented.shuffle()
|
||||
question["presented_choices"] = presented
|
||||
return question
|
||||
|
||||
|
||||
func _build_core_question_pool() -> Array:
|
||||
var pool: Array = []
|
||||
var profile := ProfileService.get_profile()
|
||||
|
||||
Reference in New Issue
Block a user