-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprograma2.5.pl
138 lines (115 loc) · 2.95 KB
/
programa2.5.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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
:- dynamic mina/2.
:- dynamic valor/3.
:- dynamic aberta/2.
:- dynamic jogada.
:- dynamic arquivo_carregado.
:- ['mina'].
:- ['ambiente'].
tamanho(TAM) :- TAM is 3.
%Proximas_jogadas
posicao(I,J) :-
arquivo_carregado,
open('jogo.pl', append, String),
assert(jogada),
Swritef(Texto, '/*JOGADA %d\n*/', [length(jogada)]),
print(Texto),
swritef(Aux, 'posicao(%d,%d).\n', [I,J]),
write(String, Aux),
print(Aux),
posicao(I, J, String, L).
%Primeira_jogada
posicao(I,J) :-
open('jogo.pl', write, String),
assert(arquivo_carregado),
assert(jogada),
swritef(Texto, '/*JOGADA 1*/.\n'),
write(String, Texto),
print(Texto)
swritef(Aux, 'posicao(%d,%d).\n', [I,J]),
write(String, Aux),
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]),
swritef(Texto, '/*AMBIENTE*/'),
write(String, texto),
print(Texto),
swritef(Aux, 'Game Over'),
print(Aux),
write(String, Aux),
close(String),
halt.
posicao(I,J, String, L) :-
not(aberta(I,J)),
valor(I,J,K),
K=0, !,
swritef(Texto, '/*AMBIENTE*/'),
write(String, texto),
print(Texto),
swritef(Aux, 'valor(%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(Texto, '/*AMBIENTE*/'),
write(String, Texto),
print(Texto),
swritef(Aux, 'valor(%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).