-
Notifications
You must be signed in to change notification settings - Fork 1
/
aGagner.pl
131 lines (91 loc) · 5.2 KB
/
aGagner.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
compareList([], []).
compareList(L1, L2) :-
L1 = [T1|Q1],
L2 = [T2|Q2],
T1 == T2,
compareList(Q1, Q2).
compareList(L1, L2, Pion) :-
L1 = [T1|Q1],
L2 = [T2|Q2],
T1 == T2,
T1 == Pion,
compareList(Q1, Q2).
sv(x):-
gamestate(Z),
sv(x, Z).
sv(o):-
gamestate(Z),
sv(o, Z).
sv(Pion, Z):-
length(Z,NbElements), NbElements > 3,
nth0(0, Z, Y), nth0(0, Y, C1), nth0(1, Y, C2), nth0(2, Y, C3), nth0(3, Y, C4), compareList([C1], [C2]),
compareList([C2], [C3]), compareList([C3], [C4], Pion);
nth0(1, Z, Y), nth0(0, Y, C1), nth0(1, Y, C2), nth0(2, Y, C3), nth0(3, Y, C4), compareList([C1], [C2]),
compareList([C2], [C3]), compareList([C3], [C4], Pion);
nth0(2, Z, Y), nth0(0, Y, C1), nth0(1, Y, C2), nth0(2, Y, C3), nth0(3, Y, C4), compareList([C1], [C2]),
compareList([C2], [C3]), compareList([C3], [C4], Pion) ;
nth0(3, Z, Y), nth0(0, Y, C1), nth0(1, Y, C2), nth0(2, Y, C3), nth0(3, Y, C4), compareList([C1], [C2]),
compareList([C2], [C3]), compareList([C3], [C4], Pion) ;
nth0(4, Z, Y), nth0(0, Y, C1), nth0(1, Y, C2), nth0(2, Y, C3), nth0(3, Y, C4), compareList([C1], [C2]),
compareList([C2], [C3]), compareList([C3], [C4], Pion) ;
nth0(5, Z, Y), nth0(0, Y, C1), nth0(1, Y, C2), nth0(2, Y, C3), nth0(3, Y, C4), compareList([C1], [C2]),
compareList([C2], [C3]), compareList([C3], [C4], Pion) ;
nth0(6, Z, Y), nth0(0, Y, C1), nth0(1, Y, C2), nth0(2, Y, C3), nth0(3, Y, C4), compareList([C1], [C2]),
compareList([C2], [C3]), compareList([C3], [C4], Pion).
sv(Pion, Z) :-
length(Z,NbElements), NbElements > 3,
nth0(0, Z, Y), nth0(1, Y, C2), nth0(2, Y, C3), nth0(3, Y, C4), nth0(4, Y, C5),
compareList([C2], [C3]), compareList([C3], [C4]), compareList([C4], [C5], Pion) ;
nth0(1, Z, Y), nth0(1, Y, C2), nth0(2, Y, C3), nth0(3, Y, C4), nth0(4, Y, C5),
compareList([C2], [C3]), compareList([C3], [C4]), compareList([C4], [C5], Pion) ;
nth0(2, Z, Y), nth0(1, Y, C2), nth0(2, Y, C3), nth0(3, Y, C4), nth0(4, Y, C5),
compareList([C2], [C3]), compareList([C3], [C4]), compareList([C4], [C5], Pion) ;
nth0(3, Z, Y), nth0(1, Y, C2), nth0(2, Y, C3), nth0(3, Y, C4), nth0(4, Y, C5),
compareList([C2], [C3]), compareList([C3], [C4]), compareList([C4], [C5], Pion) ;
nth0(4, Z, Y), nth0(1, Y, C2), nth0(2, Y, C3), nth0(3, Y, C4), nth0(4, Y, C5),
compareList([C2], [C3]), compareList([C3], [C4]), compareList([C4], [C5], Pion) ;
nth0(5, Z, Y), nth0(1, Y, C2), nth0(2, Y, C3), nth0(3, Y, C4), nth0(4, Y, C5),
compareList([C2], [C3]), compareList([C3], [C4]), compareList([C4], [C5], Pion) ;
nth0(6, Z, Y), nth0(1, Y, C2), nth0(2, Y, C3), nth0(3, Y, C4), nth0(4, Y, C5),
compareList([C2], [C3]), compareList([C3], [C4]), compareList([C4], [C5], Pion).
sv(Pion, Z) :-
length(Z,NbElements), NbElements > 3,
nth0(0, Z, Y), nth0(2, Y, C3), nth0(3, Y, C4), nth0(4, Y, C5), nth0(5, Y, C6),
compareList([C3], [C4]), compareList([C4], [C5]), compareList([C5], [C6], Pion) ;
nth0(1, Z, Y), nth0(2, Y, C3), nth0(3, Y, C4), nth0(4, Y, C5), nth0(5, Y, C6),
compareList([C3], [C4]), compareList([C4], [C5]), compareList([C5], [C6], Pion) ;
nth0(2, Z, Y), nth0(2, Y, C3), nth0(3, Y, C4), nth0(4, Y, C5), nth0(5, Y, C6),
compareList([C3], [C4]), compareList([C4], [C5]), compareList([C5], [C6], Pion) ;
nth0(3, Z, Y), nth0(2, Y, C3), nth0(3, Y, C4), nth0(4, Y, C5), nth0(5, Y, C6),
compareList([C3], [C4]), compareList([C4], [C5]), compareList([C5], [C6], Pion) ;
nth0(4, Z, Y), nth0(2, Y, C3), nth0(3, Y, C4), nth0(4, Y, C5), nth0(5, Y, C6),
compareList([C3], [C4]), compareList([C4], [C5]), compareList([C5], [C6], Pion) ;
nth0(5, Z, Y), nth0(2, Y, C3), nth0(3, Y, C4), nth0(4, Y, C5), nth0(5, Y, C6),
compareList([C3], [C4]), compareList([C4], [C5]), compareList([C5], [C6], Pion) ;
nth0(6, Z, Y), nth0(2, Y, C3), nth0(3, Y, C4), nth0(4, Y, C5), nth0(5, Y, C6),
compareList([C3], [C4]), compareList([C4], [C5]), compareList([C5], [C6], Pion).
% on prend la premiere colone puis la deuxieme, puis ... Ensuite on prend le premier element de la colonne 1, puis le premier de la colonne 2, etc
% E5 est en trop : c'est bien puissance 4?
% TODO : Regler le probleme d'ajout en debut de liste
sh(x):-
gamestate(Z),
sh(x, Z).
sh(o):-
gamestate(Z),
sh(o, Z).
sh(Pion, Z) :-
nth0(0, Z, C1), nth0(1, Z, C2), nth0(2, Z, C3), nth0(3, Z, C4),
nth0(LineNumber, C1, E1),nth0(LineNumber, C2, E2),nth0(LineNumber, C3, E3),nth0(LineNumber, C4, E4),
compareList([E1], [E2],Pion), compareList([E2], [E3]), compareList([E3], [E4],Pion).
sh(Pion, Z) :-
nth0(1, Z, C1), nth0(2, Z, C2), nth0(3, Z, C3), nth0(4, Z, C4),
nth0(LineNumber, C1, E1),nth0(LineNumber, C2, E2),nth0(LineNumber, C3, E3),nth0(LineNumber, C4, E4),
compareList([E1], [E2],Pion), compareList([E2], [E3]), compareList([E3], [E4],Pion).
sh(Pion, Z) :-
nth0(2, Z, C1), nth0(3, Z, C2), nth0(4, Z, C3), nth0(5, Z, C4),
nth0(LineNumber, C1, E1),nth0(LineNumber, C2, E2),nth0(LineNumber, C3, E3),nth0(LineNumber, C4, E4),
compareList([E1], [E2]), compareList([E2], [E3]), compareList([E3], [E4],Pion).
sh(Pion, Z) :-
nth0(3, Z, C1), nth0(4, Z, C2), nth0(5, Z, C3), nth0(6, Z, C4),
nth0(LineNumber, C1, E1),nth0(LineNumber, C2, E2),nth0(LineNumber, C3, E3),nth0(LineNumber, C4, E4),
compareList([E1], [E2],Pion), compareList([E2], [E3]), compareList([E3], [E4],Pion).