Skip to content

Commit

Permalink
Construction à deux points
Browse files Browse the repository at this point in the history
  • Loading branch information
gabeta committed Jul 6, 2017
1 parent c4f6910 commit ccbcd18
Show file tree
Hide file tree
Showing 9 changed files with 417 additions and 269 deletions.
10 changes: 10 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.

399 changes: 167 additions & 232 deletions .idea/workspace.xml

Large diffs are not rendered by default.

Binary file modified Environnement/__pycache__/pivot.cpython-35.pyc
Binary file not shown.
158 changes: 142 additions & 16 deletions Environnement/pivot.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,82 @@
# Module : Pivot
#
########################################################
from random import randrange

class Pivot(object):


def check_two_points(self,P,P2,P3,P4,point_dico):
point = {}
if(P2 in point_dico):
if (point_dico[P2] == point_dico[P]):
if(P3 in point_dico) | (P4 in point_dico):
return point
else:
coord = randrange(1,2)
if(coord == 1):
final = P3
else:
final = P4
array = final.split('_')
xf = int(array[0])
yf = int(array[1])
point['x'] = xf
point['y'] = yf

return point

else:
return point
elif(P3 in point_dico):
if (point_dico[P3] == point_dico[P]):
if(P2 in point_dico) | (P4 in point_dico):
return point
else:
coord = randrange(1,2)
if(coord == 1):
final = P2
else:
final = P4
array = final.split('_')
xf = int(array[0])
yf = int(array[1])
point['x'] = xf
point['y'] = yf

return point

else:
return point
elif(P4 in point_dico):
if (point_dico[P4] == point_dico[P]):
if(P2 in point_dico) | (P3 in point_dico):
return point
else:
coord = randrange(1,2)
if(coord == 1):
final = P2
else:
final = P4
array = final.split('_')
xf = int(array[0])
yf = int(array[1])
point['x'] = xf
point['y'] = yf

return point


else:
return point
else:
return point

def carre(self,P,P2,P3,P4,point_dico):
if(P2 in point_dico) & (P3 in point_dico) & (P4 in point_dico):
if(point_dico[P] == point_dico[P2]) & (point_dico[P] == point_dico[P3]) & (point_dico[P] == point_dico[P4]):
return True

#Vérification d'un carré en haut à gauche
def top_left(self,x,y,space,point_dico):
x2 = x - space
Expand All @@ -20,9 +93,7 @@ def top_left(self,x,y,space,point_dico):
P3 = str(str(x2)+'_'+str(y))
P4 = str(str(x2)+'_'+str(y2))

if(P2 in point_dico) & (P3 in point_dico) & (P4 in point_dico):
if(point_dico[P] == point_dico[P2]) & (point_dico[P] == point_dico[P3]) & (point_dico[P] == point_dico[P4]):
return True
return self.carre(P,P2,P3,P4,point_dico)

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

if(P2 in point_dico) & (P3 in point_dico) & (P4 in point_dico):

if(point_dico[P] == point_dico[P2]) & (point_dico[P] == point_dico[P3]) & (point_dico[P] == point_dico[P4]):

return True
return self.carre(P,P2,P3,P4,point_dico)

#Vérification d'un carré en bas à gauche
def 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))

if(P2 in point_dico) & (P3 in point_dico) & (P4 in point_dico):
if(point_dico[P] == point_dico[P2]) & (point_dico[P] == point_dico[P3]) & (point_dico[P] == point_dico[P4]):
return True
return self.carre(P,P2,P3,P4,point_dico)

#Vérification d'un carré en bas à droit
def 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))

if(P2 in point_dico) & (P3 in point_dico) & (P4 in point_dico):
if(point_dico[P] == point_dico[P2]) & (point_dico[P] == point_dico[P3]) & (point_dico[P] == point_dico[P4]):
return True
return self.carre(P,P2,P3,P4,point_dico)

def get_point_top_left(self,x,y,space,point_dico):
x2 = x - space
Expand Down Expand Up @@ -156,4 +217,69 @@ def get_point_bottom_left(self,x,y,space,point_dico):
else:
return point

def check_three_points_top_left(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))
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

