Canibales vs misioneros

Solo disponible en BuenasTareas
  • Páginas : 2 (360 palabras )
  • Descarga(s) : 7
  • Publicado : 20 de junio de 2010
Leer documento completo
Vista previa del texto
inicio( rio( [0,0,3,3] , d ) ).
fin( rio( [3,3,0,0] , i ) ).

regla( unMalaI , rio( [ X , Y , Z , W ] , d ) , rio( [ M , Y , N , W ] , i ) ) :-
Z > 0, M is (X+1) , N is (Z-1).regla( unCalaI , rio( [ X , Y , Z , W ] , d ) , rio( [ X , M , Z , N ] , i ) ) :-
W > 0, M is Y+1 , N is W-1.

regla( unMalaD , rio( [ X , Y , Z , W ] , i ) , rio( [ M , Y , N , W ] , d ) ):-
X > 0 , M is X-1 , N is Z+1.

regla( unCalaD , rio( [ X , Y , Z , W ] , i ) , rio( [ X , M , Z , N ] , d ) ) :-
Y > 0 , M is Y-1 , N is W+1.

regla( dosMalaI , rio( [ X , Y ,Z , W ] , d ) , rio( [ M , Y , N , W ] , i ) ) :-
Z > 1 , M is X+2 , N is Z-2.

regla( dosCalaI , rio( [ X , Y , Z , W ] , d ) , rio( [ X , M , Z , N ] , i ) ) :-
W > 1, M is Y+2, N is W-2.

regla( dosMalaD , rio( [ X , Y , Z , W ] , i ) , rio( [ M , Y , N , W ] , d ) ) :-
X > 1 , M is X-2 , N is Z+2.

regla( dosCalaD , rio( [ X , Y , Z , W ] , i ) , rio( [X , M , Z , N ] , d ) ) :-
Y > 1, M is Y-2 , N is W+2.

regla( unoYunoI , rio( [ X , Y , Z , W ] , d ) , rio( [ M , N , O , P ] , i ) ) :-
Z > 0 , W > 0 , M is X+1 , N is Y+1, O isZ-1 , P is W-1.

regla( unoYunoD , rio( [ X , Y , Z , W ] , i ) , rio( [ M , N , O , P ] , d ) ) :-
Z > 0 , Y > 0 , M is X-1 , N is Y-1, O is Z+1 , P is W+1.

mueve( ED , ED , R , []) :- !.

mueve( ED1 , ED3 , R2 , [ N | R ] ) :-
regla( N , ED1 , ED2 ),
checaRestriccion( ED2 ),
not( member( ED2 , R2 ) ),
mueve( ED2 , ED3 , [ED2|R2] , R ).

imprimeRuta( []).

imprimeRuta( [ X | R ] ):-
print( X ),
print( ' ' ),
imprimeRuta( R ).

noes(P):- P , ! , fail .
noes(P).

member( X , [ X | _ ] ).
member( X , [ Y | R ] ):-
member( X ,R ).

checaRestriccion( rio([X,Y,Z,W],B) ):-
X >= Y , Z >= W.

checaRestriccion( rio([X,Y,Z,W],B) ):-
X = 0 , Z >= W.

checaRestriccion( rio([X,Y,Z,W],B) ) :-
Z = 0 , X >= Y.
tracking img