diff options
author | Aleksander Sadikov <aleksander.sadikov@fri.uni-lj.si> | 2016-02-29 00:27:21 +0100 |
---|---|---|
committer | Aleksander Sadikov <aleksander.sadikov@fri.uni-lj.si> | 2016-02-29 00:27:21 +0100 |
commit | 90dbc3fa624d62e093bea7b90a72a28ad216f7bd (patch) | |
tree | ebefd97dcb67bd3e106a38a4c78c1a4337d17dfd /prolog | |
parent | 0891683712b8f4206a83c200e6ad3df283a64a75 (diff) |
Additional improvements to hints for mother, father, grandparent, sister, and brother problems.
Diffstat (limited to 'prolog')
4 files changed, 16 insertions, 16 deletions
diff --git a/prolog/problems/family_relations/brother_2/common.py b/prolog/problems/family_relations/brother_2/common.py index 0ad74c3..87f27a3 100644 --- a/prolog/problems/family_relations/brother_2/common.py +++ b/prolog/problems/family_relations/brother_2/common.py @@ -65,6 +65,10 @@ def hint(code, aux_code): try: engine_id, output = prolog.engine.create(code=code+aux_code, timeout=1.0) + # target predicate seems to always be false + if not prolog.engine.ask_truth(engine_id, 'brother(_, _)'): + return [{'id': 'predicate_always_false'}] + # X must be male if prolog.engine.ask_truth(engine_id, 'female(X), brother(X, _)'): return [{'id': 'x_must_be_male'}] @@ -83,10 +87,6 @@ def hint(code, aux_code): if prolog.util.Token('NEQU', '\=') in tokens or prolog.util.Token('NEQA', '=\=') in tokens: return [{'id': 'neq+_instead_of_neq'}] - # target predicate seems to always be false - if prolog.engine.ask_one(engine_id, 'brother(_, _)') == 'false': - return [{'id': 'predicate_always_false'}] - # X and Y must be different if prolog.util.Token('NEQ', '\==') not in tokens and prolog.engine.ask_truth(engine_id, 'setof(X, (member(X, [william, alessandro, andrew]), brother(X, X)), L), length(L, 3)'): diff --git a/prolog/problems/family_relations/father_2/common.py b/prolog/problems/family_relations/father_2/common.py index 11f0742..31109c9 100644 --- a/prolog/problems/family_relations/father_2/common.py +++ b/prolog/problems/family_relations/father_2/common.py @@ -67,6 +67,10 @@ def hint(code, aux_code): try: engine_id, output = prolog.engine.create(code=code+aux_code, timeout=1.0) + # target predicate seems to always be false + if not prolog.engine.ask_truth(engine_id, 'father(_, _)'): + return [{'id': 'predicate_always_false'}] + # OR (;) instead of AND (,) # this hint has to be before the next two # as otherwise those two would always override it @@ -102,10 +106,6 @@ def hint(code, aux_code): prolog.engine.ask_one(engine_id, 'father(_, Y), \+ parent(Y, _)') == 'false': return [{'id': 'y_need_not_be_parent'}] - # target predicate seems to always be false - if prolog.engine.ask_one(engine_id, 'father(_, _)') == 'false': - return [{'id': 'predicate_always_false'}] - except socket.timeout as ex: pass diff --git a/prolog/problems/family_relations/mother_2/common.py b/prolog/problems/family_relations/mother_2/common.py index 1bb7a4b..a7da458 100644 --- a/prolog/problems/family_relations/mother_2/common.py +++ b/prolog/problems/family_relations/mother_2/common.py @@ -68,6 +68,10 @@ def hint(code, aux_code): try: engine_id, output = prolog.engine.create(code=code+aux_code, timeout=1.0) + # target predicate seems to always be false + if not prolog.engine.ask_truth(engine_id, 'mother(_, _)'): + return [{'id': 'predicate_always_false'}] + # OR (;) instead of AND (,) # this hint has to be before the next two # as otherwise those two would always override it @@ -103,10 +107,6 @@ def hint(code, aux_code): prolog.engine.ask_one(engine_id, 'mother(_, Y), \+ parent(Y, _)') == 'false': return [{'id': 'y_need_not_be_parent'}] - # target predicate seems to always be false - if prolog.engine.ask_one(engine_id, 'mother(_, _)') == 'false': - return [{'id': 'predicate_always_false'}] - except socket.timeout as ex: pass diff --git a/prolog/problems/family_relations/sister_2/common.py b/prolog/problems/family_relations/sister_2/common.py index 1234985..2be3ab3 100644 --- a/prolog/problems/family_relations/sister_2/common.py +++ b/prolog/problems/family_relations/sister_2/common.py @@ -91,6 +91,10 @@ def hint(code, aux_code): try: engine_id, output = prolog.engine.create(code=code+aux_code, timeout=1.0) + # target predicate seems to always be false + if not prolog.engine.ask_truth(engine_id, 'sister(_, _)'): + return [{'id': 'predicate_always_false'}] + # X must be female if prolog.engine.ask_truth(engine_id, 'male(X), sister(X, _)'): return [{'id': 'x_must_be_female'}] @@ -112,10 +116,6 @@ def hint(code, aux_code): if prolog.util.Token('NEQU', '\=') in tokens or prolog.util.Token('NEQA', '=\=') in tokens: return [{'id': 'neq+_instead_of_neq'}] - # target predicate seems to always be false - if prolog.engine.ask_one(engine_id, 'sister(_, _)') == 'false': - return [{'id': 'predicate_always_false'}] - # X and Y must be different # this is the last code-specific hint (when everything else doesn't trigger anymore) if prolog.util.Token('NEQ', '\==') not in tokens and prolog.engine.ask_truth(engine_id, |