Skip to content

Commit

Permalink
Fin gestion de l'IA niveau CP1/CP2/
Browse files Browse the repository at this point in the history
  • Loading branch information
gabeta committed Jul 6, 2017
1 parent ccbcd18 commit ab9d799
Show file tree
Hide file tree
Showing 9 changed files with 239 additions and 140 deletions.
2 changes: 2 additions & 0 deletions .idea/inspectionProfiles/Project_Default.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

243 changes: 140 additions & 103 deletions .idea/workspace.xml

Large diffs are not rendered by default.

Binary file modified Environnement/__pycache__/pivot.cpython-35.pyc
Binary file not shown.
Binary file modified Environnement/__pycache__/terrain.cpython-35.pyc
Binary file not shown.
110 changes: 85 additions & 25 deletions Environnement/pivot.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,35 @@

class Pivot(object):

width = 630
height = 540

def check_two_points(self,P,P2,P3,P4,point_dico):
def check_three_points(self,P,P2,P3,P4,point_dico,space):
point = {}

if(P2 in point_dico) | (P3 in point_dico) | (P4 in point_dico):
return point
else:
coord = randrange(1,3)
if(coord == 1):
Pf = P2
elif(coord == 2):
Pf = P3
else:
Pf = P4

array = Pf.split('_')
xf = int(array[0])
yf = int(array[1])
point['x'] = xf
point['y'] = yf

if self.overFlow(xf,yf,space):
return point
else:
return {}

def check_two_points(self,P,P2,P3,P4,point_dico,space):
point = {}
if(P2 in point_dico):
if (point_dico[P2] == point_dico[P]):
Expand All @@ -31,7 +58,10 @@ def check_two_points(self,P,P2,P3,P4,point_dico):
point['x'] = xf
point['y'] = yf

return point
if self.overFlow(xf,yf,space) :
return point
else:
return {}

else:
return point
Expand All @@ -51,7 +81,11 @@ def check_two_points(self,P,P2,P3,P4,point_dico):
point['x'] = xf
point['y'] = yf

return point
if self.overFlow(xf,yf,space) :
return point
else:
return {}


else:
return point
Expand All @@ -71,7 +105,10 @@ def check_two_points(self,P,P2,P3,P4,point_dico):
point['x'] = xf
point['y'] = yf

return point
if self.overFlow(xf,yf,space) :
return point
else:
return {}


else:
Expand Down Expand Up @@ -224,25 +261,38 @@ def check_three_points_top_left(self,x,y,space,point_dico):
P2 = str(str(x)+'_'+str(y2))
P3 = str(str(x2)+'_'+str(y))
P4 = str(str(x2)+'_'+str(y2))
point = {}

if(P2 in point_dico) | (P3 in point_dico) | (P4 in point_dico):
return point
else:
coord = randrange(1,3)
if(coord == 1):
xf = x
yf = y2
elif(coord == 2):
xf = x2
yf = y
else:
xf = x2
yf = y2
return self.check_three_points(P,P2,P3,P4,point_dico,space)

point['x'] = xf
point['y'] = yf
return point
def check_three_points_top_right(self,x,y,space,point_dico):
x2 = x + space
y2 = y - space
P = str(str(x)+'_'+str(y))
P2 = str(str(x)+'_'+str(y2))
P3 = str(str(x2)+'_'+str(y2))
P4 = str(str(x2)+'_'+str(y))

return self.check_three_points(P,P2,P3,P4,point_dico,space)

def check_three_points_bottom_left(self,x,y,space,point_dico):
x2 = x - space
y2 = y + space
P = str(str(x)+'_'+str(y))
P2 = str(str(x2)+'_'+str(y))
P3 = str(str(x2)+'_'+str(y2))
P4 = str(str(x)+'_'+str(y2))

return self.check_three_points(P,P2,P3,P4,point_dico,space)

def check_three_points_bottom_right(self,x,y,space,point_dico):
x2 = x + space
y2 = y + space
P = str(str(x)+'_'+str(y))
P2 = str(str(x)+'_'+str(y2))
P3 = str(str(x2)+'_'+str(y))
P4 = str(str(x2)+'_'+str(y2))

