summaryrefslogtreecommitdiff
path: root/prolog/problems/family_relations
diff options
context:
space:
mode:
authorTimotej Lazar <timotej.lazar@fri.uni-lj.si>2016-01-05 18:36:37 +0100
committerTimotej Lazar <timotej.lazar@fri.uni-lj.si>2016-01-05 18:36:37 +0100
commit5902e5a5c40ec8fa32c7af8d4bcc57134a0bea66 (patch)
tree53b9aee47bbee39682a9c1a6c1ab0ef248a78389 /prolog/problems/family_relations
parentd6b6ab704d4552db052099fa2a7c9b7e9ff6a297 (diff)
Simplify Prolog hint functions
Diffstat (limited to 'prolog/problems/family_relations')
-rw-r--r--prolog/problems/family_relations/ancestor_2/common.py10
-rw-r--r--prolog/problems/family_relations/aunt_2/common.py10
-rw-r--r--prolog/problems/family_relations/brother_2/common.py10
-rw-r--r--prolog/problems/family_relations/cousin_2/common.py10
-rw-r--r--prolog/problems/family_relations/descendant_2/common.py10
-rw-r--r--prolog/problems/family_relations/father_2/common.py10
-rw-r--r--prolog/problems/family_relations/grandparent_2/common.py10
-rw-r--r--prolog/problems/family_relations/mother_2/common.py10
-rw-r--r--prolog/problems/family_relations/sister_2/common.py10
9 files changed, 27 insertions, 63 deletions
diff --git a/prolog/problems/family_relations/ancestor_2/common.py b/prolog/problems/family_relations/ancestor_2/common.py
index 48ea512..1a79f80 100644
--- a/prolog/problems/family_relations/ancestor_2/common.py
+++ b/prolog/problems/family_relations/ancestor_2/common.py
@@ -58,15 +58,11 @@ def test(code, aux_code):
hints = [{'id': 'test_results', 'args': {'passed': n_correct, 'total': len(test_cases)}}]
return passed, hints
-def hint(program, solved_problems):
- tokens = prolog.util.tokenize(program)
-
- code = (program + '\n' +
- server.problems.solutions_for_problems('prolog', solved_problems) + '\n' +
- server.problems.load_facts('prolog', facts).facts)
+def hint(code, aux_code):
+ tokens = prolog.util.tokenize(code)
try:
- engine_id, output = prolog.engine.create(code=code, timeout=1.0)
+ engine_id, output = prolog.engine.create(code=code+aux_code, timeout=1.0)
# gender testing is redundant
# this is not necessarily wrong, but worth mentioning anyway
diff --git a/prolog/problems/family_relations/aunt_2/common.py b/prolog/problems/family_relations/aunt_2/common.py
index 507460f..058f6f7 100644
--- a/prolog/problems/family_relations/aunt_2/common.py
+++ b/prolog/problems/family_relations/aunt_2/common.py
@@ -62,15 +62,11 @@ def test(code, aux_code):
hints = [{'id': 'test_results', 'args': {'passed': n_correct, 'total': len(test_cases)}}]
return passed, hints
-def hint(program, solved_problems):
- tokens = prolog.util.tokenize(program)
-
- code = (program + '\n' +
- server.problems.solutions_for_problems('prolog', solved_problems) + '\n' +
- server.problems.load_facts('prolog', facts).facts)
+def hint(code, aux_code):
+ tokens = prolog.util.tokenize(code)
try:
- engine_id, output = prolog.engine.create(code=code, timeout=1.0)
+ engine_id, output = prolog.engine.create(code=code+aux_code, timeout=1.0)
# X and Y mixed up
# warning: knowledge base dependent
diff --git a/prolog/problems/family_relations/brother_2/common.py b/prolog/problems/family_relations/brother_2/common.py
index 556d0e9..876e3bc 100644
--- a/prolog/problems/family_relations/brother_2/common.py
+++ b/prolog/problems/family_relations/brother_2/common.py
@@ -56,15 +56,11 @@ def test(code, aux_code):
hints = [{'id': 'test_results', 'args': {'passed': n_correct, 'total': len(test_cases)}}]
return passed, hints
-def hint(program, solved_problems):
- tokens = prolog.util.tokenize(program)
-
- code = (program + '\n' +
- server.problems.solutions_for_problems('prolog', solved_problems) + '\n' +
- server.problems.load_facts('prolog', facts).facts)
+def hint(code, aux_code):
+ tokens = prolog.util.tokenize(code)
try:
- engine_id, output = prolog.engine.create(code=code, timeout=1.0)
+ engine_id, output = prolog.engine.create(code=code+aux_code, timeout=1.0)
# X must be male
if prolog.engine.ask_truth(engine_id, 'female(X), brother(X, _)'):
diff --git a/prolog/problems/family_relations/cousin_2/common.py b/prolog/problems/family_relations/cousin_2/common.py
index 0f7a37d..eb75ca4 100644
--- a/prolog/problems/family_relations/cousin_2/common.py
+++ b/prolog/problems/family_relations/cousin_2/common.py
@@ -69,15 +69,11 @@ def test(code, aux_code):
hints = [{'id': 'test_results', 'args': {'passed': n_correct, 'total': len(test_cases)}}]
return passed, hints
-def hint(program, solved_problems):
- tokens = prolog.util.tokenize(program)
-
- code = (program + '\n' +
- server.problems.solutions_for_problems('prolog', solved_problems) + '\n' +
- server.problems.load_facts('prolog', facts).facts)
+def hint(code, aux_code):
+ tokens = prolog.util.tokenize(code)
try:
- engine_id, output = prolog.engine.create(code=code, timeout=1.0)
+ engine_id, output = prolog.engine.create(code=code+aux_code, timeout=1.0)
# gender testing is redundant
# this is not necessarily wrong, but worth mentioning anyway
diff --git a/prolog/problems/family_relations/descendant_2/common.py b/prolog/problems/family_relations/descendant_2/common.py
index f419b1d..3c2af16 100644
--- a/prolog/problems/family_relations/descendant_2/common.py
+++ b/prolog/problems/family_relations/descendant_2/common.py
@@ -58,15 +58,11 @@ def test(code, aux_code):
hints = [{'id': 'test_results', 'args': {'passed': n_correct, 'total': len(test_cases)}}]
return passed, hints
-def hint(program, solved_problems):
- tokens = prolog.util.tokenize(program)
-
- code = (program + '\n' +
- server.problems.solutions_for_problems('prolog', solved_problems) + '\n' +
- server.problems.load_facts('prolog', facts).facts)
+def hint(code, aux_code):
+ tokens = prolog.util.tokenize(code)
try:
- engine_id, output = prolog.engine.create(code=code, timeout=1.0)
+ engine_id, output = prolog.engine.create(code=code+aux_code, timeout=1.0)
# gender testing is redundant
# this is not necessarily wrong, but worth mentioning anyway
diff --git a/prolog/problems/family_relations/father_2/common.py b/prolog/problems/family_relations/father_2/common.py
index f5888de..40a0f1a 100644
--- a/prolog/problems/family_relations/father_2/common.py
+++ b/prolog/problems/family_relations/father_2/common.py
@@ -59,15 +59,11 @@ def test(code, aux_code):
hints = [{'id': 'test_results', 'args': {'passed': n_correct, 'total': len(test_cases)}}]
return passed, hints
-def hint(program, solved_problems):
- tokens = prolog.util.tokenize(program)
-
- code = (program + '\n' +
- server.problems.solutions_for_problems('prolog', solved_problems) + '\n' +
- server.problems.load_facts('prolog', facts).facts)
+def hint(code, aux_code):
+ tokens = prolog.util.tokenize(code)
try:
- engine_id, output = prolog.engine.create(code=code, timeout=1.0)
+ engine_id, output = prolog.engine.create(code=code+aux_code, timeout=1.0)
# OR (;) instead of AND (,)
# this hint has to be before the next two
diff --git a/prolog/problems/family_relations/grandparent_2/common.py b/prolog/problems/family_relations/grandparent_2/common.py
index 663c9e4..eaae7a5 100644
--- a/prolog/problems/family_relations/grandparent_2/common.py
+++ b/prolog/problems/family_relations/grandparent_2/common.py
@@ -60,15 +60,11 @@ def test(code, aux_code):
hints = [{'id': 'test_results', 'args': {'passed': n_correct, 'total': len(test_cases)}}]
return passed, hints
-def hint(program, solved_problems):
- tokens = prolog.util.tokenize(program)
-
- code = (program + '\n' +
- server.problems.solutions_for_problems('prolog', solved_problems) + '\n' +
- server.problems.load_facts('prolog', facts).facts)
+def hint(code, aux_code):
+ tokens = prolog.util.tokenize(code)
try:
- engine_id, output = prolog.engine.create(code=code, timeout=1.0)
+ engine_id, output = prolog.engine.create(code=code+aux_code, timeout=1.0)
# TODO: generic hint for:
# TODO: parent(X, Z1), parent(Z2, Y), Z1 = Z2
diff --git a/prolog/problems/family_relations/mother_2/common.py b/prolog/problems/family_relations/mother_2/common.py
index 0a4c7bf..95fd36a 100644
--- a/prolog/problems/family_relations/mother_2/common.py
+++ b/prolog/problems/family_relations/mother_2/common.py
@@ -60,15 +60,11 @@ def test(code, aux_code):
hints = [{'id': 'test_results', 'args': {'passed': n_correct, 'total': len(test_cases)}}]
return passed, hints
-def hint(program, solved_problems):
- tokens = prolog.util.tokenize(program)
-
- code = (program + '\n' +
- server.problems.solutions_for_problems('prolog', solved_problems) + '\n' +
- server.problems.load_facts('prolog', facts).facts)
+def hint(code, aux_code):
+ tokens = prolog.util.tokenize(code)
try:
- engine_id, output = prolog.engine.create(code=code, timeout=1.0)
+ engine_id, output = prolog.engine.create(code=code+aux_code, timeout=1.0)
# OR (;) instead of AND (,)
# this hint has to be before the next two
diff --git a/prolog/problems/family_relations/sister_2/common.py b/prolog/problems/family_relations/sister_2/common.py
index 90039e3..a6dff43 100644
--- a/prolog/problems/family_relations/sister_2/common.py
+++ b/prolog/problems/family_relations/sister_2/common.py
@@ -57,7 +57,7 @@ def test(code, aux_code):
hints = [{'id': 'test_results', 'args': {'passed': n_correct, 'total': len(test_cases)}}]
return passed, hints
-def hint(program, solved_problems):
+def hint(code, aux_code):
# how do I know which general hints were already shown?
# how do I know enough time has elapsed for general hints to be shown?
# how do I know whether the hint button was pressed?
@@ -83,14 +83,10 @@ def hint(program, solved_problems):
# tokenize (and similar) only if *needed* for a given exercise
# to reduce server processor load
- tokens = prolog.util.tokenize(program)
-
- code = (program + '\n' +
- server.problems.solutions_for_problems('prolog', solved_problems) + '\n' +
- server.problems.load_facts('prolog', facts).facts)
+ tokens = prolog.util.tokenize(code)
try:
- engine_id, output = prolog.engine.create(code=code, timeout=1.0)
+ engine_id, output = prolog.engine.create(code=code+aux_code, timeout=1.0)
# X must be female
if prolog.engine.ask_truth(engine_id, 'male(X), sister(X, _)'):