i have a square with start and finish points, also places where i can’t go. And my program must find a way to reach finish:
ar_galima([], _, _):-!.
ar_galima([Prad|Galas],Kelias, X) :- not(Prad == X), not(member(X, Kelias)), ar_galima(Galas, Kelias, X).
gener(Stac_M, Stac_K, k(A,B), k(Y,B)) :- Y is A + 1, Y > 0, Y =< Stac_M, B =< Stac_K.
gener(Stac_M, Stac_K, k(A,B), k(Y,B)) :- Y is A - 1, Y > 0, Y =< Stac_M, B =< Stac_K.
gener(Stac_M, Stac_K, k(A,B), k(A,Y)) :- Y is B + 1, Y > 0, Y =< Stac_K, A =< Stac_M.
gener(Stac_M, Stac_K, k(A,B), k(A,Y)) :- Y is B - 1, Y > 0, Y =< Stac_K, A =< Stac_M.
paieska(_, _,_,Tikslas,Tikslas,[], _):-!.
paieska(Stac_M, Stac_K, Draudziama, Prad, Tikslas, [K|Kelias], Kelias2) :-
gener(Stac_M, Stac_K, Prad, K), ar_galima(Draudziama, Kelias2, K),
paieska(Stac_M, Stac_K, Draudziama, K, Tikslas, Kelias, [K|Kelias2]).
trasa(Ilgis, Aukstis, Draudziama, k(X,Y), Tikslas, Kelias) :-
paieska(Ilgis,Aukstis, Draudziama, k(X,Y), Tikslas,Kelias, []).
i find routes to finish and now i’m stuck outputing the route (a list) into 2 dimension table in terminal (well, a simple graphic show of the route).
example of list to output:X = [k(2, 1), k(3, 1), k(4, 1), k(4, 2), k(4, 3), k(4, 4)] ;
Could someone suggesst me how should i output a 2 dimension table into terminal?
EDIT:
X should be printed:
+ + + *
+ + + *
+ + + *
+ * * *
print perdicate could look like this:
printTable(N, M, X) :- …
where N is number of rows, M is number of columns and X is list of coordinates.
You can do it with something like this: