-
Notifications
You must be signed in to change notification settings - Fork 0
/
programa1.1.pl
86 lines (75 loc) · 1.64 KB
/
programa1.1.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
:- dynamic mina/2.
inicio :-
open('ambiente.pl', write, String),
['mina'],
anda(1, 1, String),
close(String),
halt.
tamanho(TAM) :- TAM is 3.
checa_casa(I, J, left) :-
J1 is J - 1,
mina(I, J1).
checa_casa(I, J, right) :-
J1 is J + 1,
mina(I, J1).
checa_casa(I, J, bottom) :-
I1 is I + 1,
mina(I1, J).
checa_casa(I, J, top) :-
I1 is I - 1,
mina(I1, J).
checa_casa(I, J, topright) :-
I1 is I - 1,
J1 is J + 1,
mina(I1, J1).
checa_casa(I, J, bottomright) :-
I1 is I + 1,
J1 is J + 1,
mina(I1, J1).
checa_casa(I, J, topleft) :-
I1 is I - 1,
J1 is J - 1,
mina(I1, J1).
checa_casa(I, J, bottomleft) :-
I1 is I + 1,
J1 is J - 1,
mina(I1, J1).
anda(I, J, String) :-
not(mina(I,J)),
!,
findall(X, checa_casa(I,J,X), Z),
length(Z, K),
swritef(Aux, 'valor(%d,%d,%d).\n', [I, J, K]),
write(String, Aux),
proxima_casa(I, J, N_I, N_J),
quebra_linha(I, N_I, String),
anda(N_I, N_J, String).
anda(I, J, String) :-
proxima_casa(I, J, N_I, N_J),
quebra_linha(I, N_I, String),
anda(N_I, N_J, String).
proxima_casa(I, J, I, J) :-
tamanho(TAM),
I = TAM,
J = TAM,
!,
halt.
proxima_casa(I, J, N_I, N_J) :-
tamanho(TAM),
J > 0,
J < TAM,
I =< TAM,
I > 0,
!,
N_I is I,
N_J is J + 1.
proxima_casa(I, _, N_I, 1) :-
tamanho(TAM),
I > 0,
I =< TAM,
!,
N_I is I + 1.
quebra_linha(I, N_I, String) :-
not(I = N_I),
write(String, '\n').
quebra_linha(_, _, _).