summaryrefslogtreecommitdiff
path: root/server
diff options
context:
space:
mode:
Diffstat (limited to 'server')
-rw-r--r--server/prolog_session.py20
1 files changed, 20 insertions, 0 deletions
diff --git a/server/prolog_session.py b/server/prolog_session.py
index 7e0af90..1a76130 100644
--- a/server/prolog_session.py
+++ b/server/prolog_session.py
@@ -15,8 +15,11 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import operator
+import os.path
+import pickle
import threading
+import monkey
import prolog.engine
import server
import server.user_session
@@ -127,6 +130,15 @@ class PrologSession(server.LanguageSession):
if not hints and hasattr(problem_module, 'hint'):
hints = problem_module.hint(program, solved_problems)
if not hints:
+ # Testing function for monkey.
+ def tester(code):
+ passed, hints = problem_module.test(code, solved_problems)
+ return passed
+ solution, steps, fix_time, n_tested = monkey.fix(
+ program, _edits[problem_id], tester, timeout=5, debug=True)
+ if solution and steps:
+ hints = [{'id': 'monkey_main'}] + monkey.fix_hints(program, steps)
+ if not hints:
hints = [{'id': 'no_hint'}]
except Exception as ex:
hints = [{'id': 'system_error', 'args': {'message': str(ex)}}]
@@ -186,3 +198,11 @@ class PrologSession(server.LanguageSession):
return messages, status, have_more
server.language_session_handlers['prolog'] = lambda user_session, problem_id, language_identifier, group_identifier, problem_identifier: PrologSession()
+
+try:
+ _edits, _submissions, _queries = pickle.load(
+ open(os.path.join(os.path.dirname(os.path.realpath(__file__)), '..', 'edits.pickle'), 'rb'))
+except:
+ _edits = {}
+ _submissions = {}
+ _queries = {}