From 1b64321fda0bbf1f5a678671c1344eb2b87b5c74 Mon Sep 17 00:00:00 2001 From: Timotej Lazar Date: Thu, 10 Sep 2015 22:29:24 +0200 Subject: Use Hint classes for hints from the last commit Also move the language-specific hint method for Prolog to prolog.common. --- .../problems/family_relations/brother_2/common.py | 25 ++++++++++++++-------- prolog/problems/family_relations/brother_2/sl.py | 12 ++++------- 2 files changed, 20 insertions(+), 17 deletions(-) (limited to 'prolog/problems/family_relations/brother_2') diff --git a/prolog/problems/family_relations/brother_2/common.py b/prolog/problems/family_relations/brother_2/common.py index 41512e6..f2bfa15 100644 --- a/prolog/problems/family_relations/brother_2/common.py +++ b/prolog/problems/family_relations/brother_2/common.py @@ -1,5 +1,11 @@ # coding=utf-8 +import socket +import prolog.engine +import prolog.util +from server.hints import Hint, HintSequence +import server.problems + id = 97 group = 'family_relations' number = 4 @@ -14,10 +20,13 @@ brother(X, Y) :- X \== Y. ''' -import prolog.engine -import prolog.util -import server.problems -import socket +hint_defs = { + 'general_hint': HintSequence('general_hint', 3), + 'x_must_be_male': Hint('x_must_be_male'), + 'common_parent_needed': Hint('common_parent_needed'), + 'Y_can_be_of_any_gender': Hint('Y_can_be_of_any_gender'), + 'x_y_must_be_different': Hint('x_y_must_be_different'), +} def test(session, program): # TODO: change queries and answers (these are for sister/2) @@ -49,9 +58,6 @@ def test(session, program): return n_correct, len(queries) -def general_hint(): - pass - def hint(session, program): # tokens = prolog.util.tokenize(program) @@ -79,8 +85,9 @@ def hint(session, program): # X and Y must be different ans = prolog.engine.ask_one(engine_id, 'setof(X, (member(X, [william, alessandro, andrew]), brother(X, X)), L), length(L, N).') - if ans.get('N') == '3': - return [{'id': 'x_y_must_be_different'}] + # TODO this barfs if ans is 'false' + #if ans.get('N') == '3': + # return [{'id': 'x_y_must_be_different'}] except socket.timeout as ex: pass diff --git a/prolog/problems/family_relations/brother_2/sl.py b/prolog/problems/family_relations/brother_2/sl.py index f9db389..ad1d6c2 100644 --- a/prolog/problems/family_relations/brother_2/sl.py +++ b/prolog/problems/family_relations/brother_2/sl.py @@ -13,22 +13,18 @@ description = '''\ ''' hint = { - 'general_hint_1': '''\ + 'general_hint': ['''\

-''', - - 'general_hint_2': '''\ +''', '''\

-''', - - 'general_hint_3': '''\ +''', '''\

 parent(P, X)
 parent(P, Y)
 male(X)
 
-''', +'''], 'x_y_must_be_different': '''\

Si pomislil, da sta X in Y lahko ista oseba? Poskusi naslednjo poizvedbo:

-- cgit v1.2.1