У меня есть то, что, по-видимому, функционирует ASP-код, но он не возвращает никакого ответа? - PullRequest
0 голосов
/ 27 июня 2019

Я пытаюсь разгадать бинарную головоломку судоку с помощью программ набора ответов, клинго и MKAtoms.У меня есть рабочий набор кода, но он не возвращает наборы ответов.

Я рассмотрел код, но не уверен в проблеме.

% Binary Sudoku solver: Binary Sudoku is a similar puzzle to sudoku. 
% The rules are as follows
% 1. Each row and column must have the same number of 1's and 0's
% 2. Each row and column must be unique
% 3. Each number may not appear in consecutive triples
% 
% The program works in conjuction with python 3.6, Clingo, and     Mkatoms to create the required files and solve the user input puzzle.
%
% Required Files:
%   BinaryTemp.sm
%   BinaryOut.sm
%   BinaryPy.sm - This File
%
% Using the defined rules Clingo will attempt to find an answer set that will statisfy all conditions
num(0..1).
range(0..6).

% There may only be one number in each X,Y position

1{pos(N,X,Y):num(N)}1:-num(X), num(Y).

% Each row and column must have the same number of 1’s and 0’s

% Row check - check each rows sum to see if they hold the same number of 1's 
total_row(S) :- S = #sum{ N : pos(N,X,Y1), pos(N,X+1,Y1),           pos(N,X+2,Y1), pos(N,X+3,Y1), pos(N,X+4,Y1), pos(N,X+5,Y1)}.
total_row1(S) :- S = #sum{ N : pos(N,X,Y2), pos(N,X+1,Y2),  pos(N,X+2,Y2), pos(N,X+3,Y2), pos(N,X+4,Y2), pos(N,X+5,Y2)}.
:- total_row(S) != total_row1(S), range(S).

% Column Check
total_column(S) :- S = #sum{ N : pos(N,X1,Y), pos(N,X,Y+1),    pos(N,X1,Y+2), pos(N,X1,Y+3), pos(N,X1,Y+4), pos(N,X1,Y+5)}.
total_column1(S) :- S = #sum{ N : pos(N,X2,Y), pos(N,X2,Y+1), pos(N,X2,Y+2), pos(N,X2,Y+3), pos(N,X2,Y+4), pos(N,X2,Y+5)}.
:- total_column(S) != total_column1(S), range(S).

% Each row and column must be unique

% Row check - check if 2 values in seperate rows are different
different(X1,X2) :- pos(N1,X1,Y), pos(N2,X2,Y), N1!=N2.
:-pos(N,X1,Y), pos(N,X2,Y), X1!=X2, not different(X1,X2).

% Column check
different(Y1,Y2) :- pos(N1,X,Y1), pos(N2,X,Y2), N1!=N2.
:-pos(N,X,Y1), pos(N,X,Y2), Y1!=Y2, not different(Y1,Y2).

% Each number may not appear in consecutive triples

:-pos(N,X,Y), pos(N,X+1,Y), pos(N,X+2,Y), num(N).
:-pos(N,X,Y), pos(N,X,Y+2), pos(N,X,Y+2), num(N).

#show pos/3.

Входной файл:

  • pos (0,1,1).

  • pos (1,1,4).

  • pos (1,2,2).

  • pos (0,2,5).

  • pos (1,3,6).

  • pos (1,4,3).

  • pos (0,4,4).

  • pos (1,5,1).

  • pos (0,5,4).

  • pos (0,6,2).

  • pos (1,6,5).

Нет ошибок, но он должен возвращать позицииответы, соответствующие приведенным выше правилам.

...