point['x'] = xf
point['y'] = yf
return point

def check_two_points_top_left(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_two_points(P,P2,P3,P4,point_dico)

def check_two_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_two_points(P,P2,P3,P4,point_dico)

def check_two_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_two_points(P,P2,P3,P4,point_dico)

def check_two_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_two_points(P,P2,P3,P4,point_dico)
58 changes: 57 additions & 1 deletion IA/IrisIA.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ class IrisIA(object):
score = 0
attackDico = {}
defenseDico = {}
onePointDico = {}
twoPointDico = {}

def __init__(self,color):
self.color = color
Expand Down Expand Up @@ -73,9 +75,63 @@ def checkOtherDico(self,dico,space):
def clearDico(self):
self.attackDico.clear()
self.defenseDico.clear()
self.onePointDico.clear()
self.twoPointDico.clear()

def checkOnePointDico(self,point_dico,space):
#Parcourt le dictionnaire
for k in self.ownDico:
#Exploder le K par les enderscorts
array = k.split('_')
x = int(array[0])
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

def checkTwoPointDico(self,point_dico,space):
#Parcourt le dictionnaire
for k in self.ownDico:
#Exploder le K par les enderscorts
array = k.split('_')
x = int(array[0])
y = int(array[1])

top_left = pivot.check_two_points_top_left(x,y,space,point_dico)
top_right = pivot.check_two_points_top_right(x,y,space,point_dico)
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)

def makeBuildDico(self,dico,one_point):
if(len(dico)):
point = str(str(dico['x'])+'_'+str(dico['y']))
if(one_point):
if point in self.onePointDico:
self.onePointDico[point] = self.onePointDico[point] + 1
else:
self.onePointDico[point] = 1
else:
if point in self.twoPointDico:
self.twoPointDico[point] = self.twoPointDico[point] + 1
else:
self.twoPointDico[point] = 1

def canBuild(self):
pass
if len(self.onePointDico) | len(self.twoPointDico):
return True
else:
return False

def randPoint(self,can,point_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.
9 changes: 7 additions & 2 deletions IA/irisCpIA.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,5 +38,10 @@ def final_point(self,dico):

return final_dico

def build(self):
pass
def buildWithOnePoint(self):
onepointdico = self.onePointDico
return self.final_point(onepointdico)

def buildWithTwoPoint(self):
twopointdico = self.twoPointDico
return self.final_point(twopointdico)
52 changes: 34 additions & 18 deletions vsCpIris.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
########################################################

from tkinter import *
from random import randrange

from Environnement.player import Player
from Environnement.pivot import Pivot
Expand Down Expand Up @@ -158,29 +159,44 @@ def IAtour():
defense = P2.checkOtherDico(point_dico,space)
attack = P2.checkOwnDico(point_dico,space)

if(len(defense) | len(attack)):

if(len(attack)):
final_dico = P2.attack()
else:
final_dico = P2.defense()

P2.clearDico()
if(len(attack)):

final_dico = P2.attack()
x = final_dico['x']
y = final_dico['y']
can.create_oval(x-r, y-r, x+r, y+r, fill=current_p.getColor())

else:
#Vérification si il y a un possibilité de construire
# if(P2.canBuild()):
# pass
# else:
# point = P2.randPoint(can,point_dico)
# x = point['x']
# y = point['y']
point = P2.randPoint(can,point_dico)
x = point['x']
y = point['y']

vue = randrange(1,20) % 2

if( len(defense) & vue):
final_dico = P2.defense()
x = final_dico['x']
y = final_dico['y']
can.create_oval(x-r, y-r, x+r, y+r, fill=current_p.getColor())
else:
#Vérification si il y a un possibilité de construire
P2.checkOnePointDico(point_dico,space)
P2.checkTwoPointDico(point_dico,space)

if(P2.canBuild()):
if(len(P2.twoPointDico)):
point = P2.buildWithTwoPoint()
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())
else:
point = P2.randPoint(can,point_dico)
x = point['x']
y = point['y']

#On vide tous les dictionnaires de l'IA
P2.clearDico()

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

0 comments on commit ccbcd18

Please sign in to comment.