return self.check_three_points(P,P2,P3,P4,point_dico,space)

def check_two_points_top_left(self,x,y,space,point_dico):
x2 = x - space
Expand All @@ -252,7 +302,7 @@ def check_two_points_top_left(self,x,y,space,point_dico):
P3 = str(str(x2)+'_'+str(y))
P4 = str(str(x2)+'_'+str(y2))

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

def check_two_points_top_right(self,x,y,space,point_dico):
x2 = x + space
Expand All @@ -262,7 +312,7 @@ def check_two_points_top_right(self,x,y,space,point_dico):
P3 = str(str(x2)+'_'+str(y2))
P4 = str(str(x2)+'_'+str(y))

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

def check_two_points_bottom_left(self,x,y,space,point_dico):
x2 = x - space
Expand All @@ -272,7 +322,7 @@ def check_two_points_bottom_left(self,x,y,space,point_dico):
P3 = str(str(x2)+'_'+str(y2))
P4 = str(str(x)+'_'+str(y2))

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

def check_two_points_bottom_right(self,x,y,space,point_dico):
x2 = x + space
Expand All @@ -282,4 +332,14 @@ def check_two_points_bottom_right(self,x,y,space,point_dico):
P3 = str(str(x2)+'_'+str(y))
P4 = str(str(x2)+'_'+str(y2))

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

#Vérifie si l'IA est dans la zone de jeu
def overFlow(self,x,y,space):
if(y <= (self.height - space)) & (y >= space):
if(x <= (self.width - space)) & (x >= space):
return True
else:
return False
else:
return False
23 changes: 12 additions & 11 deletions IA/IrisIA.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,13 +87,14 @@ def checkOnePointDico(self,point_dico,space):
y = int(array[1])

top_left = pivot.check_three_points_top_left(x,y,space,point_dico)
print(top_left)
if(len(top_left)):
point = str(str(top_left['x'])+'_'+str(top_left['y']))
if point in self.onePointDico:
self.onePointDico[point] = self.onePointDico[point] + 1
else:
self.onePointDico[point] = 1
top_right = pivot.check_three_points_top_right(x,y,space,point_dico)
bottom_left = pivot.check_three_points_bottom_left(x,y,space,point_dico)
bottom_right = pivot.check_three_points_bottom_right(x,y,space,point_dico)

self.makeBuildDico(top_left,True)
self.makeBuildDico(top_right,True)
self.makeBuildDico(bottom_left,True)
self.makeBuildDico(bottom_right,True)

def checkTwoPointDico(self,point_dico,space):
#Parcourt le dictionnaire
Expand All @@ -108,10 +109,10 @@ def checkTwoPointDico(self,point_dico,space):
bottom_left = pivot.check_two_points_bottom_left(x,y,space,point_dico)
bottom_right = pivot.check_two_points_bottom_right(x,y,space,point_dico)

self.makeBuildDico(top_left,point_dico)
self.makeBuildDico(top_right,point_dico)
self.makeBuildDico(bottom_left,point_dico)
self.makeBuildDico(bottom_right,point_dico)
self.makeBuildDico(top_left,False)
self.makeBuildDico(top_right,False)
self.makeBuildDico(bottom_left,False)
self.makeBuildDico(bottom_right,False)

def makeBuildDico(self,dico,one_point):
if(len(dico)):
Expand Down
Binary file modified IA/__pycache__/IrisIA.cpython-35.pyc
Binary file not shown.
Binary file modified IA/__pycache__/irisCpIA.cpython-35.pyc
Binary file not shown.
1 change: 0 additions & 1 deletion vsCpIris.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,6 @@ def IAtour():
else:
point = P2.buildWithOnePoint()

print(point)
x = point['x']
y = point['y']
can.create_oval(x-r, y-r, x+r, y+r, fill=current_p.getColor())
Expand Down

0 comments on commit ab9d799

Please sign in to comment.