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/ancestor_2/common.py | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) (limited to 'prolog/problems/family_relations/ancestor_2/common.py') diff --git a/prolog/problems/family_relations/ancestor_2/common.py b/prolog/problems/family_relations/ancestor_2/common.py index 6690e00..9346e5f 100644 --- a/prolog/problems/family_relations/ancestor_2/common.py +++ b/prolog/problems/family_relations/ancestor_2/common.py @@ -27,8 +27,10 @@ hint_type = { 'grandparent_used_markup': HintPopup('grandparent_used_markup'), 'base_case': Hint('base_case'), 'ancestor_to_oneself': Hint('ancestor_to_oneself'), + 'ancestor_to_oneself_with_or': Hint('ancestor_to_oneself_with_or'), 'descendant_need_not_be_parent': Hint('descendant_need_not_be_parent'), 'wrong_direction': Hint('wrong_direction'), + 'only_two_levels_deep': Hint('only_two_levels_deep'), 'timeout': Hint('timeout'), } @@ -83,15 +85,23 @@ 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, 'findall(X/Y, parent(X, Y), L), member(X/Y, L), \+ ancestor(X, Y)'): return [{'id': 'base_case'}] + # two levels deep relation (up to grandparent) only + # warning: knowledge base dependent + if prolog.engine.ask_truthTO(engine_id, + 'findall(_, ancestor(X, Y), L1), length(L1, 23) ; \ + findall(_, ancestor(X, Y), L2), length(L2, 55)'): + return [{'id': 'only_two_levels_deep'}] + # ancestor to oneself if prolog.engine.ask_truthTO(engine_id, 'ancestor(X, X)'): - return [{'id': 'ancestor_to_oneself'}] + if prolog.util.Token('SEMI', ';') in tokens: + return [{'id': 'ancestor_to_oneself_with_or'}] + else: + return [{'id': 'ancestor_to_oneself'}] # descendant instead of ancestor (wrong direction) # warning: knowledge base dependent -- cgit v1.2.1