Skip to content

Commit ccbcd18

Browse files
committed
Construction à deux points
1 parent c4f6910 commit ccbcd18

File tree

9 files changed

+417
-269
lines changed

9 files changed

+417
-269
lines changed

.idea/inspectionProfiles/Project_Default.xml

+10
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/workspace.xml

+167-232
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
2.98 KB
Binary file not shown.

Environnement/pivot.py

+142-16
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,82 @@
88
# Module : Pivot
99
#
1010
########################################################
11+
from random import randrange
1112

1213
class Pivot(object):
1314

15+
16+
def check_two_points(self,P,P2,P3,P4,point_dico):
17+
point = {}
18+
if(P2 in point_dico):
19+
if (point_dico[P2] == point_dico[P]):
20+
if(P3 in point_dico) | (P4 in point_dico):
21+
return point
22+
else:
23+
coord = randrange(1,2)
24+
if(coord == 1):
25+
final = P3
26+
else:
27+
final = P4
28+
array = final.split('_')
29+
xf = int(array[0])
30+
yf = int(array[1])
31+
point['x'] = xf
32+
point['y'] = yf
33+
34+
return point
35+
36+
else:
37+
return point
38+
elif(P3 in point_dico):
39+
if (point_dico[P3] == point_dico[P]):
40+
if(P2 in point_dico) | (P4 in point_dico):
41+
return point
42+
else:
43+
coord = randrange(1,2)
44+
if(coord == 1):
45+
final = P2
46+
else:
47+
final = P4
48+
array = final.split('_')
49+
xf = int(array[0])
50+
yf = int(array[1])
51+
point['x'] = xf
52+
point['y'] = yf
53+
54+
return point
55+
56+
else:
57+
return point
58+
elif(P4 in point_dico):
59+
if (point_dico[P4] == point_dico[P]):
60+
if(P2 in point_dico) | (P3 in point_dico):
61+
return point
62+
else:
63+
coord = randrange(1,2)
64+
if(coord == 1):
65+
final = P2
66+
else:
67+
final = P4
68+
array = final.split('_')
69+
xf = int(array[0])
70+
yf = int(array[1])
71+
point['x'] = xf
72+
point['y'] = yf
73+
74+
return point
75+
76+
77+
else:
78+
return point
79+
else:
80+
return point
81+
82+
def carre(self,P,P2,P3,P4,point_dico):
83+
if(P2 in point_dico) & (P3 in point_dico) & (P4 in point_dico):
84+
if(point_dico[P] == point_dico[P2]) & (point_dico[P] == point_dico[P3]) & (point_dico[P] == point_dico[P4]):
85+
return True
86+
1487
#Vérification d'un carré en haut à gauche
1588
def top_left(self,x,y,space,point_dico):
1689
x2 = x - space
@@ -20,9 +93,7 @@ def top_left(self,x,y,space,point_dico):
2093
P3 = str(str(x2)+'_'+str(y))
2194
P4 = str(str(x2)+'_'+str(y2))
2295

23-
if(P2 in point_dico) & (P3 in point_dico) & (P4 in point_dico):
24-
if(point_dico[P] == point_dico[P2]) & (point_dico[P] == point_dico[P3]) & (point_dico[P] == point_dico[P4]):
25-
return True
96+
return self.carre(P,P2,P3,P4,point_dico)
2697

2798
#Vérification d'un carré en haut à droite
2899
def top_right(self,x,y,space,point_dico):
@@ -33,39 +104,29 @@ def top_right(self,x,y,space,point_dico):
33104
P3 = str(str(x2)+'_'+str(y2))
34105
P4 = str(str(x2)+'_'+str(y))
35106

36-
if(P2 in point_dico) & (P3 in point_dico) & (P4 in point_dico):
37-
38-
if(point_dico[P] == point_dico[P2]) & (point_dico[P] == point_dico[P3]) & (point_dico[P] == point_dico[P4]):
39-
40-
return True
107+
return self.carre(P,P2,P3,P4,point_dico)
41108

42109
#Vérification d'un carré en bas à gauche
43110
def bottom_left(self,x,y,space,point_dico):
44111
x2 = x - space
45112
y2 = y + space
46-
47113
P = str(str(x)+'_'+str(y))
48114
P2 = str(str(x2)+'_'+str(y))
49115
P3 = str(str(x2)+'_'+str(y2))
50116
P4 = str(str(x)+'_'+str(y2))
51117

52-
if(P2 in point_dico) & (P3 in point_dico) & (P4 in point_dico):
53-
if(point_dico[P] == point_dico[P2]) & (point_dico[P] == point_dico[P3]) & (point_dico[P] == point_dico[P4]):
54-
return True
118+
return self.carre(P,P2,P3,P4,point_dico)
55119

