diff options
Diffstat (limited to 'prolog/problems/denotational_semantics/prog_8puzzle_2')
-rw-r--r-- | prolog/problems/denotational_semantics/prog_8puzzle_2/common.py | 39 | ||||
-rw-r--r-- | prolog/problems/denotational_semantics/prog_8puzzle_2/sl.py | 16 |
2 files changed, 55 insertions, 0 deletions
diff --git a/prolog/problems/denotational_semantics/prog_8puzzle_2/common.py b/prolog/problems/denotational_semantics/prog_8puzzle_2/common.py index 22429cc..7f78fec 100644 --- a/prolog/problems/denotational_semantics/prog_8puzzle_2/common.py +++ b/prolog/problems/denotational_semantics/prog_8puzzle_2/common.py @@ -1,3 +1,10 @@ +from operator import itemgetter +import socket + +import prolog.engine +import prolog.util +from server.hints import Hint, HintPopup + id = 172 number = 30 visible = True @@ -14,3 +21,35 @@ instr172 --> [right]. instr172 --> [up]. instr172 --> [down]. ''' + +test_cases = [ + ('findall(W, (W = [_], prog_8puzzle(W, [])), Words), Words == []', + [{}]), + ('setof(W, [A,B,C]^(W = [A,B,C], prog_8puzzle(W, [])), Words), \ + Words == [[begin,down,end],[begin,left,end],[begin,right,end],[begin,up,end]]', + [{}]), + ('setof(W, [A,B,C,D]^(W = [A,B,C,D], prog_8puzzle(W, [])), Words), length(Words, 16)', + [{}]), + ('prog_8puzzle([begin,down,down,up,up,left,left,right,end], [])', + [{}]), +] + +def test(code, aux_code): + n_correct = 0 + engine_id = None + try: + engine_id, output = prolog.engine.create(code=code+aux_code, timeout=1.0) + if engine_id is not None and 'error' not in map(itemgetter(0), output): + # Engine successfully created, and no syntax error in program. + for query, answers in test_cases: + if prolog.engine.check_answers(engine_id, query=query, answers=answers, timeout=1.0): + n_correct += 1 + except socket.timeout: + pass + finally: + if engine_id: + prolog.engine.destroy(engine_id) + + hints = [{'id': 'test_results', 'args': {'passed': n_correct, 'total': len(test_cases)}}] + return n_correct, len(test_cases), hints + diff --git a/prolog/problems/denotational_semantics/prog_8puzzle_2/sl.py b/prolog/problems/denotational_semantics/prog_8puzzle_2/sl.py new file mode 100644 index 0000000..0e5ad88 --- /dev/null +++ b/prolog/problems/denotational_semantics/prog_8puzzle_2/sl.py @@ -0,0 +1,16 @@ +name = 'prog_8puzzle/2' +slug = 'jezik za reševanje igre Osem' + +description = '''\ +<p> +Napiši DCG za jezik igre Osem (angl. 8-puzzle). Prvi simbol vsake besede je simbol <code>[begin]</code>, temu pa +sledi poljubno zaporedje "ukazov" iz nabora {<code>left</code>, <code>right</code>, <code>up</code> <code>down</code>}, +na koncu pa je simbol <code>[end]</code>. Začetni nekončni simbol naj se imenuje <code>prog_8puzzle</code>. +</p> + +<p> +Primeri veljavnih besed: <code>[begin,left,down,right,end]</code>, <code>[begin,down,end]</code>. +</p> +''' + +hint = {} |