summaryrefslogtreecommitdiff
path: root/prolog/problems/family_relations/descendant_2/common.py
diff options
context:
space:
mode:
Diffstat (limited to 'prolog/problems/family_relations/descendant_2/common.py')
-rw-r--r--prolog/problems/family_relations/descendant_2/common.py13
1 files changed, 10 insertions, 3 deletions
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