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.py19
1 files changed, 10 insertions, 9 deletions
diff --git a/prolog/problems/family_relations/descendant_2/common.py b/prolog/problems/family_relations/descendant_2/common.py
index d2a2dcb..4c7f8e3 100644
--- a/prolog/problems/family_relations/descendant_2/common.py
+++ b/prolog/problems/family_relations/descendant_2/common.py
@@ -29,6 +29,7 @@ hint_type = {
'descendant_of_oneself': Hint('ancestor_to_oneself'),
'descendant_need_not_be_parent': Hint('descendant_need_not_be_parent'),
'wrong_direction': Hint('wrong_direction'),
+ 'timeout': Hint('timeout'),
}
test_cases = [
@@ -84,28 +85,28 @@ def hint(code, aux_code):
# 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_truth(engine_id,
+ if prolog.engine.ask_truthTO(engine_id,
'parent(Y, X), \+ descendant(X, Y)'):
return [{'id': 'base_case'}]
# descendant of oneself
- if prolog.engine.ask_truth(engine_id, 'descendant(X, X)'):
+ if prolog.engine.ask_truthTO(engine_id, 'descendant(X, X)'):
return [{'id': 'descendant_of_oneself'}]
- # X does not necessarily need to be a parent
- if prolog.engine.ask_one(engine_id,
- 'descendant(X, _), \+ parent(X, _)') == 'false':
- return [{'id': 'descendant_need_not_be_parent'}]
-
# ancestor instead of descendant (wrong direction)
# warning: knowledge base dependent
- if prolog.engine.ask_truth(engine_id,
+ if prolog.engine.ask_truthTO(engine_id,
'findall(_, descendant(william, X), L1), length(L1, 6), \
findall(_, descendant(X, william), L2), length(L2, 2)'):
return [{'id': 'wrong_direction'}]
+ # X does not necessarily need to be a parent
+ if prolog.engine.ask_one(engine_id,
+ 'descendant(X, _), \+ parent(X, _)') == 'false':
+ return [{'id': 'descendant_need_not_be_parent'}]
+
except socket.timeout as ex:
- pass
+ return [{'id': 'timeout'}]
finally:
if engine_id: