I'm doing a Prolog project for uni that's based on the Kakuro game.
I'm having trouble with the predicate spaces_puzzle/2
that does the following:
- Receives the Puzzle in the form of a list of lists that represents each file of the puzzle:
[[[sum_vertical, sum_horizontal], P11, P12, [sum_vertical, sum_horizontal],P13, P14...],
[[sum_vertical, sum_horizontal], P21, P22, P23, P24, ...],
[[sum_vertical, sum_horizontal], P31, P32, P33, P34, P35 ...],
...]
- and returns a list like this
[space(sum_horizontal, [P11,P12]), space(sum_horizontal, [P13,P14]), space(sum_horizontal, [P21,P22,P23,P24]) ...]
I was thinking of using a maplist
with a predicate that I have already defined as spaces_in_file/3
which will read a list like [[sum_vertical, sum_horizontal], P11, P12, [sum_vertical, sum_horizontal],P13, P14...]
and output in the wanted formatting: [space(sum_horizontal, [P11,P12]), space(sum_horizontal, [P13,P14])...]
I don't understand the syntax for the predicate. The "Goal" I want is the spaces_in_file/3
. spaces_in_file(H_V, File, Spaces)
is a simple bagof
where H_V
is a character that says which of the sums I should use, File
is the file I want to check for the spaces, and Spaces
is my output.
So should it be something like this:
spaces_puzzle(Puzzle, Spaces):-
maplist(spaces_in_file(h, File, Spaces), Puzzle, File)
I want my file to be one of the lists of the Puzzle. I can't seem to get the syntax right.
For now I just want the correct Result for the files, I can easily adapt to get the columns with the transpose/2
predicate which is suggested by the professors.
Appreciate any advice!