From cfbd840591f3b334790ab22daa3cb7b9c49ebc9c Mon Sep 17 00:00:00 2001 From: Aleksander Sadikov Date: Wed, 2 Mar 2016 01:36:02 +0100 Subject: Improved hints for ancestor/2 and descendant/2. --- prolog/problems/family_relations/descendant_2/common.py | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) (limited to 'prolog/problems/family_relations/descendant_2/common.py') diff --git a/prolog/problems/family_relations/descendant_2/common.py b/prolog/problems/family_relations/descendant_2/common.py index 4c7f8e3..70936da 100644 --- a/prolog/problems/family_relations/descendant_2/common.py +++ b/prolog/problems/family_relations/descendant_2/common.py @@ -27,9 +27,11 @@ hint_type = { 'grandparent_used_markup': HintPopup('grandparent_used_markup'), 'base_case': Hint('base_case'), 'descendant_of_oneself': Hint('ancestor_to_oneself'), + 'descendant_of_oneself_with_or': Hint('descendant_of_oneself_with_or'), 'descendant_need_not_be_parent': Hint('descendant_need_not_be_parent'), 'wrong_direction': Hint('wrong_direction'), 'timeout': Hint('timeout'), + 'final_hint': Hint('final_hint'), } test_cases = [ @@ -58,6 +60,10 @@ def test(code, aux_code): prolog.engine.destroy(engine_id) hints = [{'id': 'test_results', 'args': {'passed': n_correct, 'total': len(test_cases)}}] + if n_correct == len(test_cases): + tokens = prolog.util.tokenize(code) + if prolog.util.Token('NAME', 'ancestor') not in tokens: + hints += [{'id': 'final_hint'}] return n_correct, len(test_cases), hints def hint(code, aux_code): @@ -83,15 +89,16 @@ def hint(code, aux_code): [{'id': 'grandparent_used'}] # missing/failed base case - # TODO: how will ask_truth handle/return timeouts... - # TODO: timeout is the same as fail in this particular case if prolog.engine.ask_truthTO(engine_id, 'parent(Y, X), \+ descendant(X, Y)'): return [{'id': 'base_case'}] # descendant of oneself if prolog.engine.ask_truthTO(engine_id, 'descendant(X, X)'): - return [{'id': 'descendant_of_oneself'}] + if prolog.util.Token('SEMI', ';') in tokens: + return [{'id': 'descendant_of_oneself_with_or'}] + else: + return [{'id': 'descendant_of_oneself'}] # ancestor instead of descendant (wrong direction) # warning: knowledge base dependent -- cgit v1.2.1