ajout aire case et changement du run

This commit is contained in:
Mylloon 2021-03-06 19:31:08 +01:00
parent 6fe582a7df
commit c73bb0f7fb

View file

@ -1,22 +1,31 @@
longueur(X) :- X.
largeur(X) :- X.
% zone noire
aire(X, Y, X, Y, 1) :- case(X, Y, 1).
aire(X1, Y1, X1, Y1, 1) :- write('blanc').
aire(X1, Y1, X2, Y2, N) :- X1, Y1, X2, Y2, N.
% zone blanche
aire(X1, Y1, X2, Y2, 0, T) :- case(X1, Y1, 0), NX is X1 + 1, aire(NX, Y1, X2, Y2, 0, T).
aire(X, Y1, X, Y2, 0, T) :- case(X, Y1, 0), NY is Y1 + 1, airereverse(X, NY, X, Y2, 0, T).
airereverse(X1, Y1, X2, Y2, 0, T) :- case(X1, Y1, 0), NX is X1 - 1, NX \= T, airereverse(NX, Y1, X2, Y2, 0, T);
NX = T, aire(NX, Y1, X2, Y2, 0, T).
run :- write('oui').
% zone
% aire(X1, Y1, X2, Y2, N, T) :- X1, Y1, X2, Y2, N, T.
% cellule
case(X, Y, C) :- write("Coordonnées: X="), write(X), write(", Y="), write(Y), write(". Couleur : "), write(C).
run([]) :- write('0: case blanc, 1: case noire').
run([[X1, Y1, X2, Y2, N] | Q]) :- T is X2 - X1, aire(X1, Y1, X2, Y2, N, T), run(Q).
/*
longueur(6).
largeur(6).
aire(0,0,1,1,2).
aire(2,0,2,2,-1).
aire(3,0,5,1,-1).
aire(0,2,0,4,-1).
aire(1,2,1,3,0).
aire(3,2,5,2,0).
aire(1,4,1,4,1).
aire(2,3,5,5,4).
aire(0,5,1,5,-1).
run.
run([[0,0,1,1,2],
[2,0,2,2,-1],
[3,0,5,1,-1],
[0,2,0,4,-1],
[1,2,1,3,0],
[3,2,5,2,0],
[1,4,1,4,1],
[2,3,5,5,4],
[0,5,1,5,-1]]).
*/