[Echecs] Modification système déplacement et ajout deplacement tour

This commit is contained in:
Geoffrey Frogeye 2014-12-06 22:37:58 +01:00
parent 55680ad032
commit 665b963193

View file

@ -1,5 +1,14 @@
CASES_COTE = 8 CASES_COTE = 8
MVT_INCONNU = -42
MVT_OK = 1
MVT_ROQUE = 2
MVT_SELECTION = -1
MVT_SUR_PLACE = -2
MVT_SAUT_AMI = -3
MVT_PION_INC = -4
MVT_N_AUTORISE = -5
MVT_OBSTRUCTION = -501
class LogiqueEchecs: class LogiqueEchecs:
@ -65,74 +74,84 @@ class LogiqueEchecs:
def mvtPossible(self, x1, y1, x2, y2): def mvtPossible(self, x1, y1, x2, y2):
pion = self.grille[x1][y1] pion = self.grille[x1][y1]
if self.aSonTour(pion): if self.aSonTour(pion):
if pion > 0: if (x1 != x2 or y1 != y2):
tPion = pion % 10 if not self.aSonTour(self.grille[x2][y2]):
if tPion == 1: # Pion tPion = pion % 10
if x1 == x2 and self.grille[x2][y2] <= 0: # Avance if tPion == 1: # Pion
if self.joueur: if x1 == x2 and self.grille[x2][y2] <= 0: # Avance
if y2 == y1 - 1: if self.joueur:
return [None, True] if y2 == y1 - 1:
elif y1 == 6 and y2 == 4: return 1
return [None, True] elif y1 == 6 and y2 == 4:
return MVT_OK
else:
return MVT_N_AUTORISE
else: else:
return -4 if y2 == y1 + 1:
return 1
elif y1 == 1 and y2 == 3:
return MVT_OK
else:
return MVT_N_AUTORISE
elif abs(x1-x2) == 1: # Saut
if self.joueur:
if y2 == y1 - 1 and \
self.ePionNoir(self.grille[x2][y2]):
return MVT_OK
else:
return MVT_N_AUTORISE
else:
if y2 == y1 + 1 and \
self.ePionBlanc(self.grille[x2][y2]):
return MVT_OK
else:
return MVT_N_AUTORISE
else: else:
if y2 == y1 + 1: return MVT_N_AUTORISE
return [None, True] elif tPion == 2:
elif y1 == 1 and y2 == 3: if y1 == y2:
return [None, True] sens = (x2-x1)//abs(x2-x1)
else: for x in range(x1+sens, x2, sens):
return -4 if self.grille[x][y1] > 0:
elif abs(x1-x2) == 1: # Saut return MVT_OBSTRUCTION
if self.joueur: elif x1 == x2:
if y2 == y1 - 1 and \ sens = (y2-y1)//abs(y2-y1)
self.ePionNoir(self.grille[x2][y2]): for y in range(y1+sens, y2, sens):
return [[x2, y2], True] # Saute un noir if self.grille[x1][y] > 0:
else: return MVT_OBSTRUCTION
return -4
else: else:
if y2 == y1 + 1 and \ return MVT_N_AUTORISE
self.ePionBlanc(self.grille[x2][y2]): return MVT_OK
return [[x2, y2], True] # Saute un blanc elif tPion == 6: # Roi
else: if x2 <= x1 + 1 and x2 >= x1 - 1 and y2 <= y1 + 1 and \
return -4 y2 >= y1 - 1:
return MVT_OK
else:
return MVT_N_AUTORISE
else: else:
return -4 return MVT_PION_INC
elif tPion == 6:
if x2 <= x1 + 1 and x2 >= x1 - 1 and y2 <= y1 + 1 and \
y2 >= y1 - 1 \
and (x1 != x2 or y1 != y2):
return [None, True]
else:
return -4
else: else:
return -3 return MVT_SAUT_AMI
return [None, True]
else: else:
return -2 return MVT_SUR_PLACE
else: else:
return -1 return MVT_SELECTION
return MVT_INCONNU
def mvtsPossibles(self, x1, y1): def mvtsPossibles(self, x1, y1):
tableau = [] tableau = []
for x2 in range(0, CASES_COTE): for x2 in range(0, CASES_COTE):
for y2 in range(0, CASES_COTE): for y2 in range(0, CASES_COTE):
if type(self.mvtPossible(x1, y1, x2, y2)) is list: if self.mvtPossible(x1, y1, x2, y2) == MVT_OK:
tableau.append([x2, y2]) tableau.append([x2, y2])
return tableau return tableau
def dPion(self, x1, y1, x2, y2): def dPion(self, x1, y1, x2, y2):
test = self.mvtPossible(x1, y1, x2, y2) test = self.mvtPossible(x1, y1, x2, y2)
if type(test) is list: if test == MVT_OK:
self.grille[x2][y2] = self.grille[x1][y1] self.grille[x1][y1], self.grille[x2][y2] = 0, self.grille[x1][y1]
self.grille[x1][y1] = 0 self.joueur = not self.joueur
if test[1]: return test
self.joueur = not self.joueur
return test
else:
return test
# GUI # GUI
@ -375,9 +394,9 @@ class PlateauTk:
def dPion(self, x1, y1, x2, y2): def dPion(self, x1, y1, x2, y2):
test = self.logique.dPion(x1, y1, x2, y2) test = self.logique.dPion(x1, y1, x2, y2)
if type(test) is list: # Si déplacement possible if test == MVT_OK: # Si déplacement possible
if type(test[0]) is list: # Si saut → Animation effacement if self.grillePions[x2][y2]: # Si saut → Animation effacement
self.animerF(self.grillePions[test[0][0]][test[0][1]]) self.animerF(self.grillePions[x2][y2])
self.grillePions[x2][y2], self.grillePions[x1][y1] = \ self.grillePions[x2][y2], self.grillePions[x1][y1] = \
self.grillePions[x1][y1], False self.grillePions[x1][y1], False
self.animerD((x1 + .5) * COTE_CASE, (y1 + .5) * COTE_CASE, \ self.animerD((x1 + .5) * COTE_CASE, (y1 + .5) * COTE_CASE, \