-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathselect_tokens.pl
151 lines (123 loc) · 4.12 KB
/
select_tokens.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
139
140
141
142
143
144
145
146
147
148
149
150
151
:-[lists/list, factory, board, utils].
:- dynamic list_of_factories/1, amount_of_factories/1.
list_of_factories([
[blue, black, black, yellow],
[yellow, black, blue, black],
[blue, red, black, green],
[blue, black, red, green],
[red, green, red, red],
[blue, yellow, green, green],
[black, blue, black, red]
]).
turno(Player,Jugada):-random(0,2,R),
fabrica_o_centro(Player,R,Jugada1),
Jugada=[Jugada1|R]
.
fabrica_o_centro(Player,0,Jugada):-!,
call(list_of_factories(Fabri)),
length_mine(Fabri,N),
=======
:-[utils/utils, factory, board].
:- dynamic list_of_factories/1, amount_of_factories/1, jugada/3.
list_of_factories([
[blue, black, black, yellow],
[yellow, black, blue, black],
[blue, red, black, green],
[blue, black, red, green],
[red, green, red, red],
[blue, yellow, green, green],
[black, blue, black, red]
]).
amount_of_factories(7).
turno(Player,Fabricas_con_azulejos,Jugada):-
length_mine(Fabricas_con_azulejos,N),
N1 is N+1,
random(0,N1,X),!,
index(Fabri,X,F),
escoger_jugada_valida(F,Player,J),
Jugada = [X,J].
fabrica_o_centro(Player,1,Jugada):-
centro_de_mesa(F),
escoger_jugada_valida(F,Player,J),
Jugada = [-1,J].
%select_factory([],N,_,Correct):-random(0,N,X1),factories(X1,F),!,select_factory(%F,N,X1,Correct),!.
%select_factory([F|Resto],N,X,Correct):-Correct is X.
escoger_jugada_valida(T,Player,J):-
escoger_color(T,P),
cantidad_en_fabrica(T,P,X),
X =\= 4,
call(estado_zona_preparacion(Player,A)),
call(muro_del_jugador(Player,M)),
%verificar si esa cantidad de colores se pueden poner en alguna fila de la zona de preparacion
select_zona_preparacion(A,M,P,X,1,Fila),
% si lo anterior devuelve -1 indica que deben ir a la zona final obligado
Fila == -1,!,
choose(A,M,P,X,1,Selection,Min),
minlista(Min,Minimo),
searching(Minimo,Min,0,Pos),
index(Selection,Pos,Fila_final),
J = [P,Fila_final]
.
escoger_jugada_valida(T,Player,J):-
escoger_color(T,P),
cantidad_en_fabrica(T,P,X),
call(estado_zona_preparacion(Player,A)),
call(muro_del_jugador(Player,M)),
%verificar si esa cantidad de colores se pueden poner en alguna fila de la zona de preparacion
select_zona_preparacion(A,M,P,X,1,Fila),
% si lo anterior devuelve -1 indica que deben ir a la zona final obligado
J = [P,Fila].
choose([],[],_,_,_,[],[]):-!.
choose([A|R],[M|Resto],C,X,Count,[Selection|Y],[Min|Z]):-
escoger_la_mejor_entre_las_peores(A,M,C,X,Count,Selection1,Min1),!,
Selection is Selection1,
Min is Min1,
Count1 is Count +1,
choose(R,Resto,C,X,Count1,Y,Z).
choose([_|R],[_|Resto],C,X,Count,[Selection|Y],[Min|Z]):-Count1 is Count+1,Selection is -1, Min is 40,choose(R,Resto,C,X,Count1,Y,Z).
escoger_la_mejor_entre_las_peores(A,_,C,X,Count,Selection,Min):-
index(A,0,Color),
Color==C,
index(A,1,Cant),
Aux is Count-1,
Min is Cant+X-Count,
Selection is Aux.
escoger_la_mejor_entre_las_peores(A,M,C,X,Count,Selection,Min):-
index(A,0,Color),
Color==empty,
call(wall(W)),
Aux is Count-1,
index(W,Aux,F),
dictionary_colors(P,C),
searching(P,F,0,Pos),
index(M,Pos,Valid),
Valid ==0,
Min is X-Count,
Selection is Aux .
select_zona_preparacion([],[],_,_,_,Fila):-Fila is -1,!.
select_zona_preparacion([A|_],_,C,X,Count,Fila):-index(A,0,Color),
Color==C,
index(A,1,Cant),
Count>=X+Cant,
Aux is Count-1,
Fila is Aux.
select_zona_preparacion([A|_],[M|_],C,X,Count,Fila):-index(A,0,Color),
Color==empty,
Count>=X,
call(wall(W)),
Aux is Count-1,
index(W,Aux,F),
dictionary_colors(P,C),
searching(P,F,0,Pos),
index(M,Pos,Valid),
Valid ==0,!,
Fila is Aux.
select_zona_preparacion([_|Rest],[_|R],C,X,Count,Fila):-C1 is Count+1,
select_zona_preparacion(Rest,R,C,X,C1,Fila).
cantidad_en_fabrica([],_,X):-X is 0,!.
cantidad_en_fabrica([P|Resto],P,X):-!,cantidad_en_fabrica(Resto,P,X1),X is X1+1.
cantidad_en_fabrica([_|Resto],P,X):-cantidad_en_fabrica(Resto,P,X).
escoger_color(T,P):-random(0,4,X),
index(T,X,C),P = C.
=======
index(T,X,C),P = C.