Be aware that as guest, programs you create could be edited or deleted by anyone. Register
:- use_module(library(lists)).
operateur(I,F) :- gauche(I,F).
operateur(I,F) :- droite(I,F).
operateur(I,F) :- haut(I,F).
operateur(I,F) :- bas(I,F).
haut([L1,L2,L3],[NL1,NL2,L3]) :-
nth1(I,L2,x),
nth1(I,L1,El),
echange(I,El,x,L1,L2,NL1,NL2).
haut([L1,L2,L3],[L1,NL2,NL3]) :-
nth1(I,L3,x),
nth1(I,L2,El),
echange(I,El,x,L2,L3,NL2,NL3).
bas([L1,L2,L3],[NL1,NL2,L3]) :-
nth1(I,L1,x),
nth1(I,L2,El),
echange(I,El,x,L1,L2,NL1,NL2).
bas([L1,L2,L3],[L1,NL2,NL3]) :-
nth1(I,L2,x),
nth1(I,L3,El),
echange(I,El,x,L2,L3,NL2,NL3).
gauche([L1,L2,L3],[NL1,L2,L3]) :-
nth1(I,L1,x),
nth1(I,L1,El),
echange(I,El,x,L1,L1,NL1,NL1).
gauche([L1,L2,L3],[L1,NL2,L3]) :-
nth1(I,L2,x),
nth1(I,L2,El),
echange(I,El,x,L2,L2,NL2,NL2).
gauche([L1,L2,L3],[L1,L2,NL3]) :-
nth1(I,L3,x),
nth1(I,L3,El),
echange(I,El,x,L3,L3,NL3,NL3).
droite([L1,L2,L3],[NL1,L2,L3]) :-
nth1(I,L1,x),
nth1(I,L1,El),
echange(I,El,x,L1,L1,NL1,NL1).
droite([L1,L2,L3],[L1,NL2,L3]) :-
nth1(I,L2,x),
nth1(I,L2,El),
echange(I,El,x,L2,L2,NL2,NL2).
droite([L1,L2,L3],[L1,L2,NL3]) :-
nth1(I,L3,x),
nth1(I,L3,El),
echange(I,El,x,L3,L3,NL3,NL3).
echange(1, A, B, [A|R], [B|S], [B|R], [A|S]).
echange(2, A, B, [M,A|R], [P,B|S], [M,B|R], [P,A|S]). echange(3, A, B, [M,N,A|R], [P,Q,B|S], [M,N,B|R], [P,Q,A|S]).
taquin(X, X, CList, CList).
taquin(X, Y, CList, List) :-
operateur(X, Z),
\+member(Z, CList),
taquin(Z, Y, [Z | CList], List).
chemin(X, Y, CheminParcouru) :- taquin(X, Y, [X], CheminParcouru).
chemin([[1,2,3], [4,5,6], [7,x,8]], [[1,x,3], [4,2,6], [7,5,8]], X).