This repository has been archived on 2022-03-31. You can view files and clone it, but cannot push or open issues or pull requests.
heyawake-prolog/resolveur.pl

31 lines
929 B
Prolog

% zone noire
aire(X, Y, X, Y, 1) :- case(X, Y, 1).
% 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).
% 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).
/*
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]]).
*/