56120
#Vérification d'un carré en bas à droit
57121
def bottom_right(self,x,y,space,point_dico):
58122
x2 = x + space
59123
y2 = y + space
60-
61124
P = str(str(x)+'_'+str(y))
62125
P2 = str(str(x)+'_'+str(y2))
63126
P3 = str(str(x2)+'_'+str(y))
64127
P4 = str(str(x2)+'_'+str(y2))
65128

66-
if(P2 in point_dico) & (P3 in point_dico) & (P4 in point_dico):
67-
if(point_dico[P] == point_dico[P2]) & (point_dico[P] == point_dico[P3]) & (point_dico[P] == point_dico[P4]):
68-
return True
129+
return self.carre(P,P2,P3,P4,point_dico)
69130

70131
def get_point_top_left(self,x,y,space,point_dico):
71132
x2 = x - space
@@ -156,4 +217,69 @@ def get_point_bottom_left(self,x,y,space,point_dico):
156217
else:
157218
return point
158219

220+
def check_three_points_top_left(self,x,y,space,point_dico):
221+
x2 = x - space
222+
y2 = y - space
223+
P = str(str(x)+'_'+str(y))
224+
P2 = str(str(x)+'_'+str(y2))
225+
P3 = str(str(x2)+'_'+str(y))
226+
P4 = str(str(x2)+'_'+str(y2))
227+
point = {}
228+
229+
if(P2 in point_dico) | (P3 in point_dico) | (P4 in point_dico):
230+
return point
231+
else:
232+
coord = randrange(1,3)
233+
if(coord == 1):
234+
xf = x
235+
yf = y2
236+
elif(coord == 2):
237+
xf = x2
238+
yf = y
239+
else:
240+
xf = x2
241+
yf = y2
242+
243+
point['x'] = xf
244+
point['y'] = yf
245+
return point
246+
247+
def check_two_points_top_left(self,x,y,space,point_dico):
248+
x2 = x - space
249+
y2 = y - space
250+
P = str(str(x)+'_'+str(y))
251+
P2 = str(str(x)+'_'+str(y2))
252+
P3 = str(str(x2)+'_'+str(y))
253+
P4 = str(str(x2)+'_'+str(y2))
254+
255+
return self.check_two_points(P,P2,P3,P4,point_dico)
256+
257+
def check_two_points_top_right(self,x,y,space,point_dico):
258+
x2 = x + space
259+
y2 = y - space
260+
P = str(str(x)+'_'+str(y))
261+
P2 = str(str(x)+'_'+str(y2))
262+
P3 = str(str(x2)+'_'+str(y2))
263+
P4 = str(str(x2)+'_'+str(y))
264+
265+
return self.check_two_points(P,P2,P3,P4,point_dico)
266+
267+
def check_two_points_bottom_left(self,x,y,space,point_dico):
268+
x2 = x - space
269+
y2 = y + space
270+
P = str(str(x)+'_'+str(y))
271+
P2 = str(str(x2)+'_'+str(y))
272+
P3 = str(str(x2)+'_'+str(y2))
273+
P4 = str(str(x)+'_'+str(y2))
274+
275+
return self.check_two_points(P,P2,P3,P4,point_dico)
276+
277+
def check_two_points_bottom_right(self,x,y,space,point_dico):
278+
x2 = x + space
279+
y2 = y + space
280+
P = str(str(x)+'_'+str(y))
281+
P2 = str(str(x)+'_'+str(y2))
282+
P3 = str(str(x2)+'_'+str(y))
283+
P4 = str(str(x2)+'_'+str(y2))
159284

285+
return self.check_two_points(P,P2,P3,P4,point_dico)

IA/IrisIA.py

+57-1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ class IrisIA(object):
2424
score = 0
2525
attackDico = {}
2626
defenseDico = {}
27+
onePointDico = {}
28+
twoPointDico = {}
2729

2830
def __init__(self,color):
2931
self.color = color
@@ -73,9 +75,63 @@ def checkOtherDico(self,dico,space):
7375
def clearDico(self):
7476
self.attackDico.clear()
7577
self.defenseDico.clear()
78+
self.onePointDico.clear()
79+
self.twoPointDico.clear()
80+
81+
def checkOnePointDico(self,point_dico,space):
82+
#Parcourt le dictionnaire
83+
for k in self.ownDico:
84+
#Exploder le K par les enderscorts
85+
array = k.split('_')
86+
x = int(array[0])
87+
y = int(array[1])
88+
89+
top_left = pivot.check_three_points_top_left(x,y,space,point_dico)
90+
print(top_left)
91+
if(len(top_left)):
92+
point = str(str(top_left['x'])+'_'+str(top_left['y']))
93+
if point in self.onePointDico:
94+
self.onePointDico[point] = self.onePointDico[point] + 1
95+
else:
96+
self.onePointDico[point] = 1
97+
98+
def checkTwoPointDico(self,point_dico,space):
99+
#Parcourt le dictionnaire
100+
for k in self.ownDico:
101+
#Exploder le K par les enderscorts
102+
array = k.split('_')
103+
x = int(array[0])
104+
y = int(array[1])
105+
106+
top_left = pivot.check_two_points_top_left(x,y,space,point_dico)
107+
top_right = pivot.check_two_points_top_right(x,y,space,point_dico)
108+
bottom_left = pivot.check_two_points_bottom_left(x,y,space,point_dico)
109+
bottom_right = pivot.check_two_points_bottom_right(x,y,space,point_dico)
110+
111+
self.makeBuildDico(top_left,point_dico)
112+
self.makeBuildDico(top_right,point_dico)
113+
self.makeBuildDico(bottom_left,point_dico)
114+
self.makeBuildDico(bottom_right,point_dico)
115+
116+
def makeBuildDico(self,dico,one_point):
117+
if(len(dico)):
118+
point = str(str(dico['x'])+'_'+str(dico['y']))
119+
if(one_point):
120+
if point in self.onePointDico:
121+
self.onePointDico[point] = self.onePointDico[point] + 1
122+
else:
123+
self.onePointDico[point] = 1
124+
else:
125+
if point in self.twoPointDico:
126+
self.twoPointDico[point] = self.twoPointDico[point] + 1
127+
else:
128+
self.twoPointDico[point] = 1
76129

77130
def canBuild(self):
78-
pass
131+
if len(self.onePointDico) | len(self.twoPointDico):
132+
return True
133+
else:
134+
return False
79135

80136
def randPoint(self,can,point_dico):
81137

IA/__pycache__/IrisIA.cpython-35.pyc

1.56 KB
Binary file not shown.
261 Bytes
Binary file not shown.

IA/irisCpIA.py

+7-2
Original file line numberDiff line numberDiff line change
@@ -38,5 +38,10 @@ def final_point(self,dico):
3838

3939
return final_dico
4040

41-
def build(self):
42-
pass
41+
def buildWithOnePoint(self):
42+
onepointdico = self.onePointDico
43+
return self.final_point(onepointdico)
44+
45+
def buildWithTwoPoint(self):
46+
twopointdico = self.twoPointDico
47+
return self.final_point(twopointdico)

vsCpIris.py

+34-18
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
########################################################
1212

1313
from tkinter import *
14+
from random import randrange
1415

1516
from Environnement.player import Player
1617
from Environnement.pivot import Pivot
@@ -158,29 +159,44 @@ def IAtour():
158159
defense = P2.checkOtherDico(point_dico,space)
159160
attack = P2.checkOwnDico(point_dico,space)
160161

161-
if(len(defense) | len(attack)):
162-
163-
if(len(attack)):
164-
final_dico = P2.attack()
165-
else:
166-
final_dico = P2.defense()
167-
168-
P2.clearDico()
162+
if(len(attack)):
169163

164+
final_dico = P2.attack()
170165
x = final_dico['x']
171166
y = final_dico['y']
172167
can.create_oval(x-r, y-r, x+r, y+r, fill=current_p.getColor())
168+
173169
else:
174-
#Vérification si il y a un possibilité de construire
175-
# if(P2.canBuild()):
176-
# pass
177-
# else:
178-
# point = P2.randPoint(can,point_dico)
179-
# x = point['x']
180-
# y = point['y']
181-
point = P2.randPoint(can,point_dico)
182-
x = point['x']
183-
y = point['y']
170+
171+
vue = randrange(1,20) % 2
172+
173+
if( len(defense) & vue):
174+
final_dico = P2.defense()
175+
x = final_dico['x']
176+
y = final_dico['y']
177+
can.create_oval(x-r, y-r, x+r, y+r, fill=current_p.getColor())
178+
else:
179+
#Vérification si il y a un possibilité de construire
180+
P2.checkOnePointDico(point_dico,space)
181+
P2.checkTwoPointDico(point_dico,space)
182+
183+
if(P2.canBuild()):
184+
if(len(P2.twoPointDico)):
185+
point = P2.buildWithTwoPoint()
186+
else:
187+
point = P2.buildWithOnePoint()
188+
189+
print(point)
190+
x = point['x']
191+
y = point['y']
192+
can.create_oval(x-r, y-r, x+r, y+r, fill=current_p.getColor())
193+
else:
194+
point = P2.randPoint(can,point_dico)
195+
x = point['x']
196+
y = point['y']
197+
198+
#On vide tous les dictionnaires de l'IA
199+
P2.clearDico()
184200

185201
#Enregistrement des coordonnées dans le dictionnaire global.
186202
coord = str(str(x)+'_'+str(y))

0 commit comments

Comments
 (0)