I have a 5x5 grid which is described by max_size(5, 5)
. I need to generate a list of all cells from that description using DCG.
Here's the code I have so far:
:- use_module(library(clpfd)).
map_size(5, 5).
natnum(0).
natnum(X) :-
X #= X0 + 1,
natnum(X0).
list_all_cells(Visited) -->
{ length(Visited, 25) },
[].
list_all_cells(Visited) -->
[X-Y],
{ map_size(X_max, Y_max),
natnum(X), natnum(Y),
X #< X_max, Y #< Y_max,
maplist(dif(X-Y), Visited) },
list_all_cells([X-Y|Visited]).
However, it doesn't generate a list and outputs only 4 pairs.
A possible query to the DCG looks like list_all_cells([])
which is supposed to list all cells on the grid. For example, it's gonna be [0-0, 1-0, 1-1, 0-1]
for a 2x2 grid (order doesn't matter).
In fact, I need this predicate to build another one called available_steps/2
that would generate a list of all possible moves for a given position. Having available_steps(CurrentPos, Visited)
, I will be able to brute-force Hunt the Wumpus
game and find all possible routes to gold.