-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprograma2.4.pl
115 lines (92 loc) · 2.28 KB
/
programa2.4.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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
:- dynamic mina/2.
:- dynamic valor/3.
:- dynamic aberta/2.
:- dynamic arquivo_carregado.
:- ['mina'].
:- ['ambiente'].
tamanho(TAM) :- TAM is 3.
posicao(I,J) :-
arquivo_carregado,
open('jogo.pl', append, String),
posicao(I, J, String, L).
posicao(I,J) :-
open('jogo.pl', write, String),
assert(arquivo_carregado),
posicao(I, J, String, L).
posicao(I,J, String, L) :-
mina(I,J),
assert(aberta(I,J)),
swritef(Aux, 'mina(%d,%d).\n', [I, J]),
write(String, Aux),
print('BOOOOM!'),
print(Aux),
print('Game Over'),
close(String),
halt.
posicao(I,J, String, L) :-
not(aberta(I,J)),
valor(I,J,K),
K=0, !,
swritef(Aux, 'Casa(%d,%d) = %d\n', [I, J, K]),
write(String, Aux),
print(Aux),
assert(aberta(I,J)),
findall((I1,J1), posicao_adj(I,J, _, I1, J1), L),
abre_casas(L, String).
posicao(I,J, String,L) :-
not(aberta(I,J)),
valor(I,J,K), !,
swritef(Aux, 'Casa(%d,%d) = %d\n', [I,J,K]),
write(String, Aux),
assert(aberta(I,J)),
print(Aux),
abre_casas(L, String).
posicao_adj(I, J, left, I, J1) :-
J1 is J - 1,
J1 > 0,
not(mina(I,J1)).
posicao_adj(I, J, right, I, J1) :-
J1 is J + 1,
tamanho(TAM),
J1 =< TAM,
not(mina(I,J1)).
posicao_adj(I, J, bottom, I1, J) :-
I1 is I + 1,
tamanho(TAM),
I1 =< TAM,
not(mina(I1,J)).
posicao_adj(I, J, top, I1, J) :-
I1 is I - 1,
tamanho(TAM),
I1 > 0,
not(mina(I1,J)).
posicao_adj(I, J, topright, I1, J1) :-
I1 is I - 1,
J1 is J + 1,
tamanho(TAM),
J1 =< TAM,
I1 > 0,
not(mina(I1,J1)).
posicao_adj(I, J, bottomright, I1, J1) :-
I1 is I + 1,
J1 is J + 1,
tamanho(TAM),
J1 =< TAM,
I1 =< TAM,
not(mina(I1,J1)).
posicao_adj(I, J, topleft, I1, J1) :-
I1 is I - 1,
J1 is J - 1,
J1 > 0,
I1 > 0,
not(mina(I1,J1)).
posicao_adj(I, J, bottomleft, I1, J1) :-
I1 is I + 1,
J1 is J - 1,
tamanho(TAM),
J1 > 0,
I1 =< TAM,
not(mina(I1,J1)).
abre_casas([], _).
abre_casas([(I,J)|L], String) :-
posicao(I,J, String